Bypass Paywalls

A way to bypass paywalls for popular news sites.

  1. // ==UserScript==
  2. // @name Bypass Paywalls
  3. // @description A way to bypass paywalls for popular news sites.
  4. // @author Joe Fang (https://github.com/MinecraftFuns), (Fork from https://github.com/LegeBeker/bypass-paywalls-tampermonkey)
  5. // @namespace https://github.com/CodeMaintainer/EternityGreek/
  6. // @supportURL https://github.com/CodeMaintainer/EternityGreek/issues
  7. // @icon https://cdn.jsdelivr.net/gh/CodeMaintainer/EternityGreek@0.0.1/assets/bypass-paywalls-icon-32.png
  8. // @run-at document-end
  9. // @version 0.1.4
  10. // @match *://*.adweek.com/*
  11. // @match *://*.ad.nl/*
  12. // @match *://*.americanbanker.com/*
  13. // @match *://*.ambito.com/*
  14. // @match *://*.baltimoresun.com/*
  15. // @match *://*.barrons.com/*
  16. // @match *://*.bloombergquint.com/*
  17. // @match *://*.bloomberg.com/*
  18. // @match *://*.bndestem.nl/*
  19. // @match *://*.bostonglobe.com/*
  20. // @match *://*.bd.nl/*
  21. // @match *://*.brisbanetimes.com.au/*
  22. // @match *://*.businessinsider.com/*
  23. // @match *://*.caixinglobal.com/*
  24. // @match *://*.centralwesterndaily.com.au/*
  25. // @match *://*.acs.org/*
  26. // @match *://*.chicagotribune.com/*
  27. // @match *://*.corriere.it/*
  28. // @match *://*.chicagobusiness.com/*
  29. // @match *://*.dailypress.com/*
  30. // @match *://*.gelderlander.nl/*
  31. // @match *://*.groene.nl/*
  32. // @match *://*.destentor.nl/*
  33. // @match *://*.speld.nl/*
  34. // @match *://*.tijd.be/*
  35. // @match *://*.volkskrant.nl/*
  36. // @match *://*.demorgen.be/*
  37. // @match *://*.denverpost.com/*
  38. // @match *://*.df.cl/*
  39. // @match *://*.editorialedomani.it/*
  40. // @match *://*.dynamed.com/*
  41. // @match *://*.ed.nl/*
  42. // @match *://*.elmercurio.com/*
  43. // @match *://*.elpais.com/*
  44. // @match *://*.elperiodico.com/*
  45. // @match *://*.elu24.ee/*
  46. // @match *://*.britannica.com/*
  47. // @match *://*.estadao.com.br/*
  48. // @match *://*.examiner.com.au/*
  49. // @match *://*.expansion.com/*
  50. // @match *://*.fnlondon.com/*
  51. // @match *://*.financialpost.com/*
  52. // @match *://*.ft.com/*
  53. // @match *://*.firstthings.com/*
  54. // @match *://*.foreignpolicy.com/*
  55. // @match *://*.fortune.com/*
  56. // @match *://*.genomeweb.com/*
  57. // @match *://*.glassdoor.com/*
  58. // @match *://*.globes.co.il/*
  59. // @match *://*.grubstreet.com/*
  60. // @match *://*.haaretz.co.il/*
  61. // @match *://*.haaretz.com/*
  62. // @match *://*.handelsblatt.com/*
  63. // @match *://*.harpers.org/*
  64. // @match *://*.courant.com/*
  65. // @match *://*.hbr.org/*
  66. // @match *://*.heraldsun.com.au/*
  67. // @match *://*.fd.nl/*
  68. // @match *://*.historyextra.com/*
  69. // @match *://*.humo.be/*
  70. // @match *://*.ilmanifesto.it/*
  71. // @match *://*.inc.com/*
  72. // @match *://*.interest.co.nz/*
  73. // @match *://*.investorschronicle.co.uk/*
  74. // @match *://*.lecho.be/*
  75. // @match *://*.labusinessjournal.com/*
  76. // @match *://*.lanacion.com.ar/*
  77. // @match *://*.repubblica.it/*
  78. // @match *://*.lastampa.it/*
  79. // @match *://*.latercera.com/*
  80. // @match *://*.lavoixdunord.fr/*
  81. // @match *://*.ledevoir.com/*
  82. // @match *://*.leparisien.fr/*
  83. // @match *://*.lesechos.fr/*
  84. // @match *://*.loebclassics.com/*
  85. // @match *://*.lrb.co.uk/*
  86. // @match *://*.latimes.com/*
  87. // @match *://*.mit.edu/*
  88. // @match *://*.technologyreview.com/*
  89. // @match *://*.medium.com/*
  90. // @match *://*.medscape.com/*
  91. // @match *://*.mexiconewsdaily.com/*
  92. // @match *://*.mv-voice.com/*
  93. // @match *://*.nationalgeographic.com/*
  94. // @match *://*.nydailynews.com/*
  95. // @match *://*.nrc.nl/*
  96. // @match *://*.ntnews.com.au/*
  97. // @match *://*.nationalpost.com/*
  98. // @match *://*.nzz.ch/*
  99. // @match *://*.nymag.com/*
  100. // @match *://*.nzherald.co.nz/*
  101. // @match *://*.ocregister.com/*
  102. // @match *://*.orlandosentinel.com/*
  103. // @match *://*.pzc.nl/*
  104. // @match *://*.paloaltoonline.com/*
  105. // @match *://*.parool.nl/*
  106. // @match *://*.postimees.ee/*
  107. // @match *://*.qz.com/*
  108. // @match *://*.quora.com/*
  109. // @match *://*.gelocal.it/*
  110. // @match *://*.republic.ru/*
  111. // @match *://*.reuters.com/*
  112. // @match *://*.sandiegouniontribune.com/*
  113. // @match *://*.sfchronicle.com/*
  114. // @match *://*.scientificamerican.com/*
  115. // @match *://*.seekingalpha.com/*
  116. // @match *://*.slate.com/*
  117. // @match *://*.sofrep.com/*
  118. // @match *://*.statista.com/*
  119. // @match *://*.startribune.com/*
  120. // @match *://*.stuff.co.nz/*
  121. // @match *://*.sun-sentinel.com/*
  122. // @match *://*.techinasia.com/*
  123. // @match *://*.telegraaf.nl/*
  124. // @match *://*.adelaidenow.com.au/*
  125. // @match *://*.theadvocate.com.au/*
  126. // @match *://*.theage.com.au/*
  127. // @match *://*.the-american-interest.com/*
  128. // @match *://*.theathletic.com/*
  129. // @match *://*.theathletic.co.uk/*
  130. // @match *://*.theatlantic.com/*
  131. // @match *://*.afr.com/*
  132. // @match *://*.theaustralian.com.au/*
  133. // @match *://*.bizjournals.com/*
  134. // @match *://*.canberratimes.com.au/*
  135. // @match *://*.thecourier.com.au/*
  136. // @match *://*.couriermail.com.au/*
  137. // @match *://*.thecut.com/*
  138. // @match *://*.dailytelegraph.com.au/*
  139. // @match *://*.thediplomat.com/*
  140. // @match *://*.economist.com/*
  141. // @match *://*.theglobeandmail.com/*
  142. // @match *://*.theherald.com.au/*
  143. // @match *://*.thehindu.com/*
  144. // @match *://*.irishtimes.com/*
  145. // @match *://*.kansascity.com/*
  146. // @match *://*.mercurynews.com/*
  147. // @match *://*.themercury.com.au/*
  148. // @match *://*.mcall.com/*
  149. // @match *://*.thenation.com/*
  150. // @match *://*.thenational.scot/*
  151. // @match *://*.newstatesman.com/*
  152. // @match *://*.nytimes.com/*
  153. // @match *://*.newyorker.com/*
  154. // @match *://*.news-gazette.com/*
  155. // @match *://*.theolivepress.es/*
  156. // @match *://*.inquirer.com/*
  157. // @match *://*.thesaturdaypaper.com.au/*
  158. // @match *://*.seattletimes.com/*
  159. // @match *://*.spectator.com.au/*
  160. // @match *://*.spectator.co.uk/*
  161. // @match *://*.smh.com.au/*
  162. // @match *://*.telegraph.co.uk/*
  163. // @match *://*.thestar.com/*
  164. // @match *://*.wsj.com/*
  165. // @match *://*.washingtonpost.com/*
  166. // @match *://*.thewrap.com/*
  167. // @match *://*.themarker.com/*
  168. // @match *://*.the-tls.co.uk/*
  169. // @match *://*.towardsdatascience.com/*
  170. // @match *://*.trouw.nl/*
  171. // @match *://*.tubantia.nl/*
  172. // @match *://*.vanityfair.com/*
  173. // @match *://*.vn.nl/*
  174. // @match *://*.vulture.com/*
  175. // @match *://*.journalnow.com/*
  176. // @match *://*.wired.com/*
  177. // @match *://*.worldpoliticsreview.com/*
  178. // @match *://*.zeit.de/*
  179. // ==/UserScript==
  180.  
  181. (function () {
  182. 'use strict';
  183.  
  184. const placeholderFn = () => { };
  185. // Running as a user script, the script needs to be patched for the missing Chrome APIs
  186. const extensionApi = {
  187. "runtime": {
  188. "sendMessage": placeholderFn,
  189. "openOptionsPage": placeholderFn,
  190. "onInstalled": {
  191. "addListener": placeholderFn
  192. },
  193. "lastError": null
  194. },
  195. "storage": {
  196. "sync": {
  197. "set": placeholderFn,
  198. "get": placeholderFn
  199. },
  200. "onChanged": {
  201. "addListener": placeholderFn
  202. }
  203. },
  204. "tabs": {
  205. "onUpdated": {
  206. "addListener": placeholderFn
  207. },
  208. "onActivated": {
  209. "addListener": placeholderFn
  210. },
  211. "get": placeholderFn,
  212. "executeScript": placeholderFn
  213. },
  214. "browserAction": {
  215. "setBadgeBackgroundColor": placeholderFn,
  216. "setBadgeText": placeholderFn
  217. },
  218. "webRequest": {
  219. "onBeforeRequest": {
  220. "addListener": placeholderFn
  221. },
  222. "onHeadersReceived": {
  223. "addListener": placeholderFn
  224. },
  225. "OnBeforeSendHeadersOptions": placeholderFn,
  226. "onBeforeSendHeaders": {
  227. "addListener": placeholderFn
  228. },
  229. "onCompleted": {
  230. "addListener": placeholderFn
  231. }
  232. },
  233. "cookies": {
  234. "getAll": placeholderFn,
  235. "remove": placeholderFn
  236. }
  237. };
  238.  
  239. if (!matchDomain(['seekingalpha.com', 'sfchronicle.com', 'cen.acs.org', 'elmundo.es', 'scmp.com', 'nytimes.com'])) {
  240. window.localStorage.clear();
  241. }
  242.  
  243. if (matchDomain('elmercurio.com')) {
  244. if (window.location.href.toLowerCase().includes('/inversiones/')) {
  245. document.addEventListener('DOMContentLoaded', () => {
  246. const paywall = document.querySelector('#modal_limit_articulos');
  247. const body = document.querySelector('body');
  248. removeDOMElement(paywall);
  249. if (body.hasAttribute('class')) { body.removeAttribute('class'); }
  250. });
  251. }
  252. } else if (matchDomain('estadao.com.br')) {
  253. setTimeout(function () {
  254. const paywall = document.querySelector('#paywall-wrapper-iframe-estadao');
  255. const body = document.querySelector('html');
  256.  
  257. removeDOMElement(paywall);
  258. body.removeAttribute('style');
  259. }, 300); // Delay (in milliseconds)
  260. } else if (matchDomain('rep.repubblica.it')) {
  261. window.setTimeout(function () {
  262. if (window.location.href.includes('/pwa/')) {
  263. window.location.href = window.location.href.replace('/pwa/', '/ws/detail/');
  264. }
  265. }, 500);
  266. if (window.location.href.includes('/ws/detail/')) {
  267. const paywall = document.querySelector('.paywall');
  268. if (paywall) {
  269. ampUnhideSubscriptionsSection();
  270. }
  271. }
  272. } else if (matchDomain('americanbanker.com')) {
  273. const inlineGate = document.querySelector('.inline-gate');
  274. if (inlineGate) {
  275. inlineGate.classList.remove('inline-gate');
  276. const inlineGated = document.querySelectorAll('.inline-gated');
  277. for (const elem of inlineGated) { elem.classList.remove('inline-gated'); }
  278. }
  279. } else if (matchDomain('telegraaf.nl')) {
  280. if (window.location.href.startsWith('https://www.telegraaf.nl/error?ref=/')) {
  281. window.location.href = window.location.href.split('&')[0].replace('error?ref=/', '');
  282. }
  283. const articleWrapper = document.querySelector('.ArticlePageWrapper__uid');
  284. const spotXBanner = document.querySelector('.ArticleBodyBlocks__inlineArticleSpotXBanner');
  285. const paywall = document.querySelector('.PopupBackdrop__block');
  286. removeDOMElement(spotXBanner, paywall);
  287. const premium = document.querySelector('.PremiumLabelWithLine__body');
  288. const articleId = articleWrapper ? articleWrapper.innerText : '123';
  289. const articleBodyDone = document.querySelector('#articleBody' + articleId);
  290. if (premium && !articleBodyDone) {
  291. const articleBodyOld = document.querySelector('[id^=articleBody]');
  292. removeDOMElement(articleBodyOld);
  293. const json = document.querySelector('script[type="application/ld+json"][data-react-helmet="true"]');
  294. if (json) {
  295. const jsonText = JSON.parse(json.text).articleBody;
  296. const articleBody = document.querySelector('section.TextArticlePage__bodyText');
  297. if (articleBody) {
  298. const divMain = document.createElement('div');
  299. divMain.setAttribute('id', 'articleBody' + articleId);
  300. const divElem = document.createElement('div');
  301. divElem.setAttribute('data-element', 'articleBodyBlocks');
  302. const textArray = jsonText.split('\n\n');
  303. textArray.forEach(pText => {
  304. const pDiv = document.createElement('p');
  305. pDiv.setAttribute('class', 'ArticleBodyBlocks__paragraph ArticleBodyBlocks__paragraph--nieuws');
  306. pDiv.innerText = pText;
  307. divElem.appendChild(pDiv);
  308. });
  309. divMain.appendChild(divElem);
  310. articleBody.appendChild(divMain);
  311. }
  312. }
  313. }
  314. } else if (matchDomain('nrc.nl')) {
  315. const paywall = document.querySelector('.paywall--topbanner');
  316. removeDOMElement(paywall);
  317. } else if (matchDomain('washingtonpost.com')) {
  318. const leaderboard = document.querySelector('#leaderboard-wrapper');
  319. const adverts = document.querySelectorAll('div[data-qa="article-body-ad"]');
  320. const softwall = document.querySelector('[id^="softwall"]');
  321. removeDOMElement(leaderboard, softwall, ...adverts);
  322. if (window.location.href.includes('/gdpr-consent/')) {
  323. const freeButton = document.querySelector('.gdpr-consent-container .continue-btn.button.free');
  324. if (freeButton) { freeButton.click(); }
  325. window.setTimeout(function () {
  326. const gdprcheckbox = document.querySelector('.gdpr-consent-container .consent-page:not(.hide) #agree');
  327. if (gdprcheckbox) {
  328. gdprcheckbox.checked = true;
  329. gdprcheckbox.dispatchEvent(new Event('change'));
  330. document.querySelector('.gdpr-consent-container .consent-page:not(.hide) .continue-btn.button.accept-consent').click();
  331. }
  332. }, 300); // Delay (in milliseconds)
  333. } else {
  334. const url = window.location.href;
  335. function main(element) {
  336. removeDOMElement(element);
  337. window.location.href = url.split('?')[0] + '?outputType=amp';
  338. }
  339. if (!url.includes('outputType=amp')) {
  340. waitDOMElement('div[id^="paywall-"]', 'DIV', main, false);
  341. } else {
  342. const subscriptionsSections = document.querySelectorAll('[subscriptions-section="content"]');
  343. for (const subscriptionsSection of subscriptionsSections) { subscriptionsSection.removeAttribute('subscriptions-section'); }
  344. }
  345. }
  346. } else if (matchDomain('wsj.com') && !matchDomain('cn.wsj.com')) {
  347. if (window.location.href.includes('/articles/')) {
  348. const closeButton = document.querySelector('div.close-btn[role="button"]');
  349. if (closeButton) { closeButton.click(); }
  350. }
  351. document.addEventListener('DOMContentLoaded', () => {
  352. const url = window.location.href;
  353. const snippet = document.querySelector('.snippet-promotion');
  354. const wsjPro = document.querySelector('meta[name="page.site"][content="wsjpro"]');
  355. if (snippet || wsjPro) {
  356. if (!window.location.hash) {
  357. if (url.includes('?')) {
  358. window.location.href = url.replace('?', '#refreshed?');
  359. } else { window.location.href = url + '#refreshed'; }
  360. } else { window.location.href = window.location.href.replace('wsj.com', 'wsj.com/amp').replace('#refreshed', ''); }
  361. }
  362. });
  363. } else if (matchDomain('sloanreview.mit.edu')) {
  364. const readMore = document.querySelector('.btn-read-more');
  365. if (readMore) {
  366. readMore.click();
  367. }
  368. } else if (matchDomain('mexiconewsdaily.com')) {
  369. window.setTimeout(function () {
  370. const popup = document.querySelector('div.pigeon-widget-prompt');
  371. const cproOverlay = document.querySelector('.cpro-overlay');
  372. removeDOMElement(popup, cproOverlay);
  373. }, 500); // Delay (in milliseconds)
  374. } else if (matchDomain('the-american-interest.com')) {
  375. const counter = document.getElementById('article-counter');
  376. removeDOMElement(counter);
  377. } else if (matchDomain('nzherald.co.nz')) {
  378. const articleContent = document.querySelector('.article__content');
  379. if (articleContent) {
  380. const articleOffer = document.querySelector('.article-offer');
  381. if (articleOffer) {
  382. const cssSelector = articleContent.querySelectorAll('p')[5].getAttribute('class');
  383. const hiddenNotPars = articleContent.querySelectorAll('.' + cssSelector + ':not(p)');
  384. for (const hiddenNotPar of hiddenNotPars) {
  385. hiddenNotPar.classList.remove(cssSelector);
  386. hiddenNotPar.removeAttribute('style');
  387. }
  388. const hiddenPars = articleContent.querySelectorAll('p.' + cssSelector);
  389. const parser = new DOMParser();
  390. for (const hiddenPar of hiddenPars) {
  391. const parHtml = parser.parseFromString('<div style="margin: 10px 0px; font-size: 17px">' + hiddenPar.innerHTML + '</div>', 'text/html');
  392. const parDom = parHtml.querySelector('div');
  393. articleContent.insertBefore(parDom, hiddenPar);
  394. }
  395. const firstSpan = document.querySelector('p > span');
  396. if (firstSpan) { firstSpan.removeAttribute('class'); }
  397. removeDOMElement(articleOffer);
  398. }
  399. }
  400. const premiumToaster = document.querySelector('#premium-toaster');
  401. removeDOMElement(premiumToaster);
  402. } else if (matchDomain('interest.co.nz')) {
  403. const wrapper = document.getElementById('pp-ablock-banner-wrapper');
  404. const overlay = document.querySelector('.black-overlay');
  405. removeDOMElement(overlay, wrapper);
  406. } else if (matchDomain('stuff.co.nz')) {
  407. const overlay = document.querySelector('.x0');
  408. removeDOMElement(overlay);
  409. } else if (matchDomain('thenational.scot')) {
  410. const overlay = document.querySelector('.template-container');
  411. removeDOMElement(overlay);
  412. } else if (matchDomain('thestar.com')) {
  413. setTimeout(function () {
  414. const paywall = document.querySelector('.basic-paywall-new');
  415. removeDOMElement(paywall);
  416. const tbc = document.querySelectorAll('.text-block-container');
  417. for (const el of tbc) {
  418. el.removeAttribute('style');
  419. }
  420. }, 1000); // Delay (in milliseconds)
  421. } else if (matchDomain('afr.com')) {
  422. document.addEventListener('DOMContentLoaded', () => {
  423. const hiddenImage = document.querySelectorAll('img');
  424. for (const image of hiddenImage) {
  425. const src = image.src;
  426. if ('src: ' + src.indexOf('.gif') !== -1) {
  427. const dataSrc = image.getAttribute('data-src');
  428. if (dataSrc) {
  429. image.setAttribute('src', dataSrc);
  430. }
  431. }
  432. }
  433. const plista = document.querySelector('div[data-plista-placement="underArticle_Group"]');
  434. removeDOMElement(plista);
  435. });
  436. } else if (matchDomain(['parool.nl', 'trouw.nl', 'volkskrant.nl', 'demorgen.be', 'humo.be'])) {
  437. document.addEventListener('DOMContentLoaded', () => {
  438. const topBanner = document.querySelector('div[data-temptation-position="PAGE_TOP"]');
  439. const paywall = document.querySelector('div[data-temptation-position="ARTICLE_BOTTOM"]');
  440. const hiddenSection = document.querySelector('div[data-temptation-position="ARTICLE_INLINE"]');
  441. const overlay = document.querySelector('div[data-temptation-position="PAGE_BOTTOM"]');
  442. removeDOMElement(topBanner, paywall, hiddenSection, overlay);
  443. });
  444. } else if (matchDomain('firstthings.com')) {
  445. const paywall = document.getElementsByClassName('paywall')[0];
  446. removeDOMElement(paywall);
  447. } else if (matchDomain('bloomberg.com')) {
  448. blockElement('#graphics-paywall-overlay', true);
  449. } else if (matchDomain('bloombergquint.com')) {
  450. const articlesLeftModal = document.getElementsByClassName('paywall-meter-module__story-paywall-container__1UgCE')[0];
  451. const paywall = document.getElementById('paywallDmp');
  452. removeDOMElement(articlesLeftModal, paywall);
  453. } else if (matchDomain('medium.com') || document.querySelector('script[src^="https://cdn-client.medium.com/"]')) {
  454. const paywall = document.querySelector('div#paywall-background-color');
  455. removeDOMElement(paywall);
  456. if (paywall) {
  457. extensionApi.runtime.sendMessage({ request: 'refreshCurrentTab' });
  458. }
  459. window.setTimeout(function () {
  460. const meter = document.querySelector('[id*="highlight-meter-"]');
  461. if (meter) {
  462. meter.hidden = true;
  463. }
  464. }, 500); // Delay (in milliseconds)
  465. } else if (matchDomain('theglobeandmail.com')) {
  466. const articleBodySubscribed = document.querySelector('.c-article-body--subscribed');
  467. if (articleBodySubscribed) {
  468. articleBodySubscribed.removeAttribute('class');
  469. }
  470. } else if (matchDomain(['examiner.com.au', 'thecourier.com.au', 'theadvocate.com.au'])) {
  471. const subscribeTruncate = document.querySelector('.subscribe-truncate');
  472. if (subscribeTruncate) { subscribeTruncate.classList.remove('subscribe-truncate'); }
  473. const subscriberHider = document.querySelectorAll('.subscriber-hider');
  474. for (const el of subscriberHider) {
  475. el.classList.remove('subscriber-hider');
  476. }
  477. } else if (matchDomain('canberratimes.com.au')) {
  478. const paywall = document.querySelector('.subscribe-article.news-article-body.article__body');
  479. paywall.classList.remove('subscribe-article');
  480. const subscribe = document.getElementsByClassName('subscriber-container')[0];
  481. removeDOMElement(subscribe);
  482. const content = document.getElementsByClassName('subscriber-hider');
  483. for (const el of content) {
  484. el.classList.remove('subscriber-hider');
  485. }
  486. } else if (matchDomain('ledevoir.com')) {
  487. const counter = document.querySelector('.full.hidden-print.popup-msg');
  488. removeDOMElement(counter);
  489. } else if (matchDomain('ft.com')) {
  490. const cookieBanner = document.querySelector('.o-banner__outer');
  491. const ribbon = document.querySelector('.js-article-ribbon');
  492. const ads = document.querySelector('.o-ads');
  493. removeDOMElement(cookieBanner, ads, ribbon);
  494. } else if (matchDomain('thehindu.com')) {
  495. document.addEventListener('DOMContentLoaded', () => {
  496. const counter = document.querySelector('#test');
  497. const coBanner = document.querySelector('.co-banner');
  498. const support = document.querySelector('div.support-jlm');
  499. removeDOMElement(counter, coBanner, support);
  500. });
  501. } else if (matchDomain('nytimes.com')) {
  502. const banners = document.querySelectorAll('div[data-testid="inline-message"], div[id^="ad-"], div.expanded-dock, div.pz-ad-box');
  503. removeDOMElement(...banners);
  504. } else if (matchDomain('technologyreview.com')) {
  505. window.setTimeout(function () {
  506. const bodyObscured = document.querySelector('body[class*="body__obscureContent"]');
  507. if (bodyObscured) { removeClassesByPrefix(bodyObscured, 'body__obscureContent'); }
  508. const overlay = document.querySelector('div[class*="overlayFooter__wrapper"]');
  509. if (overlay) { overlay.setAttribute('style', 'display:none'); }
  510. const contentBodyHidden = document.querySelector('div[class*="contentBody__contentHidden"]');
  511. if (contentBodyHidden) { removeClassesByPrefix(contentBodyHidden, 'contentBody__contentHidden'); }
  512. const contentBodyOverlay = document.querySelector('div[class*="contentBody__overlay"]');
  513. if (contentBodyOverlay) { contentBodyOverlay.removeAttribute('class'); }
  514. }, 500);
  515. } else if (matchDomain('leparisien.fr')) {
  516. window.removeEventListener('scroll', this.scrollListener);
  517. const paywall = document.querySelector('.relative.piano-paywall.below_nav.sticky');
  518. removeDOMElement(paywall);
  519. setTimeout(function () {
  520. const content = document.getElementsByClassName('content');
  521. for (const el of content) {
  522. el.removeAttribute('style');
  523. }
  524. }, 300); // Delay (in milliseconds)
  525. } else if (matchDomain('caixinglobal.com')) {
  526. const payTips = document.querySelectorAll('.cons-pay-tip');
  527. for (const payTip of payTips) {
  528. payTip.removeAttribute('style');
  529. }
  530. const appContent = document.getElementById('appContent');
  531. if (appContent) {
  532. const pHidden = document.querySelectorAll('p:not([style="display:block;"]');
  533. for (const el of pHidden) {
  534. el.setAttribute('style', 'display:block;');
  535. }
  536. }
  537. } else if (matchDomain('bizjournals.com')) {
  538. const sheetOverlay = document.querySelector('.sheet-overlay');
  539. const chunkPaywall = document.querySelector('.chunk--paywall');
  540. removeDOMElement(sheetOverlay, chunkPaywall);
  541. const overlaid = document.querySelectorAll('.is-overlaid');
  542. for (const el of overlaid) {
  543. el.classList.remove('is-overlaid');
  544. }
  545. const bodyHidden = document.querySelector('.js-pre-chunks__story-body');
  546. bodyHidden.removeAttribute('style');
  547. } else if (matchDomain('the-tls.co.uk')) {
  548. const paywall = document.querySelector('.tls-subscriptions-banner__closed-skin');
  549. removeDOMElement(paywall);
  550. } else if (matchDomain('cen.acs.org')) {
  551. const paywall = document.querySelector('.meteredBar');
  552. removeDOMElement(paywall);
  553. } else if (matchDomain('elperiodico.com')) {
  554. setTimeout(function () {
  555. const unavailableArea = document.querySelector('.closed');
  556. const infoBox = document.querySelector('.ep-masPeriodico-info');
  557. if (unavailableArea) {
  558. unavailableArea.classList.remove('closed');
  559. }
  560. if (infoBox) {
  561. infoBox.parentNode.removeChild(infoBox);
  562. }
  563. }, 1000);
  564. } else if (matchDomain('techinasia.com')) {
  565. const paywall = document.querySelector('.paywall-content');
  566. if (paywall) {
  567. paywall.classList.remove('paywall-content');
  568. }
  569. const splashSubscribe = document.querySelector('.splash-subscribe');
  570. const paywallHard = document.querySelector('.paywall-hard');
  571. removeDOMElement(splashSubscribe, paywallHard);
  572. } else if (matchDomain('thewrap.com')) {
  573. const embed = document.querySelector('.embed');
  574. if (embed) {
  575. // Display feature video
  576. const container = document.querySelector('.featured-image-container');
  577. removeDOMElement(container);
  578. embed.classList.remove('d-none');
  579. }
  580. } else if (matchDomain('hbr.org')) {
  581. const banner = document.querySelector('.persistent-banner');
  582. removeDOMElement(banner);
  583. } else if (matchDomain('spectator.co.uk')) {
  584. const banner = document.querySelector('#subscribe-ribbon');
  585. removeDOMElement(banner);
  586. } else if (matchDomain('barrons.com')) {
  587. const url = window.location.href;
  588. if (!url.includes('barrons.com/amp/')) {
  589. const bodyContinuous = document.querySelector('body.is-continuous');
  590. const snippet = document.querySelector('meta[content="snippet"]');
  591. if (bodyContinuous && snippet) {
  592. removeDOMElement(snippet);
  593. window.location.href = url.replace('barrons.com', 'barrons.com/amp');
  594. }
  595. const signinLinks = document.querySelectorAll('a.primary-button--link[href*="target="]');
  596. for (const signinLink of signinLinks) {
  597. signinLink.href = decodeURIComponent(signinLink.href.split('target=')[1]).split('?')[0];
  598. signinLink.text = 'Click';
  599. }
  600. const barronsAds = document.querySelectorAll('.barrons-body-ad-placement');
  601. removeDOMElement(...barronsAds);
  602. } else {
  603. const preview = document.querySelector('section[subscriptions-section="content-not-granted"]');
  604. removeDOMElement(preview);
  605. const subscrSection = document.querySelector('section[subscriptions-section="content"]');
  606. if (subscrSection) {
  607. subscrSection.removeAttribute('subscriptions-section');
  608. }
  609. }
  610. removeDOMElement(document.querySelector('.login-section-container'));
  611. } else if (matchDomain('nzz.ch')) {
  612. const paywall = document.querySelector('.dynamic-regwall');
  613. removeDOMElement(paywall);
  614. } else if (matchDomain('irishtimes.com')) {
  615. document.addEventListener('DOMContentLoaded', () => {
  616. const stubArticleMsg = document.querySelector('div.stub-article-msg');
  617. const url = window.location.href;
  618. if (url.includes('mode=sample') || stubArticleMsg) { window.location.href = new URL(url).pathname + '?mode=amp'; }
  619. });
  620. } else if (matchDomain('thesaturdaypaper.com.au')) {
  621. const paywall = document.querySelector('div.paywall-hard-always-show');
  622. removeDOMElement(paywall);
  623. } else if (matchDomain('lesechos.fr') && window.location.href.match(/-\d{6,}/)) {
  624. window.setTimeout(function () {
  625. const aboBanner = document.querySelector('[class^="pgxf3b"]');
  626. const adBlocks = document.querySelectorAll('[class*="jzxvkd"');
  627. for (const adBlock of adBlocks) { adBlock.setAttribute('style', 'display:none'); }
  628. if (aboBanner) {
  629. removeDOMElement(aboBanner);
  630. const url = window.location.href;
  631. const html = document.documentElement.outerHTML;
  632. let state;
  633. const split1 = html.split('window.__PRELOADED_STATE__=')[1];
  634. const split2 = split1.split('</script>')[0].trim();
  635. if (split2.includes('; window.__DATA__=')) { state = split2.split('; window.__DATA__=')[0].trim(); } else { state = split2.substr(0, split2.length - 1); }
  636. try {
  637. const data = JSON.parse(state);
  638. const article = data.article.data.stripes[0].mainContent[0].data.description;
  639. const urlLoaded = data.article.data.path;
  640. if (!url.includes(urlLoaded)) { window.location.reload(true); }
  641. const paywallNode = document.querySelector('.post-paywall');
  642. if (paywallNode) {
  643. const contentNode = document.createElement('div');
  644. const parser = new DOMParser();
  645. const articleHtml = parser.parseFromString('<div>' + article + '</div>', 'text/html');
  646. const articlePar = articleHtml.querySelector('div');
  647. if (articlePar) {
  648. contentNode.appendChild(articlePar);
  649. contentNode.className = paywallNode.className;
  650. paywallNode.parentNode.insertBefore(contentNode, paywallNode);
  651. removeDOMElement(paywallNode);
  652. const paywallLastChildNode = document.querySelector('.post-paywall > :last-child');
  653. if (paywallLastChildNode) {
  654. paywallLastChildNode.setAttribute('style', 'height: auto !important; overflow: hidden !important; max-height: none !important;');
  655. }
  656. }
  657. }
  658. const styleElem = document.head.appendChild(document.createElement('style'));
  659. styleElem.innerHTML = '.post-paywall::after {height: auto !important;}';
  660. } catch (err) {
  661. window.location.reload(true);
  662. }
  663. }
  664. }, 500); // Delay (in milliseconds)
  665. } else if (matchDomain('startribune.com')) {
  666. // remove active class from all elements
  667. document.querySelectorAll('div.ReactModalPortal').forEach(function (el) {
  668. removeDOMElement(el);
  669. });
  670. // Enable Scroll. Reveal Hiddlen Paragraph
  671. document.getElementsByTagName('body')[0].removeAttribute('class');
  672. } else if (matchDomain('seattletimes.com')) {
  673. window.setTimeout(function () {
  674. // remove modal class from all elements
  675. document.querySelectorAll('div.modal').forEach(function (el) {
  676. removeDOMElement(el);
  677. });
  678. // Remove Blurred Style from all matching Divs
  679. document.getElementById('container').removeAttribute('style');
  680. document.querySelectorAll('div[style~="filter"]').forEach(function (el) {
  681. el.removeAttribute('style');
  682. });
  683. document
  684. .querySelectorAll('div[class~="NewsletterSignupSplash"]')
  685. .forEach(function (el) {
  686. el.removeAttribute('class');
  687. });
  688. }, 1000); // Delay (in milliseconds)
  689. } else if (matchDomain('theatlantic.com')) {
  690. // Remove all nudge elements
  691. document.querySelectorAll('div[class*="c-nudge"]').forEach(function (el) {
  692. removeDOMElement(el);
  693. });
  694. // Remove all FancyBox ads
  695. document.querySelectorAll('div[class*="fancybox"]').forEach(function (el) {
  696. removeDOMElement(el);
  697. });
  698. } else if (matchDomain(['theathletic.com', 'theathletic.co.uk'])) {
  699. window.setInterval(function () {
  700. const paywall = document.querySelector('#slideup-paywall');
  701. const darken = document.querySelector('#darken-overlay');
  702. if (paywall && darken) {
  703. removeDOMElement(paywall);
  704. removeDOMElement(darken);
  705. window.clearInterval();
  706. }
  707. }, 100);
  708.  
  709. const styleElement = document.createElement('style');
  710.  
  711. const cssRules = `
  712. .noscroll {
  713. overflow: auto !important;
  714. height: auto !important;
  715. width: auto !important;
  716. position: static !important;
  717. }
  718. `;
  719.  
  720. styleElement.innerHTML = cssRules;
  721. document.head.appendChild(styleElement);
  722.  
  723. if (!window.location.href.includes('?amp')) {
  724. const paywall = document.querySelectorAll('div#paywall-container, div[subscriptions-action="subscribe"], a.headline-paywall');
  725. const amphtml = document.querySelector('link[rel="amphtml"]');
  726. if (paywall.length && amphtml) {
  727. removeDOMElement(...paywall);
  728. window.setTimeout(function () {
  729. window.location.href = amphtml.href;
  730. }, 500);
  731. }
  732. } else {
  733. ampUnhideSubscriptionsSection();
  734. const subscriptionsActions = document.querySelectorAll('[subscriptions-actions]');
  735. removeDOMElement(...subscriptionsActions);
  736. }
  737. } else if (matchDomain('newyorker.com')) {
  738. blockElement('.paywall-bar', true);
  739. blockElement('.paywall-modal');
  740. } else if (matchDomain('vanityfair.com')) {
  741. const paywall = document.querySelector('.paywall-bar');
  742. removeDOMElement(paywall);
  743. } else if (matchDomain(['postimees.ee', 'elu24.ee'])) {
  744. setTimeout(function () {
  745. // Remove 'adblocker-detected' footer notification
  746. const adblockNotif = document.querySelector('.ad-block-notification-overlay');
  747. removeDOMElement(adblockNotif);
  748. document.body.removeAttribute('style');
  749. }, 800); // Delay (in milliseconds)
  750. } else if (matchDomain('theolivepress.es')) {
  751. const modalBackdrop = document.querySelector('.modal-backdrop');
  752. const paywall = document.querySelector('.ev-open-modal-paywall-REQUIRE_LOGIN_WITH_ENTITLEMENT');
  753. removeDOMElement(modalBackdrop, paywall);
  754.  
  755. for (const clazz of ['ev-modals', 'modal-open']) {
  756. document.body.classList.remove(clazz);
  757. }
  758. } else if (matchDomain('themarker.com')) {
  759. setTimeout(function () {
  760. const paywall = document.querySelector('[data-test="bottomStrip"]');
  761. const notifications = document.querySelector('#pwSubscribePopup');
  762. const banner = document.querySelector('#themarker\\.com\\.billboard\\.desktop');
  763. const newsBanner = document.querySelector('#themarker\\.com\\.news\\.banner');
  764. const midBanner = document.querySelector('#themarker\\.com.headline\\.banner\\.desktop');
  765. const financeBanner = document.querySelector('#themarker\\.com\\.finance\\.banner');
  766. const topStrip = document.querySelector('[data-test="topStrip"]');
  767. const otherBanners = Array.from(document.querySelectorAll('[data-audtarget]'));
  768. removeDOMElement(paywall, notifications, banner, topStrip, midBanner, newsBanner, financeBanner, ...otherBanners);
  769. }, 500);
  770. } else if (matchDomain('haaretz.co.il')) {
  771. setTimeout(function () {
  772. const notifications = document.querySelector('#pwSubscribePopup');
  773. const paywall = document.querySelector('[data-test="bottomStrip"]');
  774. const banner = document.querySelector('#haaretz\\.co\\.il\\.billboard\\.desktop');
  775. const editorsBanner = document.querySelector('#haaretz\\.co\\.il\\.editors\\.banner');
  776. const headlinesBanner = document.querySelector('#haaretz\\.co\\.il\\.headline\\.box\\.desktop');
  777. const topStrip = document.querySelector('[data-test="topStrip"]');
  778. const otherBanners = Array.from(document.querySelectorAll('[data-audtarget]'));
  779. removeDOMElement(paywall, notifications, banner, editorsBanner, topStrip, headlinesBanner, ...otherBanners);
  780. }, 500);
  781. } else if (matchDomain('sueddeutsche.de')) {
  782. const url = window.location.href;
  783. document.addEventListener('DOMContentLoaded', () => {
  784. const offerPage = document.querySelector('div.offer-page');
  785. if (url.startsWith('https://www.sueddeutsche.de') && (url.includes('reduced=true') || offerPage)) { window.location.href = url.split('?')[0].replace('www.', 'amphtml.'); } else if (url.startsWith('https://sz-magazin.sueddeutsche.de')) {
  786. if (url.includes('reduced=true') || offerPage) { window.location.href = new URL(url).pathname + '!amp'; }
  787. }
  788. });
  789. window.setTimeout(function () {
  790. if (url.includes('!amp')) {
  791. const paragraphReduced = document.querySelector('.paragraph--reduced');
  792. if (paragraphReduced) { paragraphReduced.classList.remove('paragraph--reduced'); }
  793. const paragraphHidden = document.querySelectorAll('.paragraph--hidden');
  794. for (const parHidden of paragraphHidden) { parHidden.classList.remove('paragraph--hidden'); }
  795. const paragraphDynamic = document.querySelector('.paragraph--dynamic');
  796. if (paragraphDynamic) { paragraphDynamic.classList.remove('paragraph--dynamic'); }
  797. const ampOfferpage = document.querySelector('.amp-offerpage');
  798. removeDOMElement(ampOfferpage);
  799. }
  800. }, 500); // Delay (in milliseconds)
  801. } else if (matchDomain('adweek.com')) {
  802. const bodySingle = document.querySelector('body.single');
  803. const ampHtml = document.querySelector('link[rel="amphtml"]');
  804. if (bodySingle && ampHtml) {
  805. bodySingle.classList.remove('single');
  806. window.location.href = ampHtml.href;
  807. }
  808. } else if (matchDomain('gelocal.it')) {
  809. if (!window.location.href.includes('/amp/')) {
  810. const paywallAdagio = document.querySelector('.paywall-adagio');
  811. removeDOMElement(paywallAdagio);
  812. } else {
  813. const paywall = document.querySelector('div[amp-access="showContent"]');
  814. if (paywall) { paywall.removeAttribute('amp-access-hide'); }
  815. const ampAds = document.querySelectorAll('amp-ad');
  816. removeDOMElement(...ampAds);
  817. }
  818. } else if (matchDomain('elmundo.es')) {
  819. const premium = document.querySelector('.ue-c-article__premium');
  820. const url = window.location.href;
  821. if (!url.includes('/amp.' + 'elmundo.es' + '/')) {
  822. if (premium) {
  823. removeDOMElement(premium);
  824. window.location.href = window.location.href.replace('/www.', '/amp.');
  825. }
  826. } else {
  827. const paywall = document.querySelector('div[amp-access="authorized!=true"]');
  828. if (paywall) {
  829. removeDOMElement(paywall);
  830. const divHidden = document.querySelector('div[amp-access="authorized=true"]');
  831. if (divHidden) {
  832. divHidden.removeAttribute('amp-access-hide');
  833. }
  834. }
  835. const advertising = document.querySelectorAll('.advertising, amp-embed');
  836. removeDOMElement(...advertising);
  837. }
  838. } else if (matchDomain('speld.nl')) {
  839. const paywallPopup = document.querySelector('.c-paywall-notice');
  840. removeDOMElement(paywallPopup);
  841. } else if (matchDomain('lastampa.it')) {
  842. const url = window.location.href;
  843. if (!url.includes('/amp/')) {
  844. const premium = document.querySelector('.paywall-adagio');
  845. removeDOMElement(premium);
  846. window.setTimeout(function () {
  847. if (premium) {
  848. window.location.href = url.split('?')[0] + '/amp/';
  849. }
  850. const articleBody = document.querySelector('div#article-body[style]');
  851. if (articleBody) {
  852. articleBody.removeAttribute('style');
  853. }
  854. }, 500);
  855. } else {
  856. const paywall = document.querySelector('div[id^="paywall-banner"]');
  857. removeDOMElement(paywall);
  858. const subscriptionSection = document.querySelector('[subscriptions-section="content"]');
  859. if (subscriptionSection) {
  860. subscriptionSection.removeAttribute('subscriptions-section');
  861. const preview = document.querySelector('div[subscriptions-section="content-not-granted"]');
  862. removeDOMElement(preview);
  863. }
  864. const ampAds = document.querySelectorAll('amp-ad, amp-embed');
  865. removeDOMElement(...ampAds);
  866. }
  867. } else if (matchDomain('time.com')) {
  868. const body = document.querySelector('body');
  869. if (body) {
  870. body.setAttribute('style', 'position:relative !important;');
  871. }
  872. } else if (matchDomain('expansion.com')) {
  873. const premium = document.querySelector('.ue-c-article__premium');
  874. const url = window.location.href;
  875. if (!url.includes('/amp.' + 'expansion.com' + '/')) {
  876. if (premium) {
  877. removeDOMElement(premium);
  878. window.location.href = window.location.href.replace('/www.', '/amp.');
  879. }
  880. } else {
  881. const paywall = document.querySelector('div[amp-access="authorized!=true"]');
  882. if (paywall) {
  883. removeDOMElement(paywall);
  884. const divHidden = document.querySelector('div[amp-access="authorized=true"]');
  885. if (divHidden) {
  886. divHidden.removeAttribute('amp-access-hide');
  887. }
  888. }
  889. const advertising = document.querySelectorAll('.advertising, amp-embed');
  890. removeDOMElement(...advertising);
  891. }
  892. } else if (matchDomain('chicagobusiness.com')) {
  893. const body = document.querySelector('body[class]');
  894. if (body) {
  895. body.removeAttribute('class');
  896. }
  897. } else if (matchDomain('latimes.com')) {
  898. const paywall = document.querySelector('metering-modal');
  899. const incognitoWall = document.querySelector('metering-toppanel');
  900. if (paywall) {
  901. removeDOMElement(paywall);
  902. } else if (incognitoWall) {
  903. removeDOMElement(incognitoWall);
  904. }
  905. if (paywall || incognitoWall) {
  906. document.body.removeAttribute('style');
  907. }
  908. } else if (matchDomain('foreignpolicy.com')) {
  909. const contentUngated = document.querySelector('div.content-ungated');
  910. removeDOMElement(contentUngated);
  911. const contentGated = document.querySelector('div.content-gated');
  912. if (contentGated) {
  913. contentGated.classList.remove('content-gated');
  914. }
  915. } else if (matchDomain('bostonglobe.com')) {
  916. // Remove the portion covering the paywall
  917. const paywall = document.querySelector('div.meter-paywall');
  918. if (paywall) {
  919. removeDOMElement(paywall);
  920. }
  921. // Re-enable scrolling
  922. const body = document.querySelector('body');
  923. if (body) {
  924. document.body.removeAttribute('style');
  925. }
  926. // Click the button to reveal the rest of the article
  927. const buttonDiv = document.querySelector('[id="continue_button"]');
  928. if (buttonDiv) {
  929. const button = buttonDiv.querySelector('button');
  930. if (button) {
  931. button.click();
  932. }
  933. }
  934. } else if (matchDomain('nationalgeographic.com')) {
  935. // prevent modal from showing up, then remove scroll-locking, and article blur
  936. new window.MutationObserver(function (mutations) {
  937. for (const mutation of mutations) {
  938. for (const node of mutation.addedNodes) {
  939. if (node instanceof window.HTMLElement) {
  940. if (node.matches('#fittPortal_0')) {
  941. removeDOMElement(node);
  942. const body = document.body;
  943. body.removeAttribute('class');
  944. body.removeAttribute('style');
  945. body.removeAttribute('overflow');
  946. const blur = document.querySelector('#natgeo-template1-frame-1-module-1 > div > div > section > article > section > div.Article__Content__Overlay--gated');
  947. if (blur) removeDOMElement(blur);
  948.  
  949. this.disconnect(); // Stop watching for element being added after one removal
  950. }
  951. }
  952. }
  953. }
  954. }).observe(document, { subtree: true, childList: true });
  955. } else if (matchDomain('hbrchina.org')) {
  956. const hiddenDiv = document.querySelector('div#the_content');
  957. if (hiddenDiv) {
  958. hiddenDiv.removeAttribute('style');
  959. }
  960. } else if (matchDomain('scmp.com')) {
  961. if (window.location.href.includes('/amp.')) {
  962. const divHidden = document.querySelectorAll('div.article-body[amp-access][amp-access-hide]');
  963. for (const elem of divHidden) {
  964. elem.removeAttribute('amp-access-hide');
  965. }
  966. const defaultMeters = document.querySelectorAll('div.default-meter, div#archive-article-meter');
  967. const ads = document.querySelectorAll('amp-ad, div.ad-banner, div.advert-fly-carpet-container, div.inline-advert');
  968. removeDOMElement(...defaultMeters, ...ads);
  969. }
  970. } else if (matchDomain('fortune.com')) {
  971. const paywalledArticle = document.querySelector('.paywall.paywallActive');
  972. if (paywalledArticle) {
  973. for (const clazz of ['paywall', 'paywallActive']) {
  974. paywalledArticle.classList.remove(clazz);
  975. }
  976. }
  977. }
  978.  
  979. function matchDomain(domains) {
  980. const hostname = window.location.hostname;
  981. if (typeof domains === 'string') { domains = [domains]; }
  982. return domains.some(domain => hostname === domain || hostname.endsWith('.' + domain));
  983. }
  984.  
  985. function waitDOMElement(selector, tagName = '', callback, multiple = false) {
  986. new window.MutationObserver(function (mutations) {
  987. for (const mutation of mutations) {
  988. for (const node of mutation.addedNodes) {
  989. if (!tagName || (node.tagName === tagName)) {
  990. if (node.matches(selector)) {
  991. callback(node);
  992. if (!multiple) { this.disconnect(); }
  993. }
  994. }
  995. }
  996. }
  997. }).observe(document, {
  998. subtree: true,
  999. childList: true
  1000. });
  1001. }
  1002.  
  1003. function removeDOMElement(...elements) {
  1004. for (const element of elements) {
  1005. if (element) { element.remove(); }
  1006. }
  1007. }
  1008.  
  1009. function removeClassesByPrefix(el, prefix) {
  1010. for (const clazz of el.classList) {
  1011. if (clazz.startsWith(prefix)) {
  1012. el.classList.remove(clazz);
  1013. }
  1014. }
  1015. }
  1016.  
  1017. // Prevent element from being added the first time to the DOM
  1018. function blockElement(selector, blockAlways = false) {
  1019. new window.MutationObserver(function (mutations) {
  1020. for (const mutation of mutations) {
  1021. for (const node of mutation.addedNodes) {
  1022. if (node instanceof window.HTMLElement) {
  1023. if (node.matches(selector)) {
  1024. removeDOMElement(node);
  1025. if (!blockAlways) {
  1026. this.disconnect(); // Stop watching for element being added after one removal
  1027. }
  1028. }
  1029. }
  1030. }
  1031. }
  1032. }).observe(document, { subtree: true, childList: true });
  1033. }
  1034.  
  1035. function ampUnhideSubscriptionsSection(ampAdsSel = 'amp-ad, .ad') {
  1036. const preview = document.querySelector('[subscriptions-section="content-not-granted"]');
  1037. removeDOMElement(preview);
  1038. const subscriptionsSection = document.querySelectorAll('[subscriptions-section="content"]');
  1039. for (const elem of subscriptionsSection) {
  1040. elem.removeAttribute('subscriptions-section');
  1041. }
  1042. const ampAds = document.querySelectorAll(ampAdsSel);
  1043. removeDOMElement(...ampAds);
  1044. }
  1045.  
  1046. const restrictions = {
  1047. 'adweek.com': /^((?!\.adweek\.com\/(.+\/)?(amp|agencyspy|tvnewser|tvspy)\/).)*$/,
  1048. 'barrons.com': /.+\.barrons\.com\/(amp\/)?article(s)?\/.+/,
  1049. 'economist.com': /.+economist\.com\/.+\/\d{1,4}\/\d{1,2}\/\d{2}\/.+/,
  1050. 'seekingalpha.com': /.+seekingalpha\.com\/article\/.+/,
  1051. 'techinasia.com': /\.techinasia\.com\/.+/,
  1052. 'ft.com': /.+\.ft.com\/content\//,
  1053. 'nytimes.com': /^((?!\/timesmachine\.nytimes\.com\/).)*$/
  1054. };
  1055.  
  1056. // Don't remove cookies before page load
  1057. const allowCookies = [
  1058. 'brisbanetimes.com.au',
  1059. 'canberratimes.com.au',
  1060. 'cen.acs.org',
  1061. 'demorgen.be',
  1062. 'denverpost.com',
  1063. 'examiner.com.au',
  1064. 'gelocal.it',
  1065. 'grubstreet.com',
  1066. 'harpers.org',
  1067. 'hbr.org',
  1068. 'humo.be',
  1069. 'lesechos.fr',
  1070. 'lrb.co.uk',
  1071. 'medium.com',
  1072. 'mercurynews.com',
  1073. 'newstatesman.com',
  1074. 'nrc.nl',
  1075. 'nymag.com',
  1076. 'ocregister.com',
  1077. 'parool.nl',
  1078. 'qz.com',
  1079. 'scientificamerican.com',
  1080. 'seattletimes.com',
  1081. 'seekingalpha.com',
  1082. 'sofrep.com',
  1083. 'spectator.co.uk',
  1084. 'speld.nl',
  1085. 'techinasia.com',
  1086. 'telegraaf.nl',
  1087. 'the-american-interest.com',
  1088. 'theadvocate.com.au',
  1089. 'theage.com.au',
  1090. 'theatlantic.com',
  1091. 'theaustralian.com.au',
  1092. 'thecut.com',
  1093. 'thediplomat.com',
  1094. 'themercury.com.au',
  1095. 'towardsdatascience.com',
  1096. 'trouw.nl',
  1097. 'vn.nl',
  1098. 'volkskrant.nl',
  1099. 'vulture.com',
  1100. 'nzz.ch',
  1101. 'thehindu.com',
  1102. 'financialpost.com',
  1103. 'haaretz.co.il',
  1104. 'haaretz.com',
  1105. 'themarker.com',
  1106. 'sueddeutsche.de',
  1107. 'gelocal.it',
  1108. 'elmundo.es',
  1109. 'time.com',
  1110. 'zeit.de',
  1111. 'expansion.com',
  1112. 'dailytelegraph.com.au',
  1113. 'washingtonpost.com'
  1114. ];
  1115.  
  1116. // Removes cookies after page load
  1117. const removeCookies = [
  1118. 'bloomberg.com',
  1119. 'bloombergquint.com',
  1120. 'brisbanetimes.com.au',
  1121. 'canberratimes.com.au',
  1122. 'cen.acs.org',
  1123. 'demorgen.be',
  1124. 'denverpost.com',
  1125. 'examiner.com.au',
  1126. 'globes.co.il',
  1127. 'grubstreet.com',
  1128. 'harpers.org',
  1129. 'hbr.org',
  1130. 'humo.be',
  1131. 'lesechos.fr',
  1132. 'mercurynews.com',
  1133. 'newstatesman.com',
  1134. 'nrc.nl',
  1135. 'nymag.com',
  1136. 'ocregister.com',
  1137. 'qz.com',
  1138. 'scientificamerican.com',
  1139. 'seattletimes.com',
  1140. 'sofrep.com',
  1141. 'spectator.co.uk',
  1142. 'speld.nl',
  1143. 'telegraaf.nl',
  1144. 'theadvocate.com.au',
  1145. 'theage.com.au',
  1146. 'theatlantic.com',
  1147. 'thecut.com',
  1148. 'thediplomat.com',
  1149. 'towardsdatascience.com',
  1150. 'vn.nl',
  1151. 'vulture.com',
  1152. 'wsj.com',
  1153. 'medium.com',
  1154. 'washingtonpost.com',
  1155. 'japantimes.co.jp',
  1156. 'nytimes.com'
  1157. ];
  1158.  
  1159. // Contains remove cookie sites above plus any custom sites
  1160. let _removeCookies = removeCookies;
  1161.  
  1162. // select specific cookie(s) to hold from removeCookies domains
  1163. const removeCookiesSelectHold = {
  1164. 'qz.com': ['gdpr'],
  1165. 'wsj.com': ['wsjregion'],
  1166. 'seattletimes.com': ['st_newsletter_splash_seen']
  1167. };
  1168.  
  1169. // select only specific cookie(s) to drop from removeCookies domains
  1170. const removeCookiesSelectDrop = {
  1171. 'ambito.com': ['TDNotesRead'],
  1172. 'demorgen.be': ['TID_ID'],
  1173. 'fd.nl': ['socialread'],
  1174. 'humo.be': ['TID_ID'],
  1175. 'nrc.nl': ['counter'],
  1176. 'speld.nl': ['speld-paywall']
  1177. };
  1178.  
  1179. // Override User-Agent with Googlebot
  1180. const useGoogleBotSites = [
  1181. 'adelaidenow.com.au',
  1182. 'barrons.com',
  1183. 'couriermail.com.au',
  1184. 'fd.nl',
  1185. 'genomeweb.com',
  1186. 'heraldsun.com.au',
  1187. 'lavoixdunord.fr',
  1188. 'ntnews.com.au',
  1189. 'quora.com',
  1190. 'seekingalpha.com',
  1191. 'telegraph.co.uk',
  1192. 'theaustralian.com.au',
  1193. 'themercury.com.au',
  1194. 'thenational.scot',
  1195. 'wsj.com',
  1196. 'kansascity.com',
  1197. 'republic.ru',
  1198. 'nzz.ch',
  1199. 'df.cl',
  1200. 'ft.com',
  1201. 'wired.com',
  1202. 'zeit.de'
  1203. ];
  1204.  
  1205. // Override User-Agent with Bingbot
  1206. const useBingBot = [];
  1207.  
  1208. const useMsnBot = [
  1209. 'haaretz.co.il',
  1210. 'haaretz.com',
  1211. 'themarker.com'
  1212. ];
  1213.  
  1214. // Contains google bot sites above plus any custom sites
  1215. let _useGoogleBotSites = useGoogleBotSites;
  1216.  
  1217. function setDefaultOptions() {
  1218. extensionApi.storage.sync.set({
  1219. sites: defaultSites
  1220. }, function () {
  1221. extensionApi.runtime.openOptionsPage();
  1222. });
  1223. }
  1224.  
  1225. // Block external scripts
  1226. const blockedRegexes = {
  1227. 'adweek.com': /.+\.lightboxcdn\.com\/.+/,
  1228. 'afr.com': /afr\.com\/assets\/vendorsReactRedux_client.+\.js/,
  1229. 'businessinsider.com': /(.+\.tinypass\.com\/.+|cdn\.onesignal\.com\/sdks\/.+\.js)/,
  1230. 'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\//,
  1231. 'economist.com': /(.+\.tinypass\.com\/.+|economist\.com\/engassets\/_next\/static\/chunks\/framework.+\.js)/,
  1232. 'editorialedomani.it': /(js\.pelcro\.com\/.+|editorialedomani.it\/pelcro\.js)/,
  1233. 'foreignpolicy.com': /(cdn\.cxense\.com\/|\.tinypass\.com\/)/,
  1234. 'fortune.com': /.+\.tinypass\.com\/.+/,
  1235. 'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/,
  1236. 'haaretz.com': /haaretz\.com\/hdc\/web\/js\/minified\/header-scripts-int.js.+/,
  1237. 'inquirer.com': /.+\.tinypass\.com\/.+/,
  1238. 'lastampa.it': /.+\.repstatic\.it\/minify\/sites\/lastampa\/.+\/config\.cache\.php\?name=social_js/,
  1239. 'lrb.co.uk': /.+\.tinypass\.com\/.+/,
  1240. 'medscape.com': /.+\.medscapestatic\.com\/.*medscape-library\.js/,
  1241. 'interest.co.nz': /(.+\.presspatron\.com.+|.+interest\.co\.nz.+pp-ablock-banner\.js)/,
  1242. 'repubblica.it': /scripts\.repubblica\.it\/pw\/pw\.js.+/,
  1243. 'spectator.co.uk': /.+\.tinypass\.com\/.+/,
  1244. 'spectator.com.au': /.+\.tinypass\.com\/.+/,
  1245. 'telegraph.co.uk': /.+telegraph\.co\.uk.+martech.+/,
  1246. 'thecourier.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/,
  1247. 'thenation.com': /thenation\.com\/.+\/paywall-script\.php/,
  1248. 'thenational.scot': /(.+\.tinypass\.com\/.+|.+thenational\.scot.+omniture\.js|.+thenational\.scot.+responsive-sync.+)/,
  1249. 'thewrap.com': /thewrap\.com\/.+\/wallkit\.js/,
  1250. 'wsj.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/,
  1251. 'historyextra.com': /.+\.evolok\.net\/.+\/authorize\/.+/,
  1252. 'barrons.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/,
  1253. 'irishtimes.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/,
  1254. 'elmercurio.com': /(merreader\.emol\.cl\/assets\/js\/merPramV2.js|staticmer\.emol\.cl\/js\/inversiones\/PramModal.+\.js)/,
  1255. 'sloanreview.mit.edu': /(.+\.tinypass\.com\/.+|.+\.netdna-ssl\.com\/wp-content\/themes\/smr\/assets\/js\/libs\/welcome-ad\.js)/,
  1256. 'latercera.com': /.+\.cxense\.com\/+/,
  1257. 'lesechos.fr': /.+\.tinypass\.com\/.+/,
  1258. 'thehindu.com': /ajax\.cloudflare\.com\/cdn-cgi\/scripts\/.+\/cloudflare-static\/rocket-loader\.min\.js/,
  1259. 'technologyreview.com': /.+\.blueconic\.net\/.+/,
  1260. 'spectator.us': /(cdn\.cxense\.com\/.+|\.tinypass\.com\/.+)/,
  1261. 'gelocal.it': /(\.repstatic\.it\/minify\/sites\/gelocal\/.+\/config\.cache(_\d)?\.php|cdn\.ampproject\.org\/v\d\/amp-(access|ad)-.+\.js)/,
  1262. 'elmundo.es': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
  1263. 'time.com': /\/time\.com\/dist\/meter-wall-client-js\..+\.js/,
  1264. 'thestar.com': /\.com\/api\/overlaydata/,
  1265. 'elpais.com': /(\.epimg\.net\/js\/.+\/(noticia|user)\.min\.js|\/elpais\.com\/arc\/subs\/p\.min\.js|cdn\.ampproject\.org\/v\d\/amp-(access|(sticky-)?ad|consent)-.+\.js)/,
  1266. 'expansion.com': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
  1267. 'chicagobusiness.com': /(\.tinypass\.com\/|\.chicagobusiness\.com\/.+\/js\/js_.+\.js)/,
  1268. 'dailytelegraph.com.au': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
  1269. 'theglobeandmail.com': /(\.theglobeandmail\.com\/pf\/dist\/engine\/react\.js|smartwall\.theglobeandmail\.com\/)/,
  1270. 'nytimes.com': /(\.nytimes\.com\/meter\.js|mwcm\.nyt\.com\/.+\.js|cooking\.nytimes\.com\/api\/.+\/access)/,
  1271. 'latimes.com': /(metering\.platform\.latimes\.com\/|cdn\.ampproject\.org\/v\d\/amp-(access|subscriptions)-.+\.js)/,
  1272. 'theathletic.com': /cdn\.ampproject\.org\/v\d\/amp-(access|subscriptions)-.+\.js/,
  1273. 'japantimes.co.jp': /cdn\.cxense\.com\//,
  1274. 'scmp.com': /(\.tinypass\.com\/|cdn\.ampproject\.org\/v\d\/amp-access-.+\.js)/,
  1275. 'ilmessaggero.it': /(utils\.cedsdigital\.it\/js\/PaywallMeter\.js)/,
  1276. 'washingtonpost.com': /\.washingtonpost\.com\/tetro\/metering\/evaluate/
  1277. };
  1278.  
  1279. const userAgentDesktop = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
  1280. const userAgentMobile = 'Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)';
  1281. const userAgentDesktopBingBot = 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)';
  1282. const userAgentMobileBingBot = 'Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)';
  1283. const userAgentMsnBot = 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)';
  1284.  
  1285. let enabledSites = [];
  1286.  
  1287. // Get the enabled sites
  1288. extensionApi.storage.sync.get({
  1289. sites: {},
  1290. customSites: []
  1291. }, function (items) {
  1292. enabledSites = Object.values(items.sites).concat(items.customSites);
  1293.  
  1294. // Use googlebot UA for custom sites
  1295. _useGoogleBotSites = useGoogleBotSites.concat(items.customSites);
  1296.  
  1297. // Remove cookies for custom sites
  1298. _removeCookies = removeCookies.concat(items.customSites);
  1299.  
  1300. // if (extensionApi === chrome) {
  1301. // initGA();
  1302. // }
  1303. });
  1304.  
  1305. // Listen for changes to options
  1306. extensionApi.storage.onChanged.addListener(function (changes, namespace) {
  1307. if (changes.sites && changes.sites.newValue) {
  1308. const sites = changes.sites.newValue;
  1309. enabledSites = Object.values(sites);
  1310. }
  1311. });
  1312.  
  1313. // Set and show default options on install
  1314. extensionApi.runtime.onInstalled.addListener(function (details) {
  1315. if (details.reason === 'install') {
  1316. setDefaultOptions();
  1317. } else if (details.reason === 'update') {
  1318. // User updated extension
  1319. }
  1320. });
  1321.  
  1322. extensionApi.tabs.onUpdated.addListener(function (tabId, info, tab) {
  1323. updateBadge(tab);
  1324. });
  1325. extensionApi.tabs.onActivated.addListener(function (activeInfo) {
  1326. extensionApi.tabs.get(activeInfo.tabId, updateBadge);
  1327. });
  1328.  
  1329. function updateBadge(activeTab) {
  1330. if (extensionApi.runtime.lastError || !activeTab) { return; }
  1331. const badgeText = getBadgeText(activeTab.url);
  1332. extensionApi.browserAction.setBadgeBackgroundColor({ color: 'blue' });
  1333. extensionApi.browserAction.setBadgeText({ text: badgeText });
  1334. }
  1335.  
  1336. function getBadgeText(currentUrl) {
  1337. return currentUrl && isSiteEnabled({ url: currentUrl }) ? 'ON' : '';
  1338. }
  1339.  
  1340. // AMP redirect for dailytelegraph.com.au
  1341. extensionApi.webRequest.onBeforeRequest.addListener(function (details) {
  1342. if (!isSiteEnabled(details)) {
  1343. return;
  1344. }
  1345. const updatedUrl = decodeURIComponent(details.url.split('&dest=')[1].split('&')[0]).replace('www.', 'amp.');
  1346. return { redirectUrl: updatedUrl };
  1347. },
  1348. { urls: ['*://www.dailytelegraph.com.au/subscribe/*'], types: ['main_frame'] },
  1349. ['blocking']
  1350. );
  1351.  
  1352. // nytimes.com
  1353. extensionApi.webRequest.onHeadersReceived.addListener(function (details) {
  1354. if (!isSiteEnabled(details)) {
  1355. return;
  1356. }
  1357. let headers = details.responseHeaders;
  1358. headers = headers.map(function (header) {
  1359. if (header.name === 'x-frame-options') { header.value = 'SAMEORIGIN'; }
  1360. return header;
  1361. });
  1362. return {
  1363. responseHeaders: headers
  1364. };
  1365. }, {
  1366. urls: ['*://*.nytimes.com/*']
  1367. },
  1368. ['blocking', 'responseHeaders']);
  1369.  
  1370. // Disable javascript for these sites
  1371. extensionApi.webRequest.onBeforeRequest.addListener(function (details) {
  1372. const headerReferer = details.originUrl ? details.originUrl : details.initiator;
  1373. if (!isSiteEnabled(details) && (!enabledSites.includes('generalpaywallbypass') || matchUrlDomain('japantimes.co.jp', headerReferer))) {
  1374. return;
  1375. }
  1376. return { cancel: true };
  1377. },
  1378. {
  1379. urls: [
  1380. '*://*.newstatesman.com/*',
  1381. '*://*.outbrain.com/*',
  1382. '*://*.piano.io/*',
  1383. '*://*.poool.fr/*',
  1384. '*://*.qiota.com/*',
  1385. '*://*.tinypass.com/*'
  1386. ],
  1387. types: ['script']
  1388. },
  1389. ['blocking']
  1390. );
  1391.  
  1392. const extraInfoSpec = ['blocking', 'requestHeaders'];
  1393. if (Object.prototype.hasOwnProperty.call(extensionApi.webRequest.OnBeforeSendHeadersOptions, 'EXTRA_HEADERS')) {
  1394. extraInfoSpec.push('extraHeaders');
  1395. }
  1396.  
  1397. extensionApi.webRequest.onBeforeSendHeaders.addListener(function (details) {
  1398. let requestHeaders = details.requestHeaders;
  1399.  
  1400. let headerReferer = '';
  1401. for (const n in requestHeaders) {
  1402. if (requestHeaders[n].name.toLowerCase() === 'referer') {
  1403. headerReferer = requestHeaders[n].value;
  1404. continue;
  1405. }
  1406. }
  1407.  
  1408. // check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
  1409. const blockedDomains = Object.keys(blockedRegexes);
  1410. const domain = matchUrlDomain(blockedDomains, headerReferer);
  1411. if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({ url: headerReferer })) {
  1412. return { cancel: true };
  1413. }
  1414.  
  1415. if (!isSiteEnabled(details) && !matchUrlDomain('cdn.ampproject.org', details.url)) {
  1416. return;
  1417. }
  1418.  
  1419. const tabId = details.tabId;
  1420. let useUserAgentMobile = false;
  1421. let setReferer = false;
  1422.  
  1423. // if referer exists, set it to google
  1424. requestHeaders = requestHeaders.map(function (requestHeader) {
  1425. if (requestHeader.name === 'Referer') {
  1426. if (details.url.includes('cooking.nytimes.com/api/v1/users/bootstrap')) {
  1427. // this fixes images not being loaded on cooking.nytimes.com main page
  1428. // referrer has to be *nytimes.com otherwise returns 403
  1429. requestHeader.value = 'https://cooking.nytimes.com';
  1430. } else if (matchUrlDomain('fd.nl', details.url)) {
  1431. requestHeader.value = 'https://www.facebook.com/';
  1432. } else if (matchUrlDomain('medium.com', details.url)) {
  1433. requestHeader.value = 'https://t.co/x?amp=1';
  1434. } else {
  1435. requestHeader.value = 'https://www.google.com/';
  1436. }
  1437. setReferer = true;
  1438. }
  1439. if (requestHeader.name === 'User-Agent') {
  1440. useUserAgentMobile = requestHeader.value.toLowerCase().includes('mobile');
  1441. }
  1442.  
  1443. return requestHeader;
  1444. });
  1445.  
  1446. // otherwise add it
  1447. if (!setReferer) {
  1448. if (matchUrlDomain('fd.nl', details.url)) {
  1449. requestHeaders.push({
  1450. name: 'Referer',
  1451. value: 'https://www.facebook.com/'
  1452. });
  1453. } else if (matchUrlDomain('medium.com', details.url)) {
  1454. requestHeaders.push({
  1455. name: 'Referer',
  1456. value: 'https://t.co/x?amp=1'
  1457. });
  1458. } else {
  1459. requestHeaders.push({
  1460. name: 'Referer',
  1461. value: 'https://www.google.com/'
  1462. });
  1463. }
  1464. }
  1465.  
  1466. // override User-Agent to use Googlebot
  1467. const useGoogleBot = _useGoogleBotSites.some(function (item) {
  1468. return typeof item === 'string' && matchUrlDomain(item, details.url);
  1469. });
  1470.  
  1471. if (useGoogleBot) {
  1472. requestHeaders.push({
  1473. name: 'User-Agent',
  1474. value: useUserAgentMobile ? userAgentMobile : userAgentDesktop
  1475. });
  1476. requestHeaders.push({
  1477. name: 'X-Forwarded-For',
  1478. value: '66.249.66.1'
  1479. });
  1480. }
  1481.  
  1482. // override User-Agent to use Bingbot
  1483. if (matchUrlDomain(useBingBot, details.url)) {
  1484. requestHeaders.push({
  1485. name: 'User-Agent',
  1486. value: useUserAgentMobile ? userAgentMobileBingBot : userAgentDesktopBingBot
  1487. });
  1488. }
  1489.  
  1490. // override User-Agent to use Google AdsBot Mobile Web
  1491. if (matchUrlDomain(useMsnBot, details.url)) {
  1492. requestHeaders.push({
  1493. name: 'User-Agent',
  1494. value: userAgentMsnBot
  1495. });
  1496. }
  1497.  
  1498. // remove cookies before page load
  1499. const enabledCookies = allowCookies.some(function (site) {
  1500. return matchUrlDomain(site, details.url);
  1501. });
  1502. if (!enabledCookies) {
  1503. requestHeaders = requestHeaders.map(function (requestHeader) {
  1504. if (requestHeader.name === 'Cookie') {
  1505. requestHeader.value = '';
  1506. }
  1507. return requestHeader;
  1508. });
  1509. }
  1510.  
  1511. if (tabId !== -1) {
  1512. extensionApi.tabs.get(tabId, function (currentTab) {
  1513. // Validate url of current tab to avoid injecting script to unrelated sites
  1514. if (currentTab && currentTab.url && isSiteEnabled(currentTab)) {
  1515. // run contentScript inside tab
  1516. extensionApi.tabs.executeScript(tabId, {
  1517. file: 'src/js/contentScript.js',
  1518. runAt: 'document_start'
  1519. }, function (res) {
  1520. if (extensionApi.runtime.lastError || res[0]) {
  1521.  
  1522. }
  1523. });
  1524. }
  1525. });
  1526. }
  1527.  
  1528. return { requestHeaders: requestHeaders };
  1529. }, {
  1530. urls: ['<all_urls>']
  1531. }, extraInfoSpec);
  1532.  
  1533. // remove cookies after page load
  1534. extensionApi.webRequest.onCompleted.addListener(function (details) {
  1535. let domainToRemove;
  1536. for (const domain of _removeCookies) {
  1537. if (enabledSites.includes(domain) && matchUrlDomain(domain, details.url)) {
  1538. domainToRemove = domain;
  1539. break;
  1540. }
  1541. }
  1542. if (domainToRemove) {
  1543. extensionApi.cookies.getAll({ domain: domainToRemove }, function (cookies) {
  1544. for (const ck of cookies) {
  1545. const cookie = {
  1546. url: (ck.secure ? 'https://' : 'http://') + ck.domain + ck.path,
  1547. name: ck.name,
  1548. storeId: ck.storeId
  1549. };
  1550. // .firstPartyDomain = undefined on Chrome (doesn't support it)
  1551. if (ck.firstPartyDomain !== undefined) {
  1552. cookie.firstPartyDomain = ck.firstPartyDomain;
  1553. }
  1554. const cookieDomain = ck.domain;
  1555. const rcDomain = cookieDomain.replace(/^(\.?www\.|\.)/, '');
  1556. // hold specific cookie(s) from removeCookies domains
  1557. if ((rcDomain in removeCookiesSelectHold) && removeCookiesSelectHold[rcDomain].includes(ck.name)) {
  1558. continue; // don't remove specific cookie
  1559. }
  1560. // drop only specific cookie(s) from removeCookies domains
  1561. if ((rcDomain in removeCookiesSelectDrop) && !(removeCookiesSelectDrop[rcDomain].includes(ck.name))) {
  1562. continue; // only remove specific cookie
  1563. }
  1564. extensionApi.cookies.remove(cookie);
  1565. }
  1566. });
  1567. }
  1568. }, {
  1569. urls: ['<all_urls>']
  1570. });
  1571.  
  1572. // Google Analytics to anonymously track DAU (Chrome only)
  1573. // function initGA() {
  1574. // (function (i, s, o, g, r, a, m) {
  1575. // i.GoogleAnalyticsObject = r;
  1576. // i[r] = i[r] || function () {
  1577. // (i[r].q = i[r].q || []).push(arguments);
  1578. // }, i[r].l = 1 * new Date();
  1579. // a = s.createElement(o), m = s.getElementsByTagName(o)[0];
  1580. // a.async = 1;
  1581. // a.src = g;
  1582. // m.parentNode.insertBefore(a, m);
  1583. // })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
  1584. // ga('create', 'UA-69824169-2', 'auto');
  1585. // ga('set', 'checkProtocolTask', null);
  1586. // ga('set', 'anonymizeIp', true);
  1587. // ga('send', 'pageview');
  1588. // }
  1589.  
  1590. function isSiteEnabled(details) {
  1591. const enabledSite = matchUrlDomain(enabledSites, details.url);
  1592. if (enabledSite in restrictions) {
  1593. return restrictions[enabledSite].test(details.url);
  1594. }
  1595. return !!enabledSite;
  1596. }
  1597.  
  1598. function matchUrlDomain(domains, url) {
  1599. return matchDomain(domains, urlHost(url));
  1600. }
  1601.  
  1602. function matchDomain(domains, hostname) {
  1603. let matchedDomain = false;
  1604. if (!hostname) { hostname = window.location.hostname; }
  1605. if (typeof domains === 'string') { domains = [domains]; }
  1606. domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matchedDomain = domain));
  1607. return matchedDomain;
  1608. }
  1609.  
  1610. function urlHost(url) {
  1611. if (url && url.startsWith('http')) {
  1612. try {
  1613. return new URL(url).hostname;
  1614. } catch (e) {
  1615. console.log(`url not valid: ${url} error: ${e}`);
  1616. }
  1617. }
  1618. return url;
  1619. }
  1620. })();