Is there any extension to Chrome that will let me force a URL from a particular domain to be redirected to another domain?
(E.g. Redirect http://www.google.com
to https://encrypted.google.com
.)
Note: I'm looking for an arbitrary redirector, not KB SSL Enforcer, which only works for the specific task of redirecting to HTTPS.
Answer
I had built a Chrome extension which does this.
Note: I built this for just 2 sites - just for the heck of it - by no means it's professional quality™. Please don't flame me for crappy code :)
Edit: Updated to manifest v2, which brings in certain additional restrictions.
manifest.json
{
"name": "URL Redirect",
"version": "0.2",
"description": "Checks URL and redirects as required.",
"background": {
"page":"bg.html"
},
"manifest_version": 2,
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content.js"]
}
],
"permissions": ["tabs"]
}
bg.html
redirect.js
chrome.extension.onRequest.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
content.js
var pattern=/\bBlocked/;
var viewtext_base_url = "http://viewtext.org/article?url=";
var newurl;
if (pattern.test(window.document.title)) // if it matches pattern defined above
{
newurl = viewtext_base_url + encodeURIComponent(window.location.href);
chrome.extension.sendRequest({redirect: newurl}); // send message to redirect
}
To install this, create files with filenames as mentioned above the codeblock.
Once all 3 files are created, Click on Chrome Menu → Tools → Extensions. Click the "+" on Developer Mode. Click on Load Unpacked extension and point to the directory where the files are stored.
Edit the files are required, and uninstall and reinstall the extension as mentioned above
No comments:
Post a Comment