I am building one extension in which i want to block some website urls from my chrome/firefox browser.
Lets say that i have a list of URLS that i want to make it a blacklist. So whenever the chrome user wants to join them, the extension will redirect to another URL of my choice (inside the code i will determine which URL i want it to be)
Through some research i managed to make for CHROME this one
manifest.json
{
"name": "URL Block",
"description": "Redirect to another site",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"webRequest",
"*://facebook.com/*",
"*://www.facebook.com/*",
"*://apple.com/*",
"*://www.apple.com/*",
"*://iptorrents.com/*",
"*://www.iptorrents.com/*",
"webRequestBlocking"
]
}
background.js
var host = "http://www.google.com";
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {redirectUrl: host + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]};
},
{
urls: [
"*://facebook.com/*",
"*://www.facebook.com/*",
"*://apple.com/*",
"*://www.apple.com/*",
"*://iptorrents.com/*",
"*://www.iptorrents.com/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);
So this extension works perfect for what im trying to do. But now i have some questions.
QUESTION:
Lets say that i want the extension to redirect to 2 different URL (and not only in google.com as in my example above.) [Which means, when i put URL: www.facebook.com and press the enter, the extension will redirect the certain tab to www.google.com AND OPEN A NEW TAB to redirect to www.abc.com]