-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathad-shield-fix.user.js
More file actions
198 lines (180 loc) · 8.45 KB
/
ad-shield-fix.user.js
File metadata and controls
198 lines (180 loc) · 8.45 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// ==UserScript==
// @name Ad-Shield Fix for Chrome (TamperMonkey)
// @description Use with TamperMonkey in Chrome to prevent the intrusive ad-enfocement that recently appeared on e.g.Slashdot, SourceForge
// @version 2026-03-27
// @author Platima
// @license MIT
// @homepage https://github.com/platima/Ad-Shield_Fix
// @source https://github.com/platima/Ad-Shield_Fix/raw/main/ad-shield-fix.user.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=slashdot.org
// @supportURL https://github.com/platima/Ad-Shield_Fix/issues/new?assignees=platima&labels=bug&projects=&template=bug_report.md&title=%5BBUG%5D
// @grant unsafeWindow
// @run-at document-start
// @match *://*.wetter.com/*
// @match *://wetter.com/*
// @match *://*.picrew.me/*
// @match *://picrew.me/*
// @match *://*.indiatimes.com/*
// @match *://indiatimes.com/*
// @match *://*.j-cast.com/*
// @match *://j-cast.com/*
// @match *://*.sourceforge.net/*
// @match *://sourceforge.net/*
// @match *://*.slashdot.org/*
// @match *://slashdot.org/*
// @match *://*.flagle.io/*
// @match *://flagle.io/*
// @match *://*.sharktankrecap.com/*
// @match *://sharktankrecap.com/*
// @match *://*.willyweather.com.au/*
// @match *://willyweather.com.au/*
// ==/UserScript==
(function() {
'use strict';
console.log('%cThanks for using Platima\'s Ad-Shield Fix Script 🙏 (https://github.com/platima/Ad-Shield_Fix)', 'color: green; font-size: 16px; font-weight: bold;');
const script = document.createElement('script');
script.textContent = `
(function() {
try {
// Store original methods
const _alert = window.alert;
const _querySelectorAll = document.querySelectorAll;
const _createElement = document.createElement;
const _confirm = window.confirm;
// Function to check if an iframe is a full-screen overlay
function isOverlayIframe(element) {
if (element.tagName !== 'IFRAME') return false;
const style = window.getComputedStyle(element);
return style.position === 'fixed' &&
style.width === '100vw' &&
style.height === '100vh' &&
style.zIndex === '2147483647';
}
// Override createElement to block problematic iframes
document.createElement = new Proxy(_createElement, {
apply: function(target, thisArg, args) {
const element = _createElement.apply(thisArg, args);
if (args[0].toLowerCase() === 'iframe') {
// Block setting overlay-style attributes
const originalSetAttribute = element.setAttribute;
element.setAttribute = function(name, value) {
if (name === 'style' && value.includes('100vw') && value.includes('fixed')) {
return;
}
return originalSetAttribute.call(this, name, value);
};
Object.defineProperty(element, 'src', {
set: function(value) {
if (value && value.includes('error-report.com')) {
return;
}
return value;
},
get: function() {
return element.getAttribute('src');
}
});
}
return element;
}
});
// Override alert globally
Object.defineProperty(window, 'alert', {
value: function() { return undefined; },
writable: false,
configurable: false
});
// Override confirm to always return false for Ad-Shield messages
Object.defineProperty(window, 'confirm', {
value: function(message) {
if (message && message.includes('adblockers')) {
throw Error("Ad-Shield used confirm(). Throwing error to stop execution. This is not a bad thing :)");
}
return _confirm.apply(this, arguments);
},
writable: false,
configurable: false
});
// Override querySelectorAll
document.querySelectorAll = new Proxy(_querySelectorAll, {
apply: function(target, thisArg, args) {
if (args[0] === "link,style") {
return _querySelectorAll.call(document, "invalid");
}
return _querySelectorAll.apply(thisArg, args);
}
});
// Block the setInterval that removes styles
const _setInterval = window.setInterval;
window.setInterval = new Proxy(_setInterval, {
apply: function(target, thisArg, args) {
const [fn, delay] = args;
if (delay === 100 && fn.toString().includes('querySelectorAll')) {
return 0;
}
return _setInterval.apply(thisArg, args);
}
});
// Remove ads and overlay iframes
function cleanupPage() {
try {
// Remove ad containers
const adElements = document.getElementsByClassName('adwrap');
for (let i = adElements.length - 1; i >= 0; i--) {
adElements[i].style.display = 'none';
adElements[i].innerHTML = '';
}
// Remove overlay iframes and empty iframes
const iframes = document.getElementsByTagName('iframe');
for (let i = iframes.length - 1; i >= 0; i--) {
const iframe = iframes[i];
if (isOverlayIframe(iframe) ||
!iframe.src ||
iframe.src === '' ||
!iframe.getAttribute('src')) {
iframe.remove();
}
}
} catch (e) {
console.error("Error during cleanupPage:", e);
}
}
// Add CSS to ensure iframes can't take up space
const styleId = 'ad-shield-fix-style';
if (!document.getElementById(styleId)) {
const style = document.createElement('style');
style.id = styleId;
style.textContent = 'iframe:empty, iframe:not([src]) { display: none !important; height: 0 !important; }';
document.head.appendChild(style);
}
// Run immediately and then leave it to the MutationObserver
cleanupPage();
// Also run when DOM changes
const observer = new MutationObserver(() => {
cleanupPage();
});
observer.observe(document.documentElement || document, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style']
});
} catch (e) {
console.error("Error initializing script:", e);
}
})();
`;
// Insert the script as early as possible
const insert = () => {
const parent = document.head || document.documentElement;
if (parent) {
parent.insertBefore(script, parent.firstChild);
script.remove();
}
};
insert();
// Also try on DOMContentLoaded if needed
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', insert);
}
})();