@@ 1,713 @@
+// ==UserScript==
+// @name Proxy Redirect
+// @author Schimon Jehudah, Adv.
+// @homepageURL https://openuserjs.org/scripts/sjehuda/Proxy_Redirect
+// @supportURL https://openuserjs.org/scripts/sjehuda/Proxy_Redirect/issues
+// @updateURL https://openuserjs.org/meta/sjehuda/Proxy_Redirect.meta.js
+// @downloadURL https://openuserjs.org/install/sjehuda/Proxy_Redirect.user.js
+// @copyright 2023, Schimon Jehudah (http://schimon.i2p)
+// @license AGPL-3.0-only; https://www.gnu.org/licenses/agpl-3.0.en.html
+// @namespace i2p.schimon.proxy-redirect
+// @description Redirect to privacy respecting proxy frontends
+// @run-at document-start
+// @version 23.06.10
+// @grant GM_xmlhttpRequest
+// @grant GM.xmlHttpRequest
+// @exclude *#noredirect
+// @match *://bandcamp.com/*
+// @match *://*.bandcamp.com/*
+// @match *://bilibili.com/*
+// @match *://*.bilibili.com/*
+// @match *://bing.com/maps*
+// @match *://www.bing.com/maps*
+// @match *://bing.com/search*
+// @match *://www.bing.com/search*
+// @match *://bt4g.org/magnet/*
+// @match *://*.bt4g.org/magnet/*
+// @match *://*.fandom.com/wiki/*
+// @match *://gist.github.com/*
+// @match *://github.com/*
+// @match *://*.github.com/*
+// @exclude *://github.com/*/*/*
+// @exclude *://github.com/events
+// @exclude *://github.com/events/*
+// @exclude *://github.com/login*
+// @exclude *://github.com/notifications*
+// @exclude *://github.com/sessions*
+// @exclude *://github.com/signup*
+// @exclude *://github.com/topics
+// @exclude *://github.com/topics/*
+// @match *://gitlab.com/*
+// @match *://goodreads.com/*
+// @match *://*.goodreads.com/*
+// @match /^(https?:\/\/)?(www\.)?google\.[^\/]+\/maps/i
+// @match /^(https?:\/\/)?(www\.)?google\.[^\/]+\/search/i
+// @match *://google.com/search*
+// @match *://www.google.com/search*
+// @match *://google.com/sorry*
+// @match *://consent.google.com/*
+// @match *://www.google.com/sorry*
+// @match *://translate.google.com/*
+// @match *://imdb.com/*
+// @match *://www.imdb.com/*
+// @exclude *://imdb.com/*/*/reviews/*
+// @exclude *://www.imdb.com/*/*/reviews/*
+// @match *://imgur.com/*
+// @match *://i.imgur.com/*
+// @match *://instagram.com/*
+// @match *://www.instagram.com/*
+// @match *://invidious-invidious.invidious.svc.cluster.local:3000/*
+// @match *://medium.com/*
+// @match *://*.medium.com/*
+// @exclude */v2/*
+// @exclude */c/*
+// @exclude */fit/*
+// @exclude */resize:fit:*
+// @exclude */format:*
+// @match *://moovitapp.com/*
+// @match *://*.moovitapp.com/*
+// @match *://odysee.com/*
+// @match *://*.odysee.com/*
+// @match *://quora.com/*
+// @match *://*.quora.com/*
+// @match *://reuters.com/*
+// @match *://*.reuters.com/*
+// @match *://tiktok.com/*
+// @match *://*.tiktok.com/*
+// @match *://reddit.com/*
+// @match *://*.reddit.com/*
+// @match *://stackoverflow.com/questions/*
+// @exclude *://stackoverflow.com/questions/tagged/*
+// @match *://www.torrentdownload.info/*
+// @exclude *://www.torrentdownload.info/feed_latest
+// @exclude *://www.torrentdownload.info/search?q=*
+// @match *://torrentz.eu/*
+// @exclude *://torrentz.eu/search?f=*
+// @match *://*.torrentz.eu/*
+// @exclude *://*.torrentz.eu/search?f=*
+// @match *://torrentz.me/*
+// @exclude *://torrentz.me/search?f=*
+// @match *://*.torrentz.me/*
+// @exclude *://*.torrentz.me/search?f=*
+// @match *://torrentz2.eu/*
+// @exclude *://torrentz2.eu/search?f=*
+// @match *://torrentz2.is/*
+// @exclude *://torrentz.is/search?f=*
+// @match *://*.torrentz2.is/*
+// @exclude *://*.torrentz.is/search?f=*
+// @match *://twitter.com/*
+// @exclude *://twitter.com/intent/*
+// @match *://*.twitter.com/*
+// @exclude *://*.twitter.com/intent/*
+// @match *://urbandictionary.com/*
+// @match *://*.urbandictionary.com/*
+// @match *://userscripts.org/*
+// @match *://*.userscripts.org/*
+// @match *://waze.com/live-map*
+// @match *://*.waze.com/live-map*
+// @match *://waze.com/ul*
+// @match *://*.waze.com/ul*
+// @match *://ul.waze.com/ul*
+// @match *://wikimap.toolforge.org/*
+// @match *://wikipedia.org/*
+// @match *://*.wikipedia.org/*
+// @match *://yahoo.com/search*
+// @match *://www.yahoo.com/search*
+// @match *://search.yahoo.co.jp/search?p=*
+// @match *://search.yahoo.com/?q=*
+// @match *://yandex.com/search*
+// @match *://www.yandex.com/search*
+// @match *://yandex.com/maps/*
+// @match *://www.yandex.com/maps/*
+// @match *://yandex.ru/search*
+// @match *://www.yandex.ru/search*
+// @match *://translate.yandex.com/*
+// @match *://youtu.be/*
+// @match *://youtube.com/*
+// @match *://*.youtube.com/*
+// @match *://youtube-nocookie.com/*
+// @match *://*.youtube-nocookie.com/*
+// @connect bibliogram.art
+// @connect openstreetmap.org
+// @connect scribe.rip
+// @connect teddit.cleberg.net
+// @connect libreddit.cleberg.net
+// @connect invidious.cleberg.net
+// @connect libretranslate.cleberg.net
+// @connect gh.cleberg.net
+// @connect search.cleberg.net
+// @connect nitter.cleberg.net
+// @icon data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjRtbSIgaGVpZ2h0PSI2NG1tIiB2aWV3Qm94PSIwIDAgNjQgNjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHRleHQgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgc3R5bGU9ImZvbnQtd2VpZ2h0OjQwMDtmb250LXNpemU6MTkycHg7bGluZS1oZWlnaHQ6MDt0ZXh0LWluZGVudDowO3RleHQtYWxpZ246c3RhcnQ7dGV4dC1kZWNvcmF0aW9uLXN0eWxlOnNvbGlkO3RleHQtZGVjb3JhdGlvbi1jb2xvcjojMDAwO3dyaXRpbmctbW9kZTpsci10YjtkaXJlY3Rpb246bHRyO3RleHQtb3JpZW50YXRpb246bWl4ZWQ7ZG9taW5hbnQtYmFzZWxpbmU6YXV0bztiYXNlbGluZS1zaGlmdDpiYXNlbGluZTt0ZXh0LWFuY2hvcjpzdGFydDtzaGFwZS1wYWRkaW5nOjA7c2hhcGUtbWFyZ2luOjA7aW5saW5lLXNpemU6MDtvcGFjaXR5OjE7ZmlsbDojMDAwO2ZpbGwtb3BhY2l0eToxO3N0cm9rZS13aWR0aDoxLjI3OTgyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eToxO3N0b3AtY29sb3I6IzAwMDtzdG9wLW9wYWNpdHk6MSIgeD0iMTcuMDA1MjQ1IiB5PSIzMS42NTg0MDUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC00LjQzNjg1NjQgNDAuODk0OTQpIHNjYWxlKC4yNjQ1OCkiPjx0c3BhbiB4PSIxNy4wMDUyNDUiIHk9IjMxLjY1ODQwNSIgc3R5bGU9ImZvbnQtc2l6ZToxOTJweCI+8J+luDwvdHNwYW4+PC90ZXh0Pjwvc3ZnPgo=
+// ==/UserScript==
+
+//TODO
+//Rebrand: Open Redirect, Proxy Redirect
+//Rebrand: Freelink, LibreProxy, Libreproxy, Open Link, Proxy Direct, Proxy Link, Proxy Redirect
+
+/*
+
+<!-- **Read:** Appeal to [Falkon (QupZilla) Web Browser](#-help-enhancing-userscript-support-for-falkon-web-browser) - Part of the KDE Project -->
+
+## 🕶️ Proxy Redirect <!-- 😎➿⏭️🔁➰ -->
+### _Redirection userscript for privacy-oriented and open-source proxy frontends._
+
+Proxy Redirect automatically redirects to instances of privacy-oriented frontends, such as Scribe, Nitter, Libreddit, etc.
+
+This allows more reliable access to available public instances per service, while also helping to distribute traffic more evenly across all instances and avoid performance bottlenecks and rate-limiting.
+
+---
+
+#### Recommended Userscripts
+
+#### ⛓️ [Proxify Links](https://openuserjs.org/scripts/sjehuda/Proxify_Links)
+Correct links to privacy respecting proxy frontends.
+
+---
+
+#### Please visit our counterparts
+
+#### Userscript
+
+#### [GreaseMonkey-Redirect](https://codeberg.org/zortazert/GreaseMonkey-Redirect)
+Collection of user created GreaseMonkey scripts that will convert privacy disrespecting websites to FOSS/Libre alternatives.
+
+#### [Search Engine Jumper](https://openuserjs.org/scripts/sycom/Search_Engine_Jumper) (Search Engine Kangaroo)
+When using some search engines the script creates links to a long list of alternative search engines. Don't be a search engine prisoner
+
+#### Web Extension
+
+#### [Privacy-Redirect](https://github.com/SimonBrazell/privacy-redirect#get)
+Simple web extension that redirects requests to privacy friendly counterparts.
+
+#### [LibRedirect](https://libredirect.github.io/)
+##### Based on [Privacy-Redirect](#privacy-redirect)
+Web extension that redirects requests to privacy friendly frontends and backends.
+
+#### [Invidition](https://codeberg.org/Booteille/invidition#downloads)
+##### Deprecated in favor of [Privacy-Redirect](#privacy-redirect)
+Invidition is an extension allowing you to redirect requests to their counterparts before loading them.
+
+#### Mobile App
+
+#### [UntrackMe](https://framagit.org/tom79/nitterizeme#download)
+A small application that allows to handle requests and redirect them to their Nitter or Invidious URLs and open them with the appropriate app.
+
+#### Server
+
+#### [Farside](https://farside.link/)
+Redirecting service for FOSS frontends.
+
+---
+
+#### <!-- img src="https://raw.githubusercontent.com/KDE/falkon/master/logo.png" height="30" alt="Falkon" title="Download Falkon Browser"/ --> Help enhancing userscript support for <span style='color:MediumPurple'>Falkon web browser</span>
+C++ developers, please help [Falkon](https://falkon.org/) web browser to bring [better support](https://bugs.kde.org/show_bug.cgi?id=466533) for [GM.xmlHttpRequest](https://sourceforge.net/p/greasemonkey/wiki/GM_xmlhttpRequest/).
+
+If you find this program useful, please help Falkon so we would also be able to enjoy this program. Web browsers that respect our privacy are rare. That's why Falkon is important.
+
+##### Disclosure: This program was made particularly for people who use Falkon, Jumanji, Opera, Otter, Pale Moon, Surf, Uzbl and other web browsers with Userscript support, to which non has a redirector extension like [Privacy-Redirect](#privacy-redirect).
+
+_Sincerely,
+Schimon Jehudah, Adv._
+
+*/
+
+/*
+
+NOTE
+This program was inspired by Farside project from Ben Busby
+For more information: https://farside.link
+
+TODO Brand
+FreeDirector, Free Direct, FreeDirect.js
+Open Redirector, Open Redirect, Open Direct, OpenDirect.js
+Redirect.js, Redirect.user.js, Redirector.js
+UserDirect, UserRedirect
+
+FIXME
+// @match *://*.imgur.com/*
+// @exclude *://i.*.imgur.com/*
+
+FIXME RegEx
+// @exclude /*.medium\.com\/*\/(c|fit|v2)\/.*$/
+
+*/
+
+// https://github.com/makyen
+// https://github.com/greasemonkey/greasemonkey/issues/3160#issuecomment-1456758080
+const gmXmlhttpRequest = typeof GM_xmlhttpRequest === 'function' ? GM_xmlhttpRequest : GM.xmlHttpRequest;
+
+var
+ loop, attemptCounter = 0,
+ hostname, pathname,
+ inst, addr, brand, code, cord, hash, lang, name, para, paras,
+ farside, partedURL, path, proxyArray, urlArray, instance, modURL, newURL;
+
+//const url = location.href;
+
+const proxy = {
+'anonymousoverflow' : [
+'https://ao.cleberg.net'
+], // AnonymousOverflow
+'bibliogram' : [
+'https://bibliogram.art',
+], // Bibliogram
+'gothub' : [
+'https://gh.cleberg.net'
+], // GotHub
+'invidious' : [
+'https://invidious.cleberg.net'
+], // Invidious
+'libreddit' : [
+'https://libreddit.cleberg.net'
+], // libreddit
+'map' : [
+'https://www.openstreetmap.org'
+], // Maps
+'nitter' : [
+'https://nitter.cleberg.net'
+], // Nitter
+'scribe' : [
+'https://scribe.rip'
+], // Scribe
+'searx' : [
+'https://search.cleberg.net',
+], // SearXNG
+'libretranslate' : [
+'https://libretranslate.cleberg.net'
+], // LibreTranslate
+'teddit' : [
+'https://teddit.cleberg.net'
+], // teddit
+};
+
+function pageLoader() {
+//window.onprogress = (event) => {
+ // /questions/6464592/how-to-align-entire-html-body-to-the-center
+ const loadPage = '<html><head><link type="image/svg+xml" rel="shortcut icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🥸</text></svg>"><title>Proxy Redirect</title><style>html,body{height:100%;}html{display:table;margin:auto;}body{display:table-cell;vertical-align:middle;}body{background-color:#f1f1f1;font-family:"Helvetica Neue", Helvetica,Arial,sans-serif;cursor:default;user-select:none;max-height:100%;max-width:100%;}div{font-size:2.3em;font-weight:bold;}#main{font-size:2em;color:#F83600;text-transform:uppercase;position:relative;text-align:center;}#loader{font-style:italic;animation:flickerAnimation 1s infinite;}.centerm{display:block;margin-left:auto;margin-right:auto;width:100%;}.center{padding:1em 0px 1em 0px;text-align:center;}@keyframes flickerAnimation{0%{opacity:1;}50%{opacity:0;}100%{opacity:1;}}.flip{display:inline-block;transform:scaleX(-1);-moz-transform:scaleX(-1);-o-transform:scaleX(-1);-webkit-transform:scaleX(-1);filter:FlipH;-ms-filter:FlipH;}</style></head><body><div id="message" class="center"></div><div id="loader" class="center">🔀 Redirecting...</div></body></html>';
+ //const loadPage = '<html><head><link type="image/svg+xml" rel="shortcut icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🥸</text></svg>"><title>Proxy Redirect</title><style>html,body{height:100%;}html{display:table;margin:auto;}body{display:table-cell;vertical-align:middle;}body{background-color:#f1f1f1;font-family:"Helvetica Neue", Helvetica,Arial,sans-serif;cursor:default;user-select:none;max-height:100%;max-width:100%;}div{font-size:2.3em;font-weight:bold;}#icon-tc:before{content:"🔀";font-size:4em;display:flow-root;text-align:center;}#icon-tc{font-size:3em;}#main{font-size:2em;color:#F83600;text-transform:uppercase;position:relative;text-align:center;}#loader{font-style:italic;animation:flickerAnimation 1s infinite;}.centerm{display:block;margin-left:auto;margin-right:auto;width:100%;}.center{padding:1em 0px 1em 0px;text-align:center;}@keyframes flickerAnimation{0%{opacity:1;}50%{opacity:0;}100%{opacity:1;}}.flip{display:inline-block;transform:scaleX(-1);-moz-transform:scaleX(-1);-o-transform:scaleX(-1);-webkit-transform:scaleX(-1);filter:FlipH;-ms-filter:FlipH;}</style></head><body><div id="icon-tc"></div><div id="message" class="center"></div><div id="loader" class="center">Redirecting...</div></body></html>';
+ //const loadPage = '<html><head><link type="image/svg+xml" rel="shortcut icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🥸</text></svg>"><title>Proxy Redirect</title><meta http-equiv="content-type" content="text/html;charset=utf-8" /><meta name="generator" content="Clear Cinema Player" /><style>body {background-color:#efefef;font-family:"Helvetica Neue", Helvetica,Arial,sans-serif; cursor: default; user-select: none;max-height:100%;max-width:100%;}div{font-size:2.3em;font-weight:bold;}#icon-tc:before{content:"🔀";font-size:4em;display:flow-root;text-align:center;}#icon-tc{font-size:3em;}#main{font-size:2em;color:#F83600;text-transform:uppercase;position:relative;text-align:center;}#loader{font-style: italic;animation:flickerAnimation 1s infinite;} #wait, #reload, #footer {font-size:14px;font-weight:normal;} #wait {font-style: italic;} .centerm {display:block;margin-left:auto;margin-right:auto;width:100%;}.center{padding:1em 0px 1em 0px;text-align:center;/* border: 3px solid green; */}@keyframes flickerAnimation {0%{opacity:1;}50%{opacity:0;}100% {opacity:1;}}.flip {display: inline-block; transform: scaleX(-1); -moz-transform: scaleX(-1); -o-transform: scaleX(-1); -webkit-transform: scaleX(-1); filter: FlipH; -ms-filter: FlipH;}</style></head><body><div id="intro" class="center">Proxy Redirect</div><div id="icon-tc" onclick="(function(){document.location = document.location})();"></div><div id="loader" class="center">Redirecting...</div><div id="wait" class="center">Please wait while our monkeys find a working proxy</div><div id="reload" class="center" onclick="(function(){document.location = document.location})();"></div><div id="footer" class="center">Made with <a href="https://falkon.org/">Falkon</a> web browser (<a href="https://openuserjs.org/scripts/sjehuda/Proxy_Redirect/issues">Report issue</a>)</div></body></html>';
+ const domParser = new DOMParser();
+ const newDocument = domParser.parseFromString(loadPage, 'text/html');
+ //newDocument.querySelector('#icon-tc').onclick = () => {disable()}; // FIXME
+ //newDocument.querySelector('#icon-tc').addEventListener("click", disable, false);
+ const insertDocument = document.importNode(newDocument.documentElement, true);
+ const removeDocument = document.documentElement;
+ document.replaceChild(insertDocument, removeDocument);
+ setTimeout(message, 9000); // FIXME
+}
+
+function message() {
+ var div = document.querySelector('#message');
+ if (div) {
+ div.innerHTML = `🔀 Continue to ${modURL.hostname}`;
+ div.onclick = () => {location.href = modURL};
+ document.querySelector('#loader').remove();
+ } else {
+ location.href = 'https://openuserjs.org/scripts/sjehuda/Proxy_Redirect?autoredirect'
+ }
+}
+
+function noRespond() {
+ var div = document.querySelector('#message');
+ div.id = 'message-error'
+ div.innerHTML = 'Proxy list appears to be out of date. Continue to ' + location.host + ' or...';
+ div.onclick = () => {location.href = location.href + '#noredirect'; location.reload()};
+ var div = document.querySelector('#loader');
+ div.innerHTML = '🥸 Update Proxy Redirect';
+ div.onclick = () => {location.href = 'https://openuserjs.org/scripts/sjehuda/Proxy_Redirect'};
+}
+
+// FIXME
+// /questions/1397329/how-to-remove-the-hash-from-window-location-url-with-javascript-without-page-r
+function disable() {
+ window.location.href =
+ window.location.href.substr(
+ 0,
+ window.location.href.indexOf('#'))
+ + '#noredirect';
+}
+
+/*
+loop = setInterval(function() {
+ //modifyURL(location.href);
+ window.open(newURL,'_self');
+ //location.href = newURL;
+ console.info('Redirecting to ' + newURL);
+ clearInterval(loop);
+}, 1000);
+*/
+
+/*
+function modifyURL() {
+ inst = pickURL();
+ // make function synchronous
+ // /questions/8778267/synchronous-gm-xmlhttprequest-acting-asynchronously
+ stat = statRES(inst);
+ if (stat.match(200)) {
+ newURL = settURL();
+ } else {
+ pickURL(url);
+ }
+ return newURL;
+}
+*/
+
+// var caller = (function xhr() {
+var init = (function xhr() {
+ instance = pickURL();
+try {
+ gmXmlhttpRequest({
+ method: 'GET',
+ url: instance,
+ synchronous: true,
+ onprogress: pageLoader(),
+ onload: function(response) {
+ if (response.finalUrl.startsWith(instance)) {
+ location.href = settURL();
+ } else {
+ instance = instance.slice(instance.lastIndexOf('/')+1);
+ instance = instance.replace(/\./g,'-');
+ console.warn('Instance URL ' + instance + ' might be out of service. URL has changed. Please report this to the developer.');
+ if (maxAttempts()) {
+ noRespond()
+ return;
+ }
+ maxAttempts()
+ xhr();
+ }
+ },
+ onerror: function(response) {
+ instance = instance.slice(instance.lastIndexOf('/')+1);
+ instance = instance.replace(/\./g,'-');
+ console.warn('Instance URL ' + instance + ' might be offline. Status error: ' + response.status + '. Please report this to the developer.');
+ if (maxAttempts()) {
+ noRespond()
+ return;
+ }
+ maxAttempts()
+ xhr();
+ }
+ });
+} catch (err) {
+ console.warn(err)
+ console.info('Please contribute C++ to Greasemonkey for Falkon https://bugs.kde.org/show_bug.cgi?id=466533')
+ //pickURL();
+ farside = true;
+ location.href = settURL();
+}
+
+})();
+
+function maxAttempts() {
+ attemptCounter = attemptCounter + 1;
+ if (attemptCounter == urlArray.length) { return true; }
+}
+
+function setValue(para) {
+ if (partedURL.searchParams.get(para)) {
+ para = [para];
+ return pickParameters(para);
+ } else {
+ return 'auto';
+ }
+}
+
+function pickParameters(para) {
+ for (let i = 0; i < para.length; i++) {
+ if (partedURL.searchParams.get(para[i])) {
+ para = partedURL.searchParams.get(para[i]);
+ partedURL.searchParams.delete(para[i]);
+ return para;
+ }
+ }
+}
+
+function pickURL() {
+
+ partedURL = new URL(location.href);
+
+ paras = ['continue', 'retpath']
+ for (let i = 0; i < paras.length; i++) {
+ if (partedURL.searchParams.get(paras[i])) {
+ //partedURL = pickParameters(paras[i]);
+ partedURL = partedURL.searchParams.get(paras[i]);
+ partedURL = new URL(partedURL);
+ }
+ }
+
+ hostname = partedURL.hostname;
+ pathname = partedURL.pathname;
+
+ switch (true) {
+
+ case hostname.endsWith('github.com'):
+ urlArray = proxy.gothub;
+ break;
+
+ // TODO quadkey (mapquest)
+ // NOTE quadkeyToTile(quadkey) See /mapbox/tilebelt
+ case hostname.endsWith('wikimap.toolforge.org'):
+ case (hostname.endsWith('moovitapp.com') &&
+ partedURL.search.includes('tll')):
+ case (hostname.endsWith('bing.com') &&
+ pathname.startsWith('/maps')):
+ case (hostname.includes('google.') &&
+ pathname.startsWith('/maps')):
+ case (hostname.includes('waze.com') &&
+ pathname.startsWith('/live-map')):
+ case (hostname.includes('waze.com') &&
+ pathname.startsWith('/ul')):
+ case (hostname.includes('yandex.') &&
+ pathname.startsWith('/maps')):
+ urlArray = proxy.map;
+ break;
+
+ case hostname.endsWith('instagram.com'):
+ urlArray = proxy.bibliogram;
+ break;
+
+ case hostname.endsWith('medium.com'):
+ proxyArray = [proxy.libmedium, proxy.scribe];
+ break;
+
+ case hostname.endsWith('reddit.com'):
+ proxyArray = [proxy.libreddit, proxy.teddit];
+ break;
+
+ // FIXME
+ case (hostname.startsWith('search.yahoo.')):
+ case (pathname.startsWith('/search')):
+ case (hostname.includes('yandex.') &&
+ pathname.startsWith('/search')):
+ case (hostname.includes('yahoo.') &&
+ pathname.startsWith('/search')):
+ case (hostname.includes('bing.') &&
+ pathname.startsWith('/search')):
+ case (hostname.includes('google.') &&
+ pathname.startsWith('/search')):
+ proxyArray = [proxy.searx];
+ break;
+
+ case hostname.endsWith('stackoverflow.com'):
+ urlArray = proxy.anonymousoverflow;
+ break;
+
+ case hostname.endsWith('tiktok.com'):
+ urlArray = proxy.proxitok;
+ break;
+
+ case (hostname.endsWith('translate.yandex.com')):
+ // FIXME website blocks us from redirecting
+ // function setTimeout() seems to not work
+ // consider different approach/way
+ case (hostname.endsWith('translate.google.com')):
+ proxyArray = [proxy.libretranslate];
+ break;
+
+ case hostname.endsWith('twitter.com'):
+ urlArray = proxy.nitter;
+ break;
+
+ case hostname.endsWith('youtu.be'):
+ case hostname.endsWith('youtube.com'):
+ case hostname.endsWith('youtube-nocookie.com'):
+ case hostname.endsWith('invidious-invidious.invidious.svc.cluster.local:3000'):
+ proxyArray = [proxy.invidious];
+ break;
+
+ //default:
+ // return target;
+
+ }
+
+ // proxy select
+ if (proxyArray) {
+ urlArray = proxyArray[Math.floor(Math.random()*proxyArray.length)];
+ }
+
+ // instance select
+ return urlArray[Math.floor(Math.random()*urlArray.length)];
+
+}
+
+// Settlement
+function settURL() {
+ let newPath;
+ switch (urlArray) {
+
+ // consider function setTimeout()
+ case proxy.bibliogram:
+ if (!pathname.includes('accounts/login')) {
+ newPath = `/u/${para}`;
+ } else {
+ if (partedURL.searchParams.get('next')) {
+ para = ['next'];
+ para = pickParameters(para);
+ newPath = `/u/${para}`;
+ }
+ }
+ break;
+
+ case proxy.invidious:
+ if (partedURL.searchParams.get('v')) {
+ para = ['v'];
+ para = pickParameters(para);
+ newPath = `/watch?v=${para}`;
+ }
+ break;
+
+ case proxy.gothub:
+ if (hostname.endsWith('gist.github.com')) {
+ newPath = `/gist${pathname}`;
+ }
+ break;
+
+ case proxy.libmedium:
+ partedHost = hostname.split('.');
+ if (partedHost.length === 3 || partedHost.length === 4) {
+ name = partedHost[0];
+ }
+ newPath = `/@${name}${pathname}`;
+ break;
+
+ //if (paras[2] === 'auto') { paras[2] = ''; }
+
+ if ((paras[0] == 'auto') && (paras[1] == 'auto')) {
+ newPath = `/${paras[2]}`;
+ } else {
+ newPath = `/${paras[0]}/${paras[1]}/${paras[2]}`;
+ }
+ break;
+
+ case proxy.map:
+ // extract coordinations
+ /*
+ if (pathname.includes('@')) {
+ cord = pathname.split('/')[2].split('&')[0].slice(1);
+ cord = cord.split(',');
+ }
+ newPath = '/#map=' + cord[2].slice(0, 1) +
+ '/' + cord[0] + '/' + cord[1];
+ */
+ let lat, lon, zoom;
+ // extract coordinations
+ if (partedURL.search.includes('%7E')) { // %7E is ~
+ para = ['cp'];
+ cord = pickParameters(para);
+ cord = cord.split('~');
+ para = ['lvl'];
+ zoom = pickParameters(para);
+ lat = cord[0];
+ lon = cord[1];
+ } else
+ if (partedURL.search.includes('to')) {
+ para = ['to'];
+ cord = pickParameters(para);
+ cord = cord.slice(3).split(',');
+ lat = cord[0];
+ lon = cord[1];
+ } else
+ if (pathname.includes('ul') &&
+ partedURL.search.includes('ll')) {
+ para = ['ll'];
+ cord = pickParameters(para);
+ cord = cord.split(',');
+ para = ['zoom'];
+ zoom = pickParameters(para);
+ lat = cord[0];
+ lon = cord[1];
+ } else
+ if (partedURL.search.includes('ll')) {
+ para = ['ll'];
+ cord = pickParameters(para);
+ cord = cord.split(',');
+ para = ['z'];
+ zoom = pickParameters(para);
+ lat = cord[0];
+ lon = cord[1];
+ } else
+ if (partedURL.search.includes('tll')) {
+ para = ['tll'];
+ cord = pickParameters(para);
+ cord = cord.split('_');
+ lat = cord[0];
+ lon = cord[1];
+ } else
+ if (pathname.includes('@')) {
+ partedPath = pathname.split('/')
+ for (let i = 0; i < partedPath.length; i++) {
+ if (partedPath[i].startsWith('@')) {
+ cord = partedPath[i].split(',');
+ }
+ }
+ lat = cord[0].slice(1);
+ lon = cord[1];
+ zoom = cord[2];
+ //newPath = `/#map=${cord[2].slice(0, 2)}/${cord[0].slice(1)}/${cord[1]}`;
+ //newPath = `/#map=${cord[2]}/${cord[0].slice(1)}/${cord[1]}`;
+ //newPath = `/#${cord[2]}/${cord[0].slice(1)}/${cord[1]}/`;
+ }
+
+ if (lat && lon && zoom) {
+ newPath = `/#${zoom}/${lat}/${lon}/`;
+ } else
+ if (lat && lon && !zoom) {
+ newPath = `/#10/${lat}/${lon}/`;
+ }
+
+ if (!newPath && partedURL.searchParams.get('q')) {
+ para = ['q'];
+ para = pickParameters(para);
+ newPath = `/search?query=${para}`;
+ instance = 'https://www.openstreetmap.org';
+ }
+ break;
+
+ case proxy.searx:
+ // extract search parameter
+ para = ['q','text','p'];
+ para = pickParameters(para);
+ newPath = `/search?q=${para}`;
+ break;
+
+ case proxy.mikuinvidious:
+ if (!hostname.startsWith('www.')) {
+ partedHost = hostname.split('.');
+ if (partedHost.length === 3 || partedHost.length === 4) {
+ name = partedHost[0];
+ }
+ newPath = `/${name}${pathname}`;
+ }
+ break;
+
+ case proxy.tent:
+ partedHost = hostname.split('.');
+ if (partedHost.length === 3 || partedHost.length === 4) {
+ artist = partedHost[0];
+ }
+ partedPath = pathname.split('/');
+ type = partedPath[1];
+ name = partedPath[2];
+ if (name) {
+ newPath = `/release.php?artist=${artist}&type=${type}&name=${name}`;
+ } else {
+ newPath = `/release.php?artist=${artist}&type=${type}`;
+ }
+ break;
+
+ }
+
+ if (!newPath || newPath == '/') {
+ newPath = pathname + partedURL.search + partedURL.hash;
+ }
+
+ if (farside) {
+ if (urlArray.filter(str => str.includes('farside.link')).length) {
+ instance = urlArray.filter(str => str.includes('farside.link'))[0];
+ }
+ }
+
+ modURL = new URL(instance + newPath);
+ return modURL;
+
+}