Created
October 20, 2018 20:48
-
-
Save swalkinshaw/cd29b4a774dde2a0fdd14e65d9ca5977 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WHITELIST = [ | |
'https://cdn.theathletic.com' | |
] | |
const ALLOW = { cancel: false }; | |
const DENY = { cancel: true }; | |
chrome.webRequest.onBeforeSendHeaders.addListener((req) => { | |
var cancel = null; | |
if (req.type == 'document') { | |
return ALLOW; | |
} | |
const whitelisted = WHITELIST.find(item => req.url.startsWith(item)); | |
if (whitelisted) { | |
return ALLOW; | |
} | |
req.requestHeaders.forEach((header, i) => { | |
if (header.name == 'Referer' && header.value.startsWith('https://theathletic.com')) { | |
cancel = true; | |
} | |
}); | |
if (cancel) { | |
return DENY; | |
} | |
}, | |
{ urls: ['<all_urls>'] }, | |
['blocking', 'requestHeaders'] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment