// ==UserScript==
// @name New script hhu.de
// @namespace Violentmonkey Scripts
// @match https://adam.math.hhu.de/*
// @grant none
// @version 1.3
// @description 2024/7/10 22:30:50
// ==/UserScript==
(function() {
'use strict';
var isHide = true;
// 创建样式
const style = document.createElement('style');
style.textContent = `
.chat-panel-hidden {
visibility: hidden;
}
`;
document.head.appendChild(style);
// 创建切换按钮
const toggleButton = document.createElement('button');
toggleButton.textContent = 'Toggle Chat Panel';
toggleButton.style.position = 'fixed';
toggleButton.style.top = '0px';
toggleButton.style.right = '0px';
toggleButton.style.zIndex = '9999';
// 添加按钮到页面
document.body.appendChild(toggleButton);
// 初始化隐藏聊天面板
function initHideChatPanel() {
const chatPanel = document.querySelector('.chat-panel');
if (chatPanel) {
chatPanel.classList.add('chat-panel-hidden');
return true; // 成功找到并隐藏
}
return false; // 未找到聊天面板
}
// 重试机制
function retryInitHideChatPanel(maxRetries = 100, interval = 100) {
if (isHide){
let retries = 0;
const retry = () => {
if (initHideChatPanel()) {
console.log('Chat panel hidden successfully');
} else if (retries < maxRetries) {
retries++;
console.log(`Attempt ${retries}: Chat panel not found, retrying...`);
setTimeout(retry, interval);
} else {
console.log('Max retries reached, chat panel not found');
}
};
retry();
}
}
// 定时器:每秒执行一次
setInterval(() => {
retryInitHideChatPanel();
}, 1000);
// 切换功能
toggleButton.addEventListener('click', function() {
const chatPanel = document.querySelector('.chat-panel');
if (chatPanel) {
chatPanel.classList.toggle('chat-panel-hidden');
} else {
console.log('Chat panel not found');
}
isHide = !isHide;
});
// 监听popstate事件以处理历史记录前进后退
window.addEventListener('popstate', function() {
retryInitHideChatPanel();
});
// 监听DOMContentLoaded事件以处理页面加载完成
document.addEventListener('DOMContentLoaded', function() {
retryInitHideChatPanel();
});
})();