tvl-depot/users/tazjin/nittredir/background.js
Vincent Ambo ea9982d9ea 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
2021-01-20 15:36:05 +00:00

10 lines
332 B
JavaScript

/**
* 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']);