From 23ae536550334a359b1472a5afb2616815390c92 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Thu, 10 Feb 2022 00:04:00 +0300 Subject: [PATCH] Added ProxiTok #22 --- src/assets/javascripts/helpers/search.js | 94 ++++++++++++++++++-- src/assets/javascripts/helpers/tiktok.js | 107 +++++++++++++++++++++++ src/pages/background/background.js | 4 + src/pages/popup/popup.html | 5 ++ src/pages/popup/popup.js | 8 ++ 5 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 src/assets/javascripts/helpers/tiktok.js diff --git a/src/assets/javascripts/helpers/search.js b/src/assets/javascripts/helpers/search.js index a51361e..c48a0ed 100644 --- a/src/assets/javascripts/helpers/search.js +++ b/src/assets/javascripts/helpers/search.js @@ -1,18 +1,102 @@ import commonHelper from './common.js' const targets = [ - /https?:\/\/(www\.|maps\.|search\.|)google\.com(\/search\?q=..*|\/$|)/, + /https?:\/\/(www\.|maps\.|search\.|)google\.com(\/search\?q=..*|\/$)/, ]; let redirects = { "searx": { "normal": [ - "https://a.searx.space", "https://anon.sx", - "https://beezboo.com", "https://darmarit.org/searx", "https://dynabyte.ca", "https://engo.mint.lgbt", - + "https://jsearch.pw", + "https://metasearch.nl", + "https://nibblehole.com", + "https://northboot.xyz", + "https://paulgo.io", + "https://procurx.pt", + "https://s.zhaocloud.net", + "https://search.antonkling.se", + "https://search.asynchronousexchange.com", + "https://search.biboumail.fr", + "https://search.bus-hit.me", + "https://search.disroot.org", + "https://search.ethibox.fr", + "https://search.jpope.org", + "https://search.mdosch.de", + "https://search.neet.works", + "https://search.ononoki.org", + "https://search.snopyta.org", + "https://search.st8.at", + "https://search.stinpriza.org", + "https://search.trom.tf", + "https://search.zdechov.net", + "https://searx-private-search.de", + "https://searx.bar", + "https://searx.be", + "https://searx.bissisoft.com", + "https://searx.divided-by-zero.eu", + "https://searx.dresden.network", + "https://searx.esmailelbob.xyz", + "https://searx.everdot.org", + "https://searx.fmac.xyz", + "https://searx.fossencdi.org", + "https://searx.gnous.eu", + "https://searx.gnu.style", + "https://searx.hardwired.link", + "https://searx.hummel-web.at", + "https://searx.lavatech.top", + "https://searx.mastodontech.de", + "https://searx.mha.fi", + "https://searx.mxchange.org", + "https://searx.nakhan.net", + "https://searx.netzspielplatz.de", + "https://searx.nevrlands.de", + "https://searx.ninja", + "https://searx.nixnet.services", + "https://searx.openhoofd.nl", + "https://searx.operationtulip.com", + "https://searx.org", + "https://searx.prvcy.eu", + "https://searx.pwoss.org", + "https://searx.rasp.fr", + "https://searx.roughs.ru", + "https://searx.ru", + "https://searx.run", + "https://searx.sadblog.xyz", + "https://searx.semipvt.com", + "https://searx.slash-dev.de", + "https://searx.solusar.de", + "https://searx.sp-codes.de", + "https://searx.stuehieyr.com", + "https://searx.theanonymouse.xyz", + "https://searx.thegreenwebfoundation.org", + "https://searx.tiekoetter.com", + "https://searx.tk", + "https://searx.tux.land", + "https://searx.tuxcloud.net", + "https://searx.tyil.nl", + "https://searx.vitanetworks.link", + "https://searx.webheberg.info", + "https://searx.xkek.net", + "https://searx.xyz", + "https://searx.zackptg5.com", + "https://searx.zapashcanon.fr", + "https://searx.zecircle.xyz", + "https://serx.cf", + "https://spot.ecloud.global", + "https://suche.dasnetzundich.de", + "https://suche.uferwerk.org", + "https://swag.pw", + "https://sx.catgirl.cloud", + "https://sx.fedi.tech", + "https://timdor.noip.me/searx", + "https://trovu.komun.org", + "https://www.gruble.de", + "https://www.webrats.xyz", + "https://xeek.com", + "https://searx.roflcopter.fr", ], "onion": [ "http://3afisqjw2rxm6z7mmstyt5rx75qfqrgxnkzftknbp2vhipr2nrmrjdyd.onion", @@ -145,7 +229,7 @@ function redirect(url, initiator) { } let searchQuery = ""; - url.search.slice(1).split("&").forEach(function (input) { + url.search.slice(1).split("&").forEach((input) => { if (input.startsWith("q=")) searchQuery = input; }); return `${randomInstance}${path}?${searchQuery}`; diff --git a/src/assets/javascripts/helpers/tiktok.js b/src/assets/javascripts/helpers/tiktok.js new file mode 100644 index 0000000..c2eb2fb --- /dev/null +++ b/src/assets/javascripts/helpers/tiktok.js @@ -0,0 +1,107 @@ +import commonHelper from './common.js' + +const targets = [ + /^https?:\/\/(www\.|)tiktok\.com.*/ +]; + +let redirects = { + "proxiTok": { + "normal": [ + "https://proxitok.herokuapp.com", + ] + } +} + +const getRedirects = () => redirects; +function setRedirects(val) { + redirects.proxiTok = val; + browser.storage.sync.set({ tiktokRedirects: redirects }) + console.log("tiktokRedirects: ", val) + for (const item of proxiTokRedirectsChecks) + if (!redirects.proxiTok.normal.includes(item)) { + var index = proxiTokRedirectsChecks.indexOf(item); + if (index !== -1) proxiTokRedirectsChecks.splice(index, 1); + } + setProxiTokRedirectsChecks(proxiTokRedirectsChecks); +} + +let proxiTokRedirectsChecks; +const getProxiTokRedirectsChecks = () => proxiTokRedirectsChecks; +function setProxiTokRedirectsChecks(val) { + proxiTokRedirectsChecks = val; + browser.storage.sync.set({ proxiTokRedirectsChecks }) + console.log("proxiTokRedirectsChecks: ", val) +} + +let proxiTokCustomRedirects = []; +const getProxiTokCustomRedirects = () => proxiTokCustomRedirects; +function setProxiTokCustomRedirects(val) { + proxiTokCustomRedirects = val; + browser.storage.sync.set({ proxiTokCustomRedirects }) + console.log("proxiTokCustomRedirects: ", val) +} + +let disableTiktok; +const getDisableTiktok = () => disableTiktok; +function setDisableTiktok(val) { + disableTiktok = val; + browser.storage.sync.set({ disableTiktok }) +} + +function redirect(url, initiator, type) { + // https://www.tiktok.com/@keysikaspol/video/7061265241887345946 + // https://www.tiktok.com/@keysikaspol + + if (disableTiktok) return null; + + if (type != "main_frame" && "sub_frame" && "xmlhttprequest") return null; + + let instancesList = [...proxiTokRedirectsChecks, ...proxiTokCustomRedirects]; + if (instancesList.length === 0) return null; + let randomInstance = commonHelper.getRandomInstance(instancesList) + + if (initiator && (instancesList.includes(initiator.origin) || targets.includes(initiator.host))) return null; + + let pathName = url.pathname.replace(new RegExp(/@.*\/(?=video)/), "") + + return `${randomInstance}${pathName}`; +} + +function isTiktok(url) { + return targets.some((rx) => rx.test(url.href)); +} + +async function init() { + let result = await browser.storage.sync.get([ + "disableTiktok", + "tiktokRedirects", + "proxiTokRedirectsChecks", + "proxiTokCustomRedirects", + ]) + disableTiktok = result.disableTiktok ?? false; + if (result.tiktokRedirects) + redirects = result.tiktokRedirects; + + proxiTokRedirectsChecks = result.proxiTokRedirectsChecks ?? [...redirects.proxiTok.normal]; + proxiTokCustomRedirects = result.proxiTokCustomRedirects ?? []; +} + +export default { + targets, + + getRedirects, + setRedirects, + + getDisableTiktok, + setDisableTiktok, + + getProxiTokRedirectsChecks, + setProxiTokRedirectsChecks, + + getProxiTokCustomRedirects, + setProxiTokCustomRedirects, + + redirect, + isTiktok, + init, +}; diff --git a/src/pages/background/background.js b/src/pages/background/background.js index e9d2f39..140f171 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -10,6 +10,7 @@ import mapsHelper from "../../assets/javascripts/helpers/maps.js"; import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; import mediumHelper from "../../assets/javascripts/helpers/medium.js"; import imgurHelper from "../../assets/javascripts/helpers/imgur.js"; +import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js"; window.browser = window.browser || window.chrome; @@ -24,6 +25,7 @@ function wholeInit() { wikipediaHelper.init() youtubeHelper.init() imgurHelper.init() + tiktokHelper.init() } wholeInit(); @@ -55,6 +57,8 @@ browser.webRequest.onBeforeRequest.addListener( else if (imgurHelper.isImgur(url)) newUrl = imgurHelper.redirect(url, initiator, details.type); + else if (tiktokHelper.isTiktok(url)) newUrl = tiktokHelper.redirect(url, initiator, details.type); + else if (translateHelper.isTranslate(url)) newUrl = translateHelper.redirect(url, initiator); else if (searchHelper.isSearch(url)) newUrl = searchHelper.redirect(url, initiator) diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 7a604f8..126912a 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -54,6 +54,11 @@ +
+

TikTok

+ +
+

Medium

diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 9b5422d..8d7a7bb 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -12,6 +12,7 @@ import translateHelper from "../../assets/javascripts/helpers/translate.js"; import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; import mediumHelper from "../../assets/javascripts/helpers/medium.js"; import imgurHelper from "../../assets/javascripts/helpers/imgur.js"; +import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js"; let disableTwitterElement = document.querySelector("#disable-nitter"); let disableYoutubeElement = document.querySelector("#disable-invidious"); @@ -23,6 +24,7 @@ let disableTranslateElement = document.querySelector("#disable-simplyTranslate") let disableWikipediaElement = document.querySelector("#disable-wikipedia"); let disableMediumElement = document.querySelector("#disable-medium"); let disableImgurElement = document.querySelector("#disable-imgur"); +let disableTiktokElement = document.querySelector("#disable-tiktok"); window.browser = window.browser || window.chrome; @@ -36,6 +38,7 @@ async function wholeInit() { await translateHelper.init(); await wikipediaHelper.init(); await imgurHelper.init(); + await tiktokHelper.init(); await mediumHelper.init(); }; @@ -50,6 +53,7 @@ wholeInit().then(() => { disableTranslateElement.checked = !translateHelper.getDisableTranslate(); disableWikipediaElement.checked = !wikipediaHelper.getDisableWikipedia(); disableImgurElement.checked = !imgurHelper.getDisableImgur(); + disableTiktokElement.checked = !tiktokHelper.getDisableTiktok(); disableMediumElement.checked = !mediumHelper.getDisableMedium(); }) @@ -89,6 +93,10 @@ disableImgurElement.addEventListener("change", (event) => imgurHelper.setDisableImgur(!event.target.checked) ); +disableTiktokElement.addEventListener("change", + (event) => tiktokHelper.setDisableTiktok(!event.target.checked) +); + disableMediumElement.addEventListener("change", (event) => mediumHelper.setDisableMedium(!event.target.checked) );