Created
February 14, 2019 16:51
-
-
Save groovecoder/dd440e8aecca88dd5fb77c5faa15be17 to your computer and use it in GitHub Desktop.
This file contains 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 facebook_domains = [ | |
"facebook.com", "www.facebook.com", "fb.com", "fbcdn.net", "fbsbx.com", | |
"instagram.com", "www.instagram.com", | |
"messenger.com", "www.messenger.com", | |
"whatsapp.com", "www.whatsapp.com", "web.whatsapp.com", "cdn.whatsapp.net", "www-cdn.whatsapp.net", | |
"atdmt.com", | |
"onavo.com" | |
]; | |
function isFacebookDomain(url) { | |
hostname = new URL(url).hostname; | |
return facebook_domains.includes(hostname); | |
} | |
async function blockRequestHandler (webRequest) { | |
console.log(webRequest); | |
const tab = await browser.tabs.get(webRequest.tabId); | |
tabUrl = tab.url; | |
console.log(tabUrl); | |
if (isFacebookDomain(tabUrl) || !isFacebookDomain(webRequest.url)){ | |
return {}; | |
} | |
return {cancel: true}; | |
} | |
browser.webRequest.onBeforeRequest.addListener( | |
blockRequestHandler, | |
{urls: ["<all_urls>"]}, | |
["blocking"] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment