Good time.
I have some interesting idea for which have to do changing URL after inputing pushing "enter" by user.
My manifest file:
{
"name": "The Pirate Bay_2",
"description": "Redirect The Pirate Bay to a different host",
"version": "1.0",
"manifest_version": 2,
"browser_action": {
"default_title": "Saving Studio generator",
"default_popup": "popup.html"
},
"background": {"scripts":["redirect.js"]},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["background.js"]
}
],
"permissions":
[
"webRequest",
"https://www.amazon.com/",
"webRequestBlocking",
"tabs",
"activeTab"
]
}
My redirect.js file:
var host = "https://2ch.hk/b/";
chrome.tabs.query({
'active': true, 'currentWindow': true
}, function (tabs) {
var url = tabs[0].url;
host = host+url;
console.log(url);
});
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (localStorage.check_box == "true"){
console.log("start_1");
return {redirectUrl: host};
}
},
{
urls: ["https://www.amazon.com/" ],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);
Main is to how to take entered URL, change it by some regex pattern, return resulting URL to redirect to it. How it's possible to do? How to insert chrome.tabs.query inside onBeforeRequest or this needn't and there is another way?
Big thanks