diff options
Diffstat (limited to 'src/assets/javascripts/services.js')
-rw-r--r-- | src/assets/javascripts/services.js | 83 |
1 files changed, 74 insertions, 9 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 446926c0..0aea56cc 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -30,6 +30,12 @@ function all(service, frontend, options, config) { return instances } +/** + * @param {string} service + * @param {URL} url + * @param {{}} config + * @param {string} frontend + */ function regexArray(service, url, config, frontend) { let targetList = config.services[service].targets if (frontend && 'excludeTargets' in config.services[service].frontends[frontend]) { @@ -44,15 +50,29 @@ function regexArray(service, url, config, frontend) { return false } +/** + * @param {URL} url + * @param {string} type + * @param {URL} initiator + * @param {boolean} forceRedirection + */ async function redirectAsync(url, type, initiator, forceRedirection) { await init() return redirect(url, type, initiator, forceRedirection) } -function redirect(url, type, initiator, forceRedirection) { +/** + * @param {URL} url + * @param {string} type + * @param {URL} initiator + * @param {boolean} forceRedirection + * @returns {string | undefined} + */ +function redirect(url, type, initiator, forceRedirection, incognito) { if (type != "main_frame" && type != "sub_frame" && type != "image") return let randomInstance let frontend + if (!forceRedirection && options.redirectOnlyInIncognito == true && !incognito) return for (const service in config.services) { if (!forceRedirection && !options[service].enabled) continue @@ -147,6 +167,10 @@ function redirect(url, type, initiator, forceRedirection) { case "freetube": { return 'freetube://' + url.href } + case "freetubePwa": { + return 'freetube://' + url.href + } + case "poketube": { if (url.pathname.startsWith('/channel')) { const reg = /\/channel\/(.*)\/?$/.exec(url.pathname) @@ -375,7 +399,7 @@ function redirect(url, type, initiator, forceRedirection) { } case "anonymousOverflow": { if (url.hostname == "stackoverflow.com") { - const threadID = /\/(\d+)\/?$/.exec(url.pathname) + const threadID = /^\/a\/(\d+)\/?/.exec(url.pathname) if (threadID) return `${randomInstance}/questions/${threadID[1]}${url.search}` return `${randomInstance}${url.pathname}${url.search}` } @@ -524,26 +548,39 @@ function redirect(url, type, initiator, forceRedirection) { return `${randomInstance}` } case "tuboSoundcloud": { - if (url.pathname.match(/\/user[^\/]+(\/$|$)/)) { + if (url.pathname == '/') return `${randomInstance}?kiosk?serviceId=1` + if (url.pathname.match(/^\/[^\/]+(\/$|$)/)) { return `${randomInstance}/channel?url=${encodeURIComponent(url.href)}` } - if (url.pathname.match(/\/user[^\/]+\/[^\/]+/)) { + if (url.pathname.match(/^\/[^\/]+\/[^\/]+/)) { return `${randomInstance}/stream?url=${encodeURIComponent(url.href)}` } return `${randomInstance}` } + case "twineo": case "safetwitch": { if (url.hostname.startsWith("clips.")) { return `${randomInstance}/clip${url.pathname}${url.search}` } return `${randomInstance}${url.pathname}${url.search}` } + case "tekstoLibre": { + return `${randomInstance}/?${url.pathname.slice(1)}`; + } + case "skyview": { + if (url.pathname == '/') return randomInstance + return `${randomInstance}?url=${encodeURIComponent(url.href)}` + } default: { return `${randomInstance}${url.pathname}${url.search}` } } } +/** + * @param {URL} url + * @param {*} returnFrontend + */ function computeService(url, returnFrontend) { return new Promise(async resolve => { const config = await utils.getConfig() @@ -568,6 +605,10 @@ function computeService(url, returnFrontend) { }) } +/** + * @param {URL} url + * @param {string} customService + */ function switchInstance(url, customService) { return new Promise(async resolve => { let options = await utils.getOptions() @@ -577,7 +618,7 @@ function switchInstance(url, customService) { if (customService) { const instancesList = options[options[customService].frontend] if (instancesList !== undefined) { - resolve(`${utils.getRandomInstance(instancesList)}${url.pathname}${url.search}`) + resolve(`${utils.getNextInstance(url.origin, instancesList)}${url.pathname}${url.search}`) } } else { for (const service in config.services) { @@ -590,7 +631,7 @@ function switchInstance(url, customService) { resolve() return } - resolve(`${utils.getRandomInstance(instancesList)}${url.pathname}${url.search}`) + resolve(`${utils.getNextInstance(url.origin, instancesList)}${url.pathname}${url.search}`) return } } @@ -598,6 +639,9 @@ function switchInstance(url, customService) { }) } +/** + * @param {URL} url + */ async function reverse(url) { let options = await utils.getOptions() let config = await utils.getConfig() @@ -640,6 +684,9 @@ async function reverse(url) { } return } + case "tekstowo": { + return `${config.services[service].url}/${url.search.slice(1)}` + } default: return } @@ -689,9 +736,12 @@ const defaultInstances = { 'indestructables': ['https://indestructables.private.coffee'], 'destructables': ['https://ds.vern.cc'], 'safetwitch': ['https://safetwitch.drgns.space'], + 'twineo': ['https://twineo.exozy.me'], 'proxigram': ['https://proxigram.privacyfrontends.repl.co'], 'tuboYoutube': ['https://tubo.migalmoreno.com'], 'tuboSoundcloud': ['https://tubo.migalmoreno.com'], + 'tekstoLibre': ['https://davilarek.github.io/TekstoLibre'], + 'skyview': ['https://skyview.social'], } function initDefaults() { @@ -714,9 +764,10 @@ function initDefaults() { url: [], regex: [], } - options['theme'] = "detect" - options['popupServices'] = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"] - options['fetchInstances'] = 'github' + options.theme = "detect" + options.popupServices = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"] + options.fetchInstances = 'github' + options.redirectOnlyInIncognito = false options = { ...options, ...defaultInstances } @@ -765,6 +816,13 @@ function processUpdate() { delete options[frontend] } } + + for (const frontend of options.popupServices) { + if (!Object.keys(config.services).includes(frontend)) { + const i = options.popupServices.indexOf(frontend); + if (i > -1) options.popupServices.splice(i, 1); + } + } } browser.storage.local.set({ options }, () => { resolve() @@ -772,6 +830,10 @@ function processUpdate() { }) } +/** + * @param {URL} url + * @param {boolean} test + */ async function copyRaw(url, test) { const newUrl = await reverse(url) if (newUrl) { @@ -792,6 +854,9 @@ async function copyRaw(url, test) { } } +/** + * @param {URL} url + */ function isException(url) { if (!options.exceptions) return false let exceptions = options.exceptions |