Skip to content

Commit

Permalink
Fix nytimes.com
Browse files Browse the repository at this point in the history
  • Loading branch information
iamadamdev committed Jun 18, 2023
1 parent 747dddd commit 97b84f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const restrictions = {
'economist.com': /.+economist\.com\/.+\/\d{1,4}\/\d{1,2}\/\d{2}\/.+/,
'seekingalpha.com': /.+seekingalpha\.com\/article\/.+/,
'techinasia.com': /\.techinasia\.com\/.+/,
'ft.com': /.+\.ft.com\/content\//
'ft.com': /.+\.ft.com\/content\//,
'nytimes.com': /^((?!\/timesmachine\.nytimes\.com\/).)*$/
};

// Don't remove cookies before page load
Expand Down Expand Up @@ -108,7 +109,8 @@ const removeCookies = [
'wsj.com',
'medium.com',
'washingtonpost.com',
'japantimes.co.jp'
'japantimes.co.jp',
'nytimes.com'
];

// Contains remove cookie sites above plus any custom sites
Expand Down Expand Up @@ -222,7 +224,7 @@ const blockedRegexes = {
'chicagobusiness.com': /(\.tinypass\.com\/|\.chicagobusiness\.com\/.+\/js\/js_.+\.js)/,
'dailytelegraph.com.au': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
'theglobeandmail.com': /(\.theglobeandmail\.com\/pf\/dist\/engine\/react\.js|smartwall\.theglobeandmail\.com\/)/,
'nytimes.com': /(meter-svc\.nytimes\.com\/meter\.js|mwcm\.nyt\.com\/.+\.js|cooking\.nytimes\.com\/api\/.+\/access)/,
'nytimes.com': /(\.nytimes\.com\/meter\.js|mwcm\.nyt\.com\/.+\.js|cooking\.nytimes\.com\/api\/.+\/access)/,
'latimes.com': /(metering\.platform\.latimes\.com\/|cdn\.ampproject\.org\/v\d\/amp-(access|subscriptions)-.+\.js)/,
'theathletic.com': /cdn\.ampproject\.org\/v\d\/amp-(access|subscriptions)-.+\.js/,
'japantimes.co.jp': /cdn\.cxense\.com\//,
Expand Down Expand Up @@ -304,6 +306,24 @@ extensionApi.webRequest.onBeforeRequest.addListener(function (details) {
['blocking']
);

// nytimes.com
extensionApi.webRequest.onHeadersReceived.addListener(function (details) {
if (!isSiteEnabled(details)) {
return;
}
let headers = details.responseHeaders;
headers = headers.map(function (header) {
if (header.name === 'x-frame-options') { header.value = 'SAMEORIGIN'; }
return header;
});
return {
responseHeaders: headers
};
}, {
urls: ['*://*.nytimes.com/*']
},
['blocking', 'responseHeaders']);

// Disable javascript for these sites
extensionApi.webRequest.onBeforeRequest.addListener(function (details) {
const headerReferer = details.originUrl ? details.originUrl : details.initiator;
Expand Down Expand Up @@ -432,7 +452,6 @@ extensionApi.webRequest.onBeforeSendHeaders.addListener(function (details) {
});
}


// remove cookies before page load
const enabledCookies = allowCookies.some(function (site) {
return matchUrlDomain(site, details.url);
Expand Down
4 changes: 2 additions & 2 deletions src/js/contentScript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (!matchDomain(['seekingalpha.com', 'sfchronicle.com', 'cen.acs.org', 'elmundo.es', 'scmp.com'])) {
if (!matchDomain(['seekingalpha.com', 'sfchronicle.com', 'cen.acs.org', 'elmundo.es', 'scmp.com', 'nytimes.com'])) {
window.localStorage.clear();
}

Expand Down Expand Up @@ -258,7 +258,7 @@ if (matchDomain('elmercurio.com')) {
removeDOMElement(counter, coBanner, support);
});
} else if (matchDomain('nytimes.com')) {
const banners = document.querySelectorAll('div[data-testid="inline-message"], div[id^="ad-"], div.expanded-dock');
const banners = document.querySelectorAll('div[data-testid="inline-message"], div[id^="ad-"], div.expanded-dock, div.pz-ad-box');
removeDOMElement(...banners);
} else if (matchDomain('technologyreview.com')) {
window.setTimeout(function () {
Expand Down

0 comments on commit 97b84f0

Please sign in to comment.