// ==UserScript==
// @name Disable General Overlay Popup
// @namespace http://tampermonkey.net/
// @version 1.6
// @description Disables popups with specified IDs and classes on certain sites, including dynamically loaded elements
// @author Tek
// @match *://*.xxx.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Define the IDs and classes as arrays
const $hiddenid = ['overlay', 'popup', 'modal']; // Add your IDs here
const $hiddenclass = ['popup-overlay', 'modal-dialog', 'ad-banner']; // Add your classes here
// Function to hide elements by ID and class
function hideElements(mutations = null) {
// Hide elements by ID
$hiddenid.forEach(id => {
const elements = document.querySelectorAll(`[id="${id}"]`);
elements.forEach(element => {
if (element.style.display !== 'none') {
element.style.display = 'none';
// console.log(`Hid element with id: ${id}`);
}
});
});
// Hide elements by class
$hiddenclass.forEach(className => {
const elements = document.getElementsByClassName(className);
Array.from(elements).forEach(element => {
if (element.style.display !== 'none') {
element.style.display = 'none';
// console.log(`Hid element with class: ${className}`);
}
});
});
}
// Run on page load
window.addEventListener('load', () => {
hideElements();
// console.log('Initial check for elements on page load');
});
// Observe DOM changes for dynamically added elements
const observer = new MutationObserver((mutations) => {
hideElements(mutations);
});
// Start observing with optimized configuration
observer.observe(document.body, {
childList: true,
subtree: true
});
// Ensure observer is disconnected when page unloads to prevent memory leaks
window.addEventListener('unload', () => {
observer.disconnect();
});
})();
通过油猴脚本禁用特定网站弹框
未经允许不得转载:迷你笔记 » 通过油猴脚本禁用特定网站弹框
标签油猴
