commit 51f68152a398ff21e5f70fd28e2665d11e8ac0c9 Author: baalajimaestro Date: Sun Sep 17 16:32:47 2023 +0000 Add script.js Signed-off-by: baalajimaestro diff --git a/script.js b/script.js new file mode 100644 index 0000000..78ee700 --- /dev/null +++ b/script.js @@ -0,0 +1,88 @@ +// ==UserScript== +// @name Privacy Redirector +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description Redirects sites to privacy-focused frontends +// @author baalajimaestro +// @match https://youtube.com/* +// @match https://youtu.be/* +// @match https://www.youtube.com/* +// @match https://www.youtu.be/* +// @match https://twitter.com/* +// @match https://x.com/* +// @match https://www.x.com/* +// @match https://www.twitter.com/* +// @match https://stackoverflow.com/* +// @match https://www.stackoverflow.com/* +// @match https://reddit.com/* +// @match https://www.reddit.com/* +// @match https://old.reddit.com/* +// @match https://new.reddit.com/* +// @match https://quora.com/* +// @match https://www.quora.com/* +// @icon https://baalajimaestro.me/favicon.ico +// @grant none +// ==/UserScript== + +// our document location +let link = document.location.href; + +// regexes +const re_yt = + /^(?:(?:https|http):\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be).*(?<=\/|v\/|u\/|embed\/|shorts\/|watch\?v=)(?[\w\-]{11})(?=\?|&|$)/; +const re_twt = + /^(?:https?:\/\/(?:twitter|x)\.com)(?\/(?:#!\/)?(\w+)\/status(es)?\/(\d+))/; +const re_soflow = + /^https?:\/\/stackoverflow\.com(?\/questions\/\d+\/[^\/\s]*)/; +const re_reddit = + /^https?:\/\/(?:www\.)?(?:old\.)?reddit\.com(?\/r\/\w+\/comments\/\w+\/[^/?#]+)/; +const re_quora = /https:\/\/www\.quora\.com(?\/.*)/; + +// redirectors +const inv = "//invidious.baalajimaestro.me"; +const nitter = "//nitter.net"; +const oflow = "//overflow.baalajimaestro.me"; +const lr = "//libreddit.baalajimaestro.me"; +const qtr = "//quetre.baalajimaestro.me"; + +// handle dynamic pages +const observer = new MutationObserver(function (mutations) { + mutations.forEach(function (mutation) { + if (link != document.location.href) { + link = document.location.href; + handler(); + } + }); +}); + +observer.observe(document.body, { + childList: true, + subtree: true, +}); + +//universal handler to handle all sites +function handler() { + if (re_yt.test(link)) { + window.location.replace( + inv + "/watch?v=" + window.location.href.match(re_yt).groups.id, + ); + } else if (re_twt.test(link)) { + window.location.replace( + nitter + window.location.href.match(re_twt).groups.url, + ); + } else if (re_reddit.test(link)) { + window.location.replace( + lr + window.location.href.match(re_reddit).groups.url, + ); + } else if (re_soflow.test(link)) { + window.location.replace( + oflow + window.location.href.match(re_soflow).groups.url, + ); + } else if (re_quora.test(link)) { + window.location.replace( + qtr + window.location.href.match(re_quora).groups.url, + ); + } +} + +handler();