添加 移除中国肿瘤生物治疗杂志的弹窗.js
This commit is contained in:
59
移除中国肿瘤生物治疗杂志的弹窗.js
Normal file
59
移除中国肿瘤生物治疗杂志的弹窗.js
Normal file
@@ -0,0 +1,59 @@
|
||||
// ==UserScript==
|
||||
// @name 移除中国肿瘤生物治疗杂志的弹窗
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.0
|
||||
// @description 移除中国肿瘤生物治疗杂志的弹窗
|
||||
// @author 8ga
|
||||
// @match https://www.biother.cn/*
|
||||
// @grant none
|
||||
// @run-at document-end
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// 定义要移除的元素 ID
|
||||
const targetId = 'MoveImagesWindowDiv';
|
||||
|
||||
// 移除元素的函数
|
||||
function removeElement() {
|
||||
const element = document.getElementById(targetId);
|
||||
if (element) {
|
||||
element.remove();
|
||||
console.log('油猴脚本成功移除元素:', targetId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 1. 尝试立即移除(针对静态加载或已加载的元素)
|
||||
removeElement();
|
||||
|
||||
// 2. 设置观察器(针对动态加载的元素)
|
||||
// 如果页面是通过 AJAX 或延迟加载该 div,观察器能确保它一出现就被移除
|
||||
const observer = new MutationObserver(() => {
|
||||
if (removeElement()) {
|
||||
// 如果成功移除,可以选择断开观察器以节省性能,或者保留它以应对元素被重新添加的情况
|
||||
// observer.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
// 开始观察 body 节点的子节点变化
|
||||
if (document.body) {
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
} else {
|
||||
// 如果 body 还没加载(虽然 @run-at document-end 通常能保证 body 存在),等待 DOMContentLoaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (document.body) {
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
removeElement();
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user