diff --git a/src/assets/images/send-icon.svg b/src/assets/images/send-icon.svg new file mode 100644 index 0000000..2ed80a0 --- /dev/null +++ b/src/assets/images/send-icon.svg @@ -0,0 +1,51 @@ + + + + + + + + + diff --git a/src/assets/javascripts/helpers/sendTargets.js b/src/assets/javascripts/helpers/sendTargets.js new file mode 100644 index 0000000..3108257 --- /dev/null +++ b/src/assets/javascripts/helpers/sendTargets.js @@ -0,0 +1,188 @@ +window.browser = window.browser || window.chrome; + +import commonHelper from './common.js' + +const targets = [ + /^https?:\/\/send\.firefox\.com\/$/, + /^https?:\/\/sendfiles\.online\/$/ +]; + +let redirects = { + "send": { + "normal": [ + "https://send.silkky.cloud", + "https://send.turingpoint.de", + "https://send.ephemeral.land", + "https://send.monks.tools", + "https://send.jeugdhulp.be", + "https://send.aurorabilisim.com", + "https://nhanh.cloud", + "https://send.datahoarder.dev", + "https://send.navennec.net", + "https://fileupload.ggc-project.de", + "https://drop.chapril.org", + "https://files.psu.ru", + "https://send.portailpro.net", + "https://bytefile.de", + "https://transfer.acted.org ", + ], + "tor": [] + } +} + +const getRedirects = () => redirects; +const getCustomRedirects = function () { + return { + "send": { + "normal": [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects] + }, + }; +}; + +function setRedirects(val) { + redirects.send = val; + browser.storage.local.set({ sendTargetsRedirects: redirects }) + console.log("sendTargetsRedirects: ", val) + for (const item of sendNormalRedirectsChecks) + if (!redirects.send.normal.includes(item)) { + var index = sendNormalRedirectsChecks.indexOf(item); + if (index !== -1) sendNormalRedirectsChecks.splice(index, 1); + } + setSendNormalRedirectsChecks(sendNormalRedirectsChecks); + + for (const item of sendTorRedirectsChecks) + if (!redirects.send.normal.includes(item)) { + var index = sendTorRedirectsChecks.indexOf(item); + if (index !== -1) sendTorRedirectsChecks.splice(index, 1); + } + setSendTorRedirectsChecks(sendTorRedirectsChecks); +} + +let sendNormalRedirectsChecks; +const getSendNormalRedirectsChecks = () => sendNormalRedirectsChecks; +function setSendNormalRedirectsChecks(val) { + sendNormalRedirectsChecks = val; + browser.storage.local.set({ sendNormalRedirectsChecks }) + console.log("sendNormalRedirectsChecks: ", val) +} + +let sendTorRedirectsChecks; +const getSendTorRedirectsChecks = () => sendTorRedirectsChecks; +function setSendTorRedirectsChecks(val) { + sendTorRedirectsChecks = val; + browser.storage.local.set({ sendTorRedirectsChecks }) + console.log("sendTorRedirectsChecks: ", val) +} + +let sendNormalCustomRedirects = []; +const getSendNormalCustomRedirects = () => sendNormalCustomRedirects; +function setSendNormalCustomRedirects(val) { + sendNormalCustomRedirects = val; + browser.storage.local.set({ sendNormalCustomRedirects }) + console.log("sendNormalCustomRedirects: ", val) +} + +let sendTorCustomRedirects = []; +const getSendTorCustomRedirects = () => sendTorCustomRedirects; +function setSendTorCustomRedirects(val) { + sendTorCustomRedirects = val; + browser.storage.local.set({ sendTorCustomRedirects }) + console.log("sendTorCustomRedirects: ", val) +} + +let disable; +const getDisable = () => disable; +function setDisable(val) { + disable = val; + browser.storage.local.set({ disableSendTarget: disable }) +} + +let protocol; +const getProtocol = () => protocol; +function setProtocol(val) { + protocol = val; + browser.storage.local.set({ sendTargetsProtocol: val }) + console.log("sendTargetsProtocol: ", val) +} + +function redirect(url, type, initiator) { + + if (disable) return null; + if (initiator && ([...redirects.send.normal, ...sendNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null; + if (!targets.some((rx) => rx.test(url.href))) return null; + + if (type != "main_frame") return null; + + let instancesList; + if (protocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects]; + if (protocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects]; + if (instancesList.length === 0) return null; + let randomInstance = commonHelper.getRandomInstance(instancesList); + + let pathName = url.pathname.replace(new RegExp(/@.*\/(?=video)/), ""); + + return `${randomInstance}${pathName}`; +} + +async function init() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(data => { + let dataJson = JSON.parse(data); + browser.storage.local.get( + [ + "disableSendTarget", + "sendTargetsRedirects", + + "sendNormalRedirectsChecks", + "sendNormalCustomRedirects", + + "sendTorRedirectsChecks", + "sendTorCustomRedirects", + + "sendTargetsProtocol" + ], + r => { + disable = r.disableSendTarget ?? false; + + protocol = r.sendTargetsProtocol ?? "normal"; + + if (r.sendTargetsRedirects) redirects = r.sendTargetsRedirects; + + sendNormalRedirectsChecks = r.sendNormalRedirectsChecks ?? [...redirects.send.normal]; + sendNormalCustomRedirects = r.sendNormalCustomRedirects ?? []; + + sendTorRedirectsChecks = r.sendTorRedirectsChecks ?? [...redirects.send.tor]; + sendTorCustomRedirects = r.sendTorCustomRedirects ?? []; + + resolve(); + } + ) + }); + }); +} + +export default { + + getRedirects, + getCustomRedirects, + setRedirects, + + getDisable, + setDisable, + + getProtocol, + setProtocol, + + getSendNormalRedirectsChecks, + setSendNormalRedirectsChecks, + getSendTorRedirectsChecks, + setSendTorRedirectsChecks, + + getSendTorCustomRedirects, + setSendTorCustomRedirects, + getSendNormalCustomRedirects, + setSendNormalCustomRedirects, + + redirect, + init, +}; diff --git a/src/assets/javascripts/helpers/wikipedia.js b/src/assets/javascripts/helpers/wikipedia.js index 299e6cd..1217162 100644 --- a/src/assets/javascripts/helpers/wikipedia.js +++ b/src/assets/javascripts/helpers/wikipedia.js @@ -2,7 +2,7 @@ window.browser = window.browser || window.chrome; import commonHelper from './common.js' -const targets = /^https?:\/\/.*wikipedia\.org\// +const targets = /^https?:\/\/(.*\.|)wikipedia\.org/ let redirects = { "wikiless": { diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 8ab6ad8..6b41b34 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -12,6 +12,7 @@ import mediumHelper from "../../assets/javascripts/helpers/medium.js"; import imgurHelper from "../../assets/javascripts/helpers/imgur.js"; import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js"; import pixivHelper from "../../assets/javascripts/helpers/pixiv.js"; +import sendTargetsHelper from "../../assets/javascripts/helpers/sendTargets.js"; import generalHelper from "../../assets/javascripts/helpers/general.js"; import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js"; @@ -31,6 +32,7 @@ async function wholeInit() { imgurHelper.init() tiktokHelper.init() pixivHelper.init() + sendTargetsHelper.init() generalHelper.init() } wholeInit(); @@ -52,7 +54,6 @@ browser.webRequest.onBeforeRequest.addListener( var newUrl; if (!newUrl) newUrl = youtubeHelper.redirect(url, details, initiator) - // if (youtubeHelper.isPipedorInvidious(newUrl ?? url, details.type, 'invidious')) newUrl = youtubeHelper.addUrlParams(newUrl ?? url); if (youtubeMusicHelper.isYoutubeMusic(url, initiator)) newUrl = youtubeMusicHelper.redirect(url, details.type) if (!newUrl) newUrl = twitterHelper.redirect(url, initiator); @@ -71,6 +72,8 @@ browser.webRequest.onBeforeRequest.addListener( if (!newUrl) newUrl = pixivHelper.redirect(url, details.type, initiator); + if (!newUrl) newUrl = sendTargetsHelper.redirect(url, details.type, initiator); + if (translateHelper.isTranslate(url, initiator)) newUrl = translateHelper.redirect(url); if (searchHelper.isSearch(url)) newUrl = searchHelper.redirect(url) @@ -110,10 +113,6 @@ browser.tabs.onRemoved.addListener((tabId) => { } }); - - - - browser.webRequest.onResponseStarted.addListener( details => { console.log("onResponseStarted"); @@ -121,13 +120,13 @@ browser.webRequest.onResponseStarted.addListener( if (!autoRedirect) return null; - if (details.statusCode >= 500) { + console.log("statusCode", details.statusCode); + if (details.type == 'main_frame' && details.statusCode >= 500) { const url = new URL(details.url); let newUrl; newUrl = youtubeHelper.changeInstance(url); - if (!newUrl) newUrl = twitterHelper.changeInstance(url); if (!newUrl) newUrl = instagramHelper.changeInstance(url); @@ -145,12 +144,9 @@ browser.webRequest.onResponseStarted.addListener( if (!newUrl) newUrl = wikipediaHelper.changeInstance(url) if (newUrl) { - browser.tabs.update({ url: '../errors/instance_offline.html' }); - + browser.tabs.update({ url: '/pages/errors/instance_offline.html' }); setTimeout(() => browser.tabs.update({ url: newUrl }), 2000); } - - } }, { urls: [""], } @@ -162,8 +158,6 @@ browser.tabs.onUpdated.addListener( try { url = new URL(changeInfo.url); } catch (_) { return } if (youtubeHelper.isPipedorInvidious(url, 'main_frame', 'piped')) youtubeHelper.initPipedLocalStorage(tabId); - // if (twitterHelper.isNitter(url, 'main_frame')) twitterHelper.initNitterCookies(); if (instagramHelper.isBibliogram(url)) instagramHelper.initBibliogramCookies(url); // if (changeInfo.url && youtubeHelper.isPipedorInvidious(url, 'main_frame', 'pipedMaterial')) youtubeHelper.initPipedMaterialLocalStorage(tabId); - // if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'invidious')) youtubeHelper.initInvidiousCookies(tabId); }); \ No newline at end of file diff --git a/src/pages/options/general/general.html b/src/pages/options/general/general.html index acacc59..d3b82af 100644 --- a/src/pages/options/general/general.html +++ b/src/pages/options/general/general.html @@ -87,6 +87,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/imgur/imgur.html b/src/pages/options/imgur/imgur.html index 8f611ca..b1e1ac7 100644 --- a/src/pages/options/imgur/imgur.html +++ b/src/pages/options/imgur/imgur.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/instagram/instagram.html b/src/pages/options/instagram/instagram.html index fe99d12..dbcd28c 100644 --- a/src/pages/options/instagram/instagram.html +++ b/src/pages/options/instagram/instagram.html @@ -89,6 +89,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/maps/maps.html b/src/pages/options/maps/maps.html index c0a9b7d..7be5bdb 100644 --- a/src/pages/options/maps/maps.html +++ b/src/pages/options/maps/maps.html @@ -89,7 +89,13 @@ Maps - +
+ + + + Send Files +
diff --git a/src/pages/options/medium/medium.html b/src/pages/options/medium/medium.html index 89d7302..b323081 100644 --- a/src/pages/options/medium/medium.html +++ b/src/pages/options/medium/medium.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/pixiv/pixiv.html b/src/pages/options/pixiv/pixiv.html index 43d3bf7..1d10ca0 100644 --- a/src/pages/options/pixiv/pixiv.html +++ b/src/pages/options/pixiv/pixiv.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/reddit/reddit.html b/src/pages/options/reddit/reddit.html index 0ced873..b0250dc 100644 --- a/src/pages/options/reddit/reddit.html +++ b/src/pages/options/reddit/reddit.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/search/search.html b/src/pages/options/search/search.html index 6f2bc64..1349445 100644 --- a/src/pages/options/search/search.html +++ b/src/pages/options/search/search.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/sendTargets/sendTargets.html b/src/pages/options/sendTargets/sendTargets.html new file mode 100644 index 0000000..387e87d --- /dev/null +++ b/src/pages/options/sendTargets/sendTargets.html @@ -0,0 +1,168 @@ + + + + + + + + + + LibRedirect Options: TikTok + + + + + +
+
+

Enable

+ +
+ +
+

Protocol

+ +
+ +
+ +
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/src/pages/options/sendTargets/sendTargets.js b/src/pages/options/sendTargets/sendTargets.js new file mode 100644 index 0000000..0b0a937 --- /dev/null +++ b/src/pages/options/sendTargets/sendTargets.js @@ -0,0 +1,59 @@ +import sendTargetsHelper from "../../../assets/javascripts/helpers/sendTargets.js"; +import commonHelper from "../../../assets/javascripts/helpers/common.js"; + +let disableSendTargetsElement = document.getElementById("disable-sendTargets"); +disableSendTargetsElement.addEventListener("change", + (event) => sendTargetsHelper.setDisable(!event.target.checked) +); + +let protocolElement = document.getElementById("protocol") +protocolElement.addEventListener("change", + (event) => { + let protocol = event.target.options[protocolElement.selectedIndex].value + sendTargetsHelper.setProtocol(protocol); + changeProtocolSettings(protocol); + } +); + +function changeProtocolSettings(protocol) { + let normalDiv = document.getElementById("normal"); + let torDiv = document.getElementById("tor"); + if (protocol == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +sendTargetsHelper.init().then(() => { + disableSendTargetsElement.checked = !sendTargetsHelper.getDisable(); + + let protocol = sendTargetsHelper.getProtocol(); + protocolElement.value = protocol; + changeProtocolSettings(protocol); + + commonHelper.processDefaultCustomInstances( + 'send', + 'normal', + sendTargetsHelper, + document, + sendTargetsHelper.getSendNormalRedirectsChecks, + sendTargetsHelper.setSendNormalRedirectsChecks, + sendTargetsHelper.getSendNormalCustomRedirects, + sendTargetsHelper.setSendNormalCustomRedirects + ); + + commonHelper.processDefaultCustomInstances( + 'send', + 'tor', + sendTargetsHelper, + document, + sendTargetsHelper.getSendTorRedirectsChecks, + sendTargetsHelper.setSendTorRedirectsChecks, + sendTargetsHelper.getSendTorCustomRedirects, + sendTargetsHelper.setSendTorCustomRedirects + ) +}) \ No newline at end of file diff --git a/src/pages/options/tiktok/tiktok.html b/src/pages/options/tiktok/tiktok.html index 0e003f3..c493fc2 100644 --- a/src/pages/options/tiktok/tiktok.html +++ b/src/pages/options/tiktok/tiktok.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/translate/translate.html b/src/pages/options/translate/translate.html index 01b0224..ed74416 100644 --- a/src/pages/options/translate/translate.html +++ b/src/pages/options/translate/translate.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/twitter/twitter.html b/src/pages/options/twitter/twitter.html index 00ae8e9..fadba31 100644 --- a/src/pages/options/twitter/twitter.html +++ b/src/pages/options/twitter/twitter.html @@ -89,6 +89,13 @@ Maps
+
+ + + + Send Files +
diff --git a/src/pages/options/wikipedia/wikipedia.html b/src/pages/options/wikipedia/wikipedia.html index c38def3..258578b 100644 --- a/src/pages/options/wikipedia/wikipedia.html +++ b/src/pages/options/wikipedia/wikipedia.html @@ -88,6 +88,13 @@ Maps +
+ + + + Send Files +
diff --git a/src/pages/options/youtube/youtube.html b/src/pages/options/youtube/youtube.html index 7ef7f96..32555eb 100644 --- a/src/pages/options/youtube/youtube.html +++ b/src/pages/options/youtube/youtube.html @@ -89,6 +89,13 @@ Maps
+
+ + + + Send Files +
diff --git a/src/pages/options/youtubeMusic/youtubeMusic.html b/src/pages/options/youtubeMusic/youtubeMusic.html index e327ba3..15d1c38 100644 --- a/src/pages/options/youtubeMusic/youtubeMusic.html +++ b/src/pages/options/youtubeMusic/youtubeMusic.html @@ -89,6 +89,13 @@ Maps +
+ + + + Send Files +