-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvetserialu.io-pop-up-blocker.user.js
71 lines (62 loc) · 2.41 KB
/
svetserialu.io-pop-up-blocker.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// ==UserScript==
// @name Pop-up Blocker @svetserialu.io
// @namespace https://github.com/kofaysi/general-userscripts/blob/main/svetserialu.io-pop-up-blocker.user.js.js
// @version 1.5
// @description Blocks pop-up windows on svetserialu.io
// @author https://github.com/kofaysi/
// @match https://svetserialu.io/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Block pop-up windows by intercepting window.open calls
(function(open) {
window.open = function(url, name, features) {
console.log('Blocked a pop-up window attempt.');
return null;
};
})(window.open);
// Function to remove pop-up elements
function removePopups() {
let popups = document.querySelectorAll('div, iframe, a, span, section');
popups.forEach(popup => {
const style = window.getComputedStyle(popup);
if ((style.position === 'fixed' || style.position === 'absolute') && style.zIndex > 1000) {
popup.remove();
console.log('Removed a pop-up element.');
}
});
}
// Observe for new elements added to the DOM
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) {
removePopups();
}
});
});
});
// Start observing the body for added nodes
observer.observe(document.body, { childList: true, subtree: true });
// Initial check for existing pop-ups
removePopups();
// Additional listener for popups created dynamically
setInterval(removePopups, 1000);
// Block right-click pop-up menus
document.addEventListener('contextmenu', function(event) {
event.preventDefault();
console.log('Blocked a context menu pop-up.');
}, true);
// Block click events that open pop-ups
document.addEventListener('click', function(event) {
const target = event.target;
if (target.tagName === 'A' && target.hasAttribute('href')) {
const href = target.getAttribute('href');
if (href.startsWith('javascript:') || href.includes('pop') || href.includes('popup')) {
event.preventDefault();
console.log('Blocked a pop-up link click.');
}
}
}, true);
})();