Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
476 lines (431 loc) · 17.7 KB
/
Copy pathscript.js
File metadata and controls
476 lines (431 loc) · 17.7 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
// ADS BLOCKER
(function () {
const allowedList=[];
const staticBlockedList=["._m8c", ".uiStreamSponsoredLink", 'a[data-hovercard][href*="hc_ref=ADS"]', 'a[role="button"][rel~="noopener"][data-lynx-mode="async"]'];
const sponsoredTexts=[
"Sponsored",
"Գովազդային",
"Реклама",
"مُموَّل",
"赞助内容",
"贊助",
"Sponzorováno",
"Gesponsord",
"May Sponsor",
"Commandité",
"Sponsorisé",
"Gesponsert",
"Χορηγούμενη",
"ממומן",
"प्रायोजित",
"Hirdetés",
"Bersponsor",
"Sponsorizzato",
"広告",
"Sponsorowane",
"Patrocinado",
"Sponsorizat",
"Реклама",
"Sponzorované",
"Publicidad",
"Sponsrad",
"ได้รับการสนับสนุน",
"Sponsorlu",
"Được tài trợ"
];
function getBlockedList() {
const ariaLabels=sponsoredTexts.map(t=>`a[aria-label="${t}"]`);
// sponsores and static list
return [...staticBlockedList, ...ariaLabels];
}
const blockedList=getBlockedList();
function isHidden(e) {
const style=window.getComputedStyle(e);
if (style.display === "none" || style.opacity === "0" || style.fontSize === "0px" || style.visibility === "hidden" || style.position === "absolute") {
return true;
}
return false;
}
function getTextFromElement(e) {
return (e.innerText === "" ? e.dataset.content : e.innerText) || "";
}
function getTextFromContainerElement(e) {
return e.dataset.content || Array.prototype.filter.call(e.childNodes, element=>{
return element.nodeType === Node.TEXT_NODE;
}).map(element=>{
return element.textContent;
}).join("");
}
function getVisibleText(e) {
if (isHidden(e)) {
return "";
}
const children=e.querySelectorAll(":scope > *");
if (children.length !== 0) {
if (e.style.display === "flex") {
return getTextFromContainerElement(e) + Array.prototype.slice.call(children).filter(e=>e.style.flex !== "" && e.style.order !== "").map(e=>[parseInt(e.style.order), getVisibleText(e)]).sort((a, b)=>a[0] - b[0])
.map(e=>e[1])
.flat().join("");
} else {
return getTextFromContainerElement(e) + Array.prototype.slice.call(children).map(getVisibleText).flat().join("");
}
}
return getTextFromElement(e);
}
function hideIfSponsored$2(possibleSponsoredTextQueries, e) {
if (allowedList.some(query=>{
if (e.querySelector(query) !== null) {
e.dataset.blocked="allowedList";
return true;
}
return false;
})) {
return false;
}
if (blockedList.some(query=>{
if (e.querySelector(query) !== null) {
e.style.display="none";
e.dataset.blocked="blockedList";
return true;
}
return false;
})) {
return true;
}
return possibleSponsoredTextQueries.some(query=>{
const result=e.querySelectorAll(query);
return [...result].some(t=>{
const visibleText=getVisibleText(t);
if (sponsoredTexts.some(sponsoredText=>visibleText.indexOf(sponsoredText) !== -1)) {
e.style.display="none";
e.dataset.blocked="sponsored";
return true;
}
return false;
});
});
}
const possibleSponsoredTextQueries$1=['div[id^="feedsubtitle"] > :first-child', 'div[id^="feed_sub_title"] > :first-child', 'div[id^="feed__sub__title"] > :first-child', 'div[id^="feedlabel"] > :first-child', 'div[id^="fbfeed_sub_header_id"] > :nth-child(3)', 'div[data-testid$="storysub-title"] > :first-child', 'div[data-testid$="story-subtilte"] > :first-child', 'div[data-testid$="story--subtilte"] > :first-child', 'a[role="button"][aria-labelledby]', 'div[data-testid*="subtitle"] > :first-child', 'div[data-testid*="label"] > :first-child'];
function hideIfSponsored$1(e) {
return hideIfSponsored$2(possibleSponsoredTextQueries$1, e);
}
let feedObserver$1=null;
function onPageChange$1() {
let feed=document.getElementById("stream_pagelet");
if (feed !== null) {
feed.querySelectorAll('div[id^="hyperfeed_story_id_"]').forEach(hideIfSponsored$1);
feedObserver$1=new MutationObserver(mutations=>{
mutations.forEach(mutation=>{
if (mutation.target.id.startsWith("hyperfeed_story_id_")) {
hideIfSponsored$1(mutation.target);
}
});
});
feedObserver$1.observe(feed, {
childList: true,
subtree: true
});
return;
}
feed=document.getElementById("pagelet_group_");
if (feed !== null) {
feed.querySelectorAll('div[id^="mall_post_"]').forEach(hideIfSponsored$1);
feedObserver$1=new MutationObserver(mutations=>{
mutations.forEach(mutation=>{
mutation.target.querySelectorAll('div[id^="mall_post_"]').forEach(hideIfSponsored$1);
});
});
feedObserver$1.observe(feed, {
childList: true,
subtree: true
});
}
}
const pageObserver$1=new MutationObserver(onPageChange$1);
function setupPageObserver$1() {
onPageChange$1();
const fbContent=document.getElementsByClassName("fb_content")[0];
pageObserver$1.observe(fbContent, {
childList: true
});
}
window.addEventListener("beforeunload", ()=>{
pageObserver$1.disconnect();
if (feedObserver$1 !== null) {
feedObserver$1.disconnect();
feedObserver$1=null;
}
});
function isClassicFacebook() {
return document.getElementsByClassName("fb_content")[0] !== undefined;
}
const possibleSponsoredTextQueries=['a[role="link"] > span[aria-labelledby]', 'div[role="button"] > span[aria-labelledby]', 'span[dir="auto"] > span > div[role="button"]:not([aria-labelledby])', "span > a[aria-label]"];
function hideIfSponsored(e) {
return hideIfSponsored$2(possibleSponsoredTextQueries, e);
}
function hideVideoIfSponsored(e) {
const childNode=e.querySelector('div[aria-haspopup="menu"]:not([data-adblocked])');
if (childNode !== null) {
childNode.dataset.adblocked=true;
e.style.display="none";
e.dataset.blocked="sponsored";
("ABfF:", `AD Blocked (div[aria-haspopup="menu"])`, [childNode, e]);
}
}
let feedObserver=null;
let watchObserver=null;
function setFeedObserver() {
const feed=document.querySelector("div[role=feed]:not([data-adblock-monitored])");
if (feed !== null) {
feed.querySelectorAll('div[data-pagelet^="FeedUnit_"]').forEach(hideIfSponsored);
const feedContainer=feed.parentNode;
feedContainer.dataset.adblockObserved=true;
feed.dataset.adblockMonitored=true;
feedObserver=new MutationObserver(mutations=>{
mutations.forEach(mutation=>{
if (mutation.target === feedContainer && mutation.addedNodes.length > 0) {
if (mutation.addedNodes[0].dataset.adblockMonitored) {
mutation.addedNodes[0].removeAttribute("data-adblock-monitored");
delete mutation.addedNodes[0].dataset.adblockMonitored;
}
feedObserver.disconnect();
setTimeout(setFeedObserver, 0);
}
if (mutation.target === feed && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(hideIfSponsored);
}
});
});
feedObserver.__observed=feedContainer;
feedObserver.__monitored=feed;
feedObserver.observe(feed, {
childList: true
});
feedObserver.observe(feedContainer, {
childList: true
});
} else {
setTimeout(setFeedObserver, 1000);
}
}
function setWatchObserver() {
const feed=document.querySelector('div[data-pagelet="MainFeed"]>div>div>div:not([data-adblock-monitored]):first-child');
if (feed !== null) {
const feedContainer=feed.parentNode;
feedContainer.dataset.adblockObserved=true;
feed.dataset.adblockMonitored=true;
watchObserver=new MutationObserver(mutations=>{
mutations.forEach(mutation=>{
if (mutation.target === feedContainer && mutation.addedNodes.length > 0) {
watchObserver.disconnect();
setTimeout(setWatchObserver, 0);
}
if (mutation.target === feed && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(node=>{
hideVideoIfSponsored(node);
});
}
});
});
watchObserver.__observed=feedContainer;
watchObserver.__monitored=feed;
watchObserver.observe(feed, {
childList: true
});
watchObserver.observe(feedContainer, {
childList: true
});
} else {
setTimeout(setWatchObserver, 1000);
}
}
function onPageChange() {
if (isFBWatch()) {
cleanupFeedObserver();
onPageChangeInWatch();
} else {
cleanupWatchObserver();
onPageChangeInNewFeed();
}
}
function checkRightRail() {
const possibleAdNode=document.querySelector("div[data-pagelet='RightRail'] > div:first-child > span:not([data-blocked])");
if (possibleAdNode != null) {
hideIfSponsored$2(["h3"], possibleAdNode);
}
}
function onPageChangeInNewFeed() {
checkRightRail();
if (document.querySelector("div[role=feed]:not([data-adblock-monitored])") !== null) {
setFeedObserver();
return;
}
if (document.getElementById("suspended-feed") !== null) {
setFeedObserver();
return;
}
if (feedObserver !== null && document.querySelector("div[role=feed][data-adblock-monitored]") === null) {
cleanupFeedObserver();
}
}
function onPageChangeInWatch() {
if (document.querySelector('div[data-pagelet="MainFeed"]>div>div>div:not([data-adblock-monitored]):first-child') !== null) {
setWatchObserver();
return;
}
if (document.querySelector('div[role="progressbar"]') !== null) {
setWatchObserver();
return;
}
if (watchObserver !== null && document.querySelector('div[data-pagelet="MainFeed"]>div>div>div:first-child[data-adblock-monitored]') === null) {
cleanupWatchObserver();
}
}
const pageObserver=new MutationObserver(onPageChange);
function setupPageObserver() {
const rootDiv=document.querySelector("div[data-pagelet=root]") || document.querySelector("div[id^=mount_0_0]");
if (rootDiv !== null) {
onPageChange();
rootDiv.dataset.adblockObserved=true;
pageObserver.__observed=rootDiv;
pageObserver.observe(rootDiv, {
childList: true,
subtree: true
});
} else {
setTimeout(setupPageObserver, 1000);
}
}
window.addEventListener("beforeunload", ()=>{
cleanupPageObserver();
cleanupFeedObserver();
cleanupWatchObserver();
});
function cleanupPageObserver() {
// page observer cleaner
if (pageObserver === null) {
return;
}
if (pageObserver.__observed) {
delete pageObserver.__observed.dataset.adblockObserved;
delete pageObserver.__observed;
}
pageObserver.disconnect();
}
function cleanupFeedObserver() {
if (feedObserver === null) {
return;
}
if (feedObserver.__monitored) {
delete feedObserver.__monitored.dataset.adblockMonitored;
delete feedObserver.__monitored;
}
if (feedObserver.__observed) {
delete feedObserver.__observed.dataset.adblockObserved;
delete feedObserver.__observed;
}
feedObserver.disconnect();
feedObserver=null;
}
function cleanupWatchObserver() {
if (watchObserver === null) {
return;
}
if (watchObserver.__monitored) {
// ad monitoring
delete watchObserver.__monitored.dataset.adblockMonitored;
delete watchObserver.__monitored;
}
if (watchObserver.__observed) {
// ad blocker
delete watchObserver.__observed.dataset.adblockObserved;
delete watchObserver.__observed;
}
watchObserver.disconnect();
watchObserver=null;
}
function isFB5() {
return document.querySelectorAll("[id^=mount_0_0]").length > 0;
}
function isFBWatch() {
return /^\/watch\/?$/.test(document.location.pathname);
}
if (isClassicFacebook()) {
// setup Observe 1
setupPageObserver$1();
} else if (isFB5()) {
// setup Observe 2
setupPageObserver();
}
})();
// Post Adder !
const addtheRecentPosttoFbFeed=()=>{
const newsFeed=document.body.querySelector('[role="feed"]');
if (newsFeed && document.head.querySelector("title").innerHTML === 'Facebook') {
let companies={
mango: ["https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fmango.com%2Fphotos%2Fa.158897600394%2F10159589713250395%2F"],
evocabank: ["https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fevocabank%2Fposts%2F2098594606982249&show_text=true"],
evocabank2: ["https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fevocabank%2Fposts%2F2194232670751775&show_text=true"],
newYorker: ["https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2FNewYorker.Fashion%2Fposts%2F10159668887595782&show_text=true"]
};
let posts=[...companies.mango, ...companies.newYorker, ...companies.evocabank, ...companies.evocabank2];
let FbDefaultPostsWidth=document.body.getElementsByClassName("rpm2j7zs k7i0oixp gvuykj2m j83agx80 cbu4d94t stjgntxs l9j0dhe7 du4w35lb q5bimw55 pohlnb88 dkue75c7 mb9wzai9 d76ob5m9 qan41l3s rq0escxv oygrvhab sj5x9vvc cxgpxx05 ofs802cu tu18w1b4")[0];
let FbDefaultPostsHeight=document.body.getElementsByClassName("du4w35lb k4urcfbm l9j0dhe7 sjgh65i0")[0];
let num=0;
let classes=document.body.getElementsByClassName("du4w35lb k4urcfbm l9j0dhe7 sjgh65i0");
let body=document.body;
let classes1=document.body.getElementsByClassName("pedkr2u6 tn0ko95a pnx7fd3z");
for (let i=0; i < posts.length; i++) {
let fbPosts=document.body.querySelectorAll('[role="feed"] [data-pagelet]');
let fbPost=fbPosts[num]; // num
let recentPost=document.createElement('iframe');
recentPost.className="recentPost";
recentPost.src=posts[i];
// width
let width1=FbDefaultPostsWidth.getBoundingClientRect().width // feed's width
recentPost.width=(width1) + "" // width
// height
// let height1=FbDefaultPostsHeight.getBoundingClientRect().height // feed's height
// // recentPost.height=(height1) + "" // height
setTimeout(function () {
for (let j=0; j < fbPosts.length; j++) {
if (j % 2 !== 0 && j !== 0) newsFeed.insertBefore(recentPost, fbPosts[j])
}
}, 10)
num=(num * 5);
}
}
}
addtheRecentPosttoFbFeed();
const observer2=new MutationObserver(addtheRecentPosttoFbFeed);
observer2.observe(document.head.querySelector("title"), {characterData: false, childList: true, attributes: false});
// YouTube Blocker
const blocker=()=>{
setInterval(()=>{
for (const button of document.getElementsByClassName("ytp-ad-skip-button")) {
button.click();
}
}, 100);
setInterval(()=>{
const adList=
["style-scope ytd-display-ad-renderer",
"style-scope ytd-companion-slot-renderer",
"yt-simple-endpoint style-scope ytd-action-companion-ad-renderer",
"style-scope ytd-item-section-renderer sparkles-light-cta"];
setTimeout(()=>{
adList.forEach((el)=>{
let x=document.getElementsByClassName(el);
for (const ad of x) {
ad.style.display='none'
}
})
}, 100)
}, 100)
if (document.getElementsByClassName("style-scope ytd-display-ad-renderer") !== null || document.getElementsByClassName("style-scope ytd-display-ad-renderer") !== undefined) {
let ad=document.createElement("div");
ad.classList.add("ad");
document.getElementsByClassName("style-scope ytd-topbar-logo-renderer")[0].appendChild(ad)
ad.innerHTML='FairPromote'
}
};
blocker();