-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpopup-blocker.js
More file actions
281 lines (247 loc) 路 8.58 KB
/
Copy pathpopup-blocker.js
File metadata and controls
281 lines (247 loc) 路 8.58 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
* PS4 Games Database - Popup Blocker & Ad Blocker
* Prevents unwanted popups, redirects, and ads from opening
* Compatible with PS4 WebKit browser
*/
(function() {
'use strict';
// Configuration
var config = {
blockPopups: true,
blockRedirects: true,
blockAds: true,
blockExternalLinks: false,
allowedDomains: [
'mediafire.com',
'1fichier.com',
'1file',
'mega.nz',
'drive.google.com',
'dropbox.com',
'dlpsgame.com'
]
};
// Track blocked popups
var blockedCount = 0;
// Override window.open to block popups
var originalOpen = window.open;
window.open = function(url, target, features) {
blockedCount++;
console.log('[Popup Blocker] Blocked popup #' + blockedCount + ': ' + url);
return null;
};
// Block window.location redirects to suspicious domains
var originalLocationHref = Object.getOwnPropertyDescriptor(Location.prototype, 'href');
Object.defineProperty(Location.prototype, 'href', {
set: function(url) {
if (isSuspiciousDomain(url)) {
console.log('[Popup Blocker] Blocked redirect to: ' + url);
return;
}
originalLocationHref.set.call(this, url);
},
get: originalLocationHref.get
});
// Block target="_blank" on suspicious links
document.addEventListener('click', function(e) {
var target = e.target;
// Find the link element
while (target && target.tagName !== 'A') {
target = target.parentElement;
}
if (target && target.tagName === 'A') {
var href = target.getAttribute('href');
var targetAttr = target.getAttribute('target');
// Block external blank targets
if (targetAttr === '_blank' && isSuspiciousDomain(href)) {
e.preventDefault();
e.stopPropagation();
console.log('[Popup Blocker] Blocked external link: ' + href);
return false;
}
}
}, true);
// Block common ad/redirect patterns
document.addEventListener('beforeunload', function(e) {
// Check if navigation is to a suspicious domain
if (window.location.href && isSuspiciousDomain(window.location.href)) {
console.log('[Popup Blocker] Suspicious navigation detected');
}
});
// Intercept fetch requests to block ad networks
if (window.fetch) {
var originalFetch = window.fetch;
window.fetch = function(resource, config) {
if (typeof resource === 'string' && isAdNetwork(resource)) {
console.log('[Popup Blocker] Blocked ad network request: ' + resource);
return Promise.reject(new Error('Blocked by popup blocker'));
}
return originalFetch.apply(this, arguments);
};
}
// Intercept XMLHttpRequest to block ad networks
var originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
if (isAdNetwork(url)) {
console.log('[Popup Blocker] Blocked ad network XHR: ' + url);
this._blocked = true;
return;
}
return originalXHROpen.apply(this, arguments);
};
var originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function() {
if (this._blocked) {
return;
}
return originalXHRSend.apply(this, arguments);
};
// Block script injection attempts
var originalCreateElement = document.createElement;
document.createElement = function(tagName) {
var element = originalCreateElement.call(document, tagName);
if (tagName.toLowerCase() === 'script') {
var originalSetAttribute = element.setAttribute;
element.setAttribute = function(name, value) {
if (name === 'src' && isAdNetwork(value)) {
console.log('[Popup Blocker] Blocked ad script: ' + value);
return;
}
return originalSetAttribute.call(this, name, value);
};
}
return element;
};
// Remove common ad elements
function removeAdElements() {
var adSelectors = [
'[id*="ad"]',
'[class*="ad"]',
'[id*="banner"]',
'[class*="banner"]',
'[id*="popup"]',
'[class*="popup"]',
'iframe[src*="ads"]',
'iframe[src*="doubleclick"]',
'iframe[src*="google"]',
'script[src*="ads"]',
'script[src*="analytics"]'
];
for (var i = 0; i < adSelectors.length; i++) {
var selector = adSelectors[i];
try {
var elements = document.querySelectorAll(selector);
for (var j = 0; j < elements.length; j++) {
var element = elements[j];
if (element && element.parentNode) {
element.parentNode.removeChild(element);
console.log('[Popup Blocker] Removed ad element: ' + selector);
}
}
} catch (e) {
// Selector not supported
}
}
}
// Helper function to check if domain is suspicious
function isSuspiciousDomain(url) {
if (!url) return false;
var suspiciousDomains = [
'bit.ly',
'tinyurl.com',
'short.link',
'adf.ly',
'linkvertise.com',
'shorte.st',
'ouo.io',
'linkbucks.com',
'adfly.com',
'clicksfly.com',
'lnk.co',
'exe.io',
'sub2unlock.com',
'linksnappy.com',
'rapidgator.net',
'turbobit.net',
'uploaded.net',
'filejoker.net',
'keep2share.cc',
'nitroflare.com'
];
for (var i = 0; i < suspiciousDomains.length; i++) {
if (url.indexOf(suspiciousDomains[i]) > -1) {
return true;
}
}
return false;
}
// Helper function to check if URL is an ad network
function isAdNetwork(url) {
if (!url) return false;
var adNetworks = [
'doubleclick.net',
'google-analytics.com',
'googleadservices.com',
'googlesyndication.com',
'facebook.com/tr',
'analytics.google.com',
'ads.google.com',
'pagead2.googlesyndication.com',
'adservice.google.com',
'googletagmanager.com',
'amazon-adsystem.com',
'criteo.com',
'scorecardresearch.com',
'quantserve.com',
'addthis.com',
'sharethis.com'
];
for (var i = 0; i < adNetworks.length; i++) {
if (url.indexOf(adNetworks[i]) > -1) {
return true;
}
}
return false;
}
// Initialize popup blocker
function init() {
console.log('[Popup Blocker] Initialized');
// Remove ad elements on page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', removeAdElements);
} else {
removeAdElements();
}
// Monitor for dynamically added ad elements
if (window.MutationObserver) {
var observer = new MutationObserver(function(mutations) {
for (var i = 0; i < mutations.length; i++) {
var mutation = mutations[i];
if (mutation.addedNodes.length) {
removeAdElements();
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
}
// Start popup blocker
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
// Expose stats
window.popupBlockerStats = {
getBlockedCount: function() {
return blockedCount;
},
reset: function() {
blockedCount = 0;
}
};
console.log('[Popup Blocker] Loaded and active');
})();