Privacy Frontend Redirect

Redirect to privacy friendly front-ends of popular services.

Från och med 2023-02-02. Se den senaste versionen.

// ==UserScript==
// @name        Privacy Frontend Redirect
// @match       *://*/*
// @grant       none
// @version     3.1.2
// @author      NoUser
// @description Redirect to privacy friendly front-ends of popular services.
// @run-at      document-start
// @namespace   https://greasyfork.org/en/scripts/458875-privacy-frontend-redirect
// @homepage    https://greasyfork.org/en/scripts/458875-privacy-frontend-redirect
// @license MIT
// ==/UserScript==

// Attempt to prevent prefetching the non frontend services
// const prefetchLinks = document.querySelectorAll("link[rel='prefetch']");
// prefetchLinks.forEach(link => link.parentNode.removeChild(link));

const hostname = window.location.hostname;
const hosts = {
  "www.youtube.com": "inv.librefront.com",
  "www.youtube-nocookie.com": "inv.librefront.com",
  "m.youtube.com": "inv.librefront.com",
  "twitter.com": ["nitter.sneed.network", "canada.unofficialbird.com", "nitter.privacytools.io", "nitter.foss.wtf", "nitter.privacy.com.de", "nitter.1d4.us", "nitter.pussthecat.org", "nitter.poast.org", "twitter.censors.us"],
  "mobile.twitter.com": ["nitter.sneed.network", "canada.unofficialbird.com", "nitter.privacytools.io", "nitter.foss.wtf", "nitter.privacy.com.de", "nitter.1d4.us", "nitter.pussthecat.org", "nitter.poast.org", "twitter.censors.us"],
  "www.reddit.com": ["libreddit.eu.org", "libreddit.spike.codes", "lr.odyssey346.dev", "rd.funami.tech", "libreddit.dcs0.hu", "lr.vern.cc", "www.troddit.com"],
  "imgur.com": ["rimgo.pussthecat.org", "rimgo.totaldarkness.net", "rimgo.vern.cc", "imgur.artemislena.eu", "rimgo.privacydev.net", "rimgo.bus-hit.me"],
  "i.imgur.com": ["rimgo.pussthecat.org", "rimgo.totaldarkness.net", "rimgo.vern.cc", "imgur.artemislena.eu", "rimgo.privacydev.net", "rimgo.bus-hit.me"],
  "www.instagram.com": ["bibliogram.froth.zone", "ig.tokhmi.xyz", "bibliogram.priv.pw"],
  "www.tiktok.com": ["proxitok.pussthecat.org", "proxitok.esmailelbob.xyz", "tok.habedieeh.re", "tok.artemislena.eu", "proxitok.privacydev.net", "proxitok.manasiwibi.com"],
  "www.imdb.com": ["ld.vern.cc", "libremdb.esmailelbob.xyz", "lmdb.tokhmi.xyz", "libremdb.iket.me", "libremdb.pussthecat.org"],
  "translate.google.com": ["lingva.ml", "translate.plausibility.cloud", "lingva.lunar.icu", "translate.projectsegfau.lt", "translate.jae.fi"],
  "medium.com": ["scribe.rip", "scribe.nixnet.services", "scribe.citizen4.eu", "scribe.bus-hit.me", "scribe.froth.zone", "scribe.rawbit.ninja"],
};

const getReplacement = (host) => {
  if (host in hosts) {
    let replacement = hosts[host];
    if (Array.isArray(replacement)) {
      replacement = replacement[Math.floor(Math.random() * replacement.length)];
    }
    return replacement;
  }
};

const replaceUrl = (url, host) => {
  const replacement = getReplacement(host);
  if (replacement) {
    return url.replace(host, replacement);
  }
  return url;
};

if (getReplacement(hostname)) {
  window.location.href = replaceUrl(window.location.href, hostname);
}

window.addEventListener("load", function () {
  // Replace iframes
const iframes = document.getElementsByTagName("iframe");
Array.from(iframes).forEach(iframe => {
  let src = iframe.src;
  let url = new URL(src);
  let host = url.host;
  iframe.src = replaceUrl(src, host);
});
  // Replace hrefs
  const links = document.getElementsByTagName("a");
  for (let i = 0; i < links.length; i++) {
    let link = links[i];
    let href = link.href;
    let url = new URL(href);
    let host = url.host;
    if (host in hosts) {
      let replacement = hosts[host];
      if (Array.isArray(replacement)) {
        replacement = replacement[Math.floor(Math.random() * replacement.length)];
      }
      link.href = href.replace(host, replacement);
    }
  }
});