-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraylady.js
88 lines (79 loc) · 2.64 KB
/
graylady.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const helperSnap = (query, delay) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(document.querySelector(query).innerHTML);
},delay)
})
}
const helperLoad = (query, delay, secondQuery = false, autoResolve = false) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (document.querySelector(query)){
resolve(document.querySelector(query));
}
else if (secondQuery && document.querySelector(secondQuery)){
resolve(document.querySelector(secondQuery))
}
else if (autoResolve){
resolve(false);
}
},delay)
})
}
const atlas = () => {
const paywallLoaded = helperLoad('#paywall',500);
const rmPaywall = (paywall) => {
paywall.remove();
document.querySelector('body').style.overflow = 'initial';
}
Promise.all([paywallLoaded]).then((allValues) => rmPaywall(allValues[0]));
}
const district = () => {
const takeSnapshot = helperSnap('article',200);
const paywallLoaded = helperLoad('[id^="paywall"]',7000);
const rmPaywall = (snapshot, paywall) => {
const html = document.querySelector('html');
paywall.remove();
const getBody = () => {
console.log(document.querySelector('body').style.overflow);
return Promise.resolve(document.querySelector('body'));
}
getBody().then(
(body) => {
body.style.position = 'initial';
body.style.overflow = 'initial';
console.log(document.querySelector('body').style.overflow);
});
html.style.overflow = 'initial';
document.querySelector('article').innerHTML = snapshot;
}
Promise.all([takeSnapshot,paywallLoaded]).then((allValues) => rmPaywall(allValues[0],allValues[1]));
}
const gotham = () => {
const takeSnapshot = helperSnap('article',0);
const paywallLoaded = helperLoad('#gateway-content',3000,false,true);
const rmPaywall = (snapshot, paywall) => {
if (paywall) {
paywall.remove();
}
const content = document.querySelector('[class^="css-"]');
content.style.position = 'initial';
content.style.overflow = 'initial';
const rmGrad = (ele) => {
if (ele.className.startsWith('css-') && ele.style){
ele.style.display = 'none';
}
}
content.childNodes.forEach(ele => rmGrad(ele));
document.querySelector('article').innerHTML = snapshot;
}
Promise.all([takeSnapshot,paywallLoaded]).then((allValues) => rmPaywall(allValues[0],allValues[1]));
}
const theHost = window.location.hostname;
if (theHost === 'www.washingtonpost.com'){
district();
} else if (theHost === 'www.nytimes.com'){
gotham();
} else if (theHost === 'www.theatlantic.com'){
atlas();
}