feat(tazjin/nittredir): Add Chrome extension to redirect to Nitter

There is another extension for this already, but it hooks in after the
page has already started loading - doing it on the URL change handler
is much faster.

Change-Id: I442552cbd8bb040df999a1624cafd436f4a7b875
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2430
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2021-01-20 18:17:05 +03:00 committed by tazjin
parent de64ebbbaa
commit ea9982d9ea
2 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,10 @@
/**
* Register a URL change handler that redirects twitter.com links to nitter.net
*/
chrome.webRequest.onBeforeRequest.addListener(function(details) {
let url = new URL(details.url);
return {
redirectUrl: ('https://nitter.net' + url.pathname)
};
}, {urls: ['*://twitter.com/*'], types: ['main_frame']}, ['blocking']);

View file

@ -0,0 +1,15 @@
{
"manifest_version": 2,
"name": "nittredir",
"version": "1.0",
"description": "Redirect twitter.com to nitter.net",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"permissions": [
"webRequest",
"webRequestBlocking",
"*://twitter.com/*"
]
}