From 285c392e2eea3987d0d2d08197b39d5de3ebb227 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sat, 3 Dec 2022 18:13:37 +0100 Subject: [PATCH] Fix The Atlantic (js) --- background.js | 46 ++++++++++++++++++++--------------------- changelog.txt | 1 + contentScript.js | 4 ++-- manifest.json | 2 +- options/clearCookies.js | 3 +++ options/popup.js | 2 +- sites.js | 4 ++-- sites_updated.json | 5 +++++ 8 files changed, 37 insertions(+), 30 deletions(-) diff --git a/background.js b/background.js index 1aca7f8..0dd5cd4 100644 --- a/background.js +++ b/background.js @@ -793,11 +793,10 @@ if (typeof browser !== 'object') { } } -if (!kiwi_browser) { ext_api.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { let tab_status = changeInfo.status; - if ((tab_status && tab_status === 'complete') || (!tab_status && changeInfo.url)) { - if (/^http/.test(tab.url) && matchUrlDomain(enabledSites, tab.url)) { + if (/^http/.test(tab.url) && ((tab_status && tab_status === 'complete') || (!tab_status && changeInfo.url))) { + if (matchUrlDomain(enabledSites, tab.url)) { runOnTab(tab); } // load toggleIcon.js (icon for dark or incognito mode in Chrome)) @@ -813,7 +812,6 @@ ext_api.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { } } }); -} setInterval(function () { let current_date_str = currentDateStr(); @@ -1187,7 +1185,7 @@ if (matchUrlDomain(change_headers, details.url) && !ignore_types.includes(detail active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { let tab = tabs[0]; if (isSiteEnabled(tab)) { runOnTab(tab); @@ -1298,7 +1296,7 @@ function site_switch() { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { let currentUrl = tabs[0].url; let isDefaultSite = matchUrlDomain(defaultSites_grouped_domains, currentUrl); if (!isDefaultSite) { @@ -1351,7 +1349,7 @@ function remove_cookies_fn(domainVar, exclusions = false) { active: true, currentWindow: true }, function (tabs) { - if (!ext_api.runtime.lastError && tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (!ext_api.runtime.lastError && tabs && tabs[0] && /^http/.test(tabs[0].url)) { let tabId = tabs[0].id; let storeId = '0'; for (let store of cookieStores) { @@ -1404,7 +1402,7 @@ function clear_cookies() { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { ext_api.tabs.executeScript({ file: 'options/clearCookies.js', runAt: 'document_start' @@ -1426,8 +1424,8 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { clear_cookies(); } // clear cookies for domain - if (message.domain) { - remove_cookies_fn(message.domain); + if (message.request === 'clear_cookies_domain' && message.data) { + remove_cookies_fn(message.data.domain); } if (message.request === 'site_switch') { site_switch(); @@ -1440,23 +1438,23 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { let currentUrl = tabs[0].url; let domain; let isExcludedSite = matchUrlDomain(excludedSites, currentUrl); if (!isExcludedSite) { - let isDefaultSiteGrouped = matchUrlDomain(defaultSites_domains, currentUrl); let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl); let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl); - domain = isDefaultSiteGrouped || (!isDefaultSite && isCustomSite); + domain = isDefaultSite || isCustomSite; + if (domain) + ext_api.runtime.sendMessage({ + msg: "popup_show_toggle", + data: { + domain: domain, + enabled: enabledSites.includes(domain) + } + }); } - ext_api.runtime.sendMessage({ - msg: "popup_show_toggle", - data: { - domain: domain, - enabled: enabledSites.includes(domain) - } - }); } }); } @@ -1484,7 +1482,7 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); } }); @@ -1496,7 +1494,7 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); } }); @@ -1576,7 +1574,7 @@ function matchDomain(domains, hostname = '') { } function urlHost(url) { - if (url && url.startsWith('http')) { + if (/^http/.test(url)) { try { return new URL(url).hostname; } catch (e) { @@ -1628,7 +1626,7 @@ function refreshCurrentTab() { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { if (ext_api.runtime.lastError) return; ext_api.tabs.update(tabs[0].id, { diff --git a/changelog.txt b/changelog.txt index d4d7e28..5c1dc85 100644 --- a/changelog.txt +++ b/changelog.txt @@ -10,6 +10,7 @@ Remove Philonomist (fix obsolete) Fix Australian Community Media (identify on url) Fix Groupe Centre France (text) Fix Quotidiano.net (no amp) +Fix The Atlantic (js) Fix The Chronicle of Higher Education (css) * v2.9.5.0 (2022-11-27) diff --git a/contentScript.js b/contentScript.js index e0b0f15..f828e21 100644 --- a/contentScript.js +++ b/contentScript.js @@ -3899,8 +3899,8 @@ else if (matchDomain('theathletic.com')) { } else if (matchDomain('theatlantic.com')) { - let banner = document.querySelector('.c-nudge__container,.c-non-metered-nudge'); - removeDOMElement(banner); + let banners = document.querySelectorAll('.c-nudge__container, .c-non-metered-nudge, div[class^="ArticleInjector_"]'); + removeDOMElement(...banners); } else if (matchDomain('thedailybeast.com')) { diff --git a/manifest.json b/manifest.json index 080521a..046b219 100644 --- a/manifest.json +++ b/manifest.json @@ -732,5 +732,5 @@ "*://gcm.omerlocdn.com/*", "*://webcache.googleusercontent.com/*" ], - "version": "2.9.5.6" + "version": "2.9.5.7" } diff --git a/options/clearCookies.js b/options/clearCookies.js index a322fe0..817d2c1 100644 --- a/options/clearCookies.js +++ b/options/clearCookies.js @@ -7,7 +7,10 @@ var cookie_domain = getCookieDomain(document.domain); // send domain to background.js (to clear cookies) ext_api.runtime.sendMessage({ + request: 'clear_cookies_domain', + data: { domain: cookie_domain + } }); function getCookieDomain(hostname) { diff --git a/options/popup.js b/options/popup.js index 5a670c7..eff3b9d 100644 --- a/options/popup.js +++ b/options/popup.js @@ -13,7 +13,7 @@ function popup_show_toggle(domain, enabled) { labelEl.appendChild(inputEl); let spanEl = document.createElement('span'); spanEl.setAttribute('class', 'slider round'); - spanEl.setAttribute('title', 'en/disable current site in BPC'); + spanEl.setAttribute('title', 'en/disable current site/group in BPC'); labelEl.appendChild(spanEl); site_switch_span.appendChild(labelEl); document.getElementById("site_switch").addEventListener('click', function () { diff --git a/sites.js b/sites.js index 6dd8637..6633425 100644 --- a/sites.js +++ b/sites.js @@ -1767,7 +1767,7 @@ var defaultSites = { }, "The Atlantic": { domain: "theatlantic.com", - block_regex: /cdn\.ampproject\.org\/v\d\/amp-(access|subscriptions)-.+\.js/, + block_regex: /cdn\.theatlantic\.com\/_next\/static\/chunks\/[567].+\.js/, remove_cookies_select_drop: ["articleViews"] }, "The Australian Financial Review": { @@ -2398,4 +2398,4 @@ init_custom_domains(); // sites with no fix (background) var be_mediahuis_nofix_domains = ['gva.be', 'hbvl.be']; var it_gedi_nofix_domains = ['gelocal.it', 'huffingtonpost.it', 'ilsecoloxix.it', 'lastampa.it', 'limesonline.com']; -var nofix_sites = ['africaintelligence.com', 'africaintelligence.fr', 'aftenposten.no', 'badische-zeitung.de', 'bild.de', 'borsen.dk', 'businesstimes.com.sg', 'caixin.com', 'caixinglobal.com', 'caravanmagazine.in', 'courrierinternational.com', 'dn.se', 'elordenmundial.com', 'epw.in', 'expresso.pt', 'ftchinese.com', 'handelsblatt.com', 'hs.fi', 'ilsole24ore.com', 'jacobinmag.com', 'jeuneafrique.com', 'kurier.at', 'lavie.fr', 'lavozdegalicia.es', 'leconomiste.com', 'lefigaro.fr', 'lemonde.fr', 'lepoint.fr', 'letemps.ch', 'liberation.fr', 'medianama.com', 'mediapart.fr', 'milanofinanza.it', 'mondediplo.com', 'moneycontrol.com', 'nature.com', 'nbr.co.nz', 'nn.de', 'ouest-france.fr', 'philonomist.com', 'politiken.dk', 'pressreader.com', 'publico.pt', 'republic.ru', 'saechsische.de', 'schwarzwaelder-bote.de', 'statnews.com', 'stern.de', 'straitstimes.com', 'stuttgarter-nachrichten.de', 'stuttgarter-zeitung.de', 'suedkurier.de', 'swp.de', 'tagesanzeiger.ch', 'the-ken.com', 'theinformation.com', 'themorningcontext.com', 'theparisreview.org', 'thewirechina.com', 'weser-kurier.de', 'worldpoliticsreview.com', 'ynet.co.il', 'zerohedge.com'].concat(be_mediahuis_nofix_domains, it_gedi_nofix_domains); +var nofix_sites = ['africaintelligence.com', 'africaintelligence.fr', 'aftenposten.no', 'badische-zeitung.de', 'bild.de', 'borsen.dk', 'businesstimes.com.sg', 'caixin.com', 'caixinglobal.com', 'caravanmagazine.in', 'courrierinternational.com', 'dn.se', 'elordenmundial.com', 'epw.in', 'expresso.pt', 'ftchinese.com', 'handelsblatt.com', 'heise.de', 'hs.fi', 'ilsole24ore.com', 'jacobinmag.com', 'jeuneafrique.com', 'kurier.at', 'lavie.fr', 'lavozdegalicia.es', 'leconomiste.com', 'lefigaro.fr', 'lemonde.fr', 'lepoint.fr', 'letemps.ch', 'liberation.fr', 'medianama.com', 'mediapart.fr', 'milanofinanza.it', 'mondediplo.com', 'moneycontrol.com', 'nature.com', 'nbr.co.nz', 'nn.de', 'ouest-france.fr', 'philonomist.com', 'politiken.dk', 'pressreader.com', 'publico.pt', 'republic.ru', 'saechsische.de', 'schwarzwaelder-bote.de', 'statnews.com', 'stern.de', 'straitstimes.com', 'stuttgarter-nachrichten.de', 'stuttgarter-zeitung.de', 'suedkurier.de', 'swp.de', 'tagesanzeiger.ch', 'techcrunch.com', 'the-ken.com', 'theinformation.com', 'themorningcontext.com', 'theparisreview.org', 'thewirechina.com', 'weser-kurier.de', 'worldpoliticsreview.com', 'ynet.co.il', 'zerohedge.com'].concat(be_mediahuis_nofix_domains, it_gedi_nofix_domains); diff --git a/sites_updated.json b/sites_updated.json index 9e4732b..53ccb76 100644 --- a/sites_updated.json +++ b/sites_updated.json @@ -13,6 +13,11 @@ "allow_cookies": 1, "block_regex": "(\\.evolok\\.net\\/|\\.lavanguardia\\.com\\/js\\/godo-basex-)" }, + "The Atlantic": { + "domain": "theatlantic.com", + "block_regex": "cdn\\.theatlantic\\.com\\/_next\\/static\\/chunks\\/[567].+\\.js", + "remove_cookies_select_drop": ["articleViews"] + }, "The Spectator (UK)": { "domain": "spectator.co.uk", "useragent": "googlebot"