-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatlantic_paywall.js
42 lines (38 loc) · 1.43 KB
/
atlantic_paywall.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
// ==UserScript==
// @name Atlantic Bypass Paywall
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Attempt to bypass the atlantic paywall automatically
// @author Joseph Tibbertsma <[email protected]>
// @match https://www.theatlantic.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function loadJsCookie() {
return new Promise(resolve => {
const body = document.getElementsByTagName('body')[0];
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js';
script.onload = resolve;
body.appendChild(script);
});
}
// Clear the articleViews cookie
function clearArticleViews() {
const Cookie = window.Cookies; // from js-cookie
Cookie.remove('articleViews', { domain: '.theatlantic.com' });
}
loadJsCookie().then(() => {
// Check for the paywall twice per second
const paywallInterval = window.setInterval(() => {
// The paywall is present if the div with id 'gate' is present
if (document.getElementById('gate')) {
window.clearInterval(paywallInterval);
clearArticleViews();
// Reload the page
window.location.href = window.location.href;
}
}, 500);
});
})();