From 1f8e0d00e13fcd5d26f7e58499c534509ecc44ae Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Mar 2024 16:27:18 +0100 Subject: Move rewrite logic to own function --- src/assets/javascripts/services.js | 119 ++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 54 deletions(-) (limited to 'src/assets/javascripts/services.js') diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 1a9c3f29..b23295db 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -62,61 +62,13 @@ async function redirectAsync(url, type, initiator, forceRedirection) { } /** - * @param {URL} url - * @param {string} type - * @param {URL} initiator - * @param {boolean} forceRedirection - * @returns {string | undefined} + * @param url + * @param frontend + * @param randomInstance + * @returns {undefined|string} */ -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 - - frontend = options[service].frontend - - - if (config.services[service].frontends[frontend].desktopApp && type != "main_frame" && options[service].redirectType != "main_frame") - frontend = options[service].embedFrontend - - - if (!regexArray(service, url, config, frontend)) { - frontend = null - continue - } - - if ( - config.services[service].embeddable && - type != options[service].redirectType && options[service].redirectType != "both" - ) { - if (options[service].unsupportedUrls == 'block') return 'CANCEL' - return - } - - let instanceList = options[frontend] - if (instanceList === undefined) break - if (instanceList.length === 0) return null - - if ( - initiator - && - instanceList.includes(initiator.origin) - ) { - if (type != "main_frame") return null - else return "BYPASSTAB" - } - - randomInstance = utils.getRandomInstance(instanceList) - if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") { - randomInstance = `http://${frontend}.localhost:8080` - } - break - } - if (!frontend) return - +function rewrite(url, frontend, randomInstance){ + if (!frontend || !randomInstance) return switch (frontend) { case "hyperpipe": { return `${randomInstance}${url.pathname}${url.search}`.replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/")) @@ -557,6 +509,65 @@ function redirect(url, type, initiator, forceRedirection, incognito) { } } +/** + * @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 + + frontend = options[service].frontend + + + if (config.services[service].frontends[frontend].desktopApp && type != "main_frame" && options[service].redirectType != "main_frame") + frontend = options[service].embedFrontend + + + if (!regexArray(service, url, config, frontend)) { + frontend = null + continue + } + + if ( + config.services[service].embeddable && + type != options[service].redirectType && options[service].redirectType != "both" + ) { + if (options[service].unsupportedUrls == 'block') return 'CANCEL' + return + } + + let instanceList = options[frontend] + if (instanceList === undefined) break + if (instanceList.length === 0) return null + + if ( + initiator + && + instanceList.includes(initiator.origin) + ) { + if (type != "main_frame") return null + else return "BYPASSTAB" + } + + randomInstance = utils.getRandomInstance(instanceList) + if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") { + randomInstance = `http://${frontend}.localhost:8080` + } + break + } + if (!frontend) return + + return rewrite(url, frontend, randomInstance) +} + /** * @param {URL} url * @param {*} returnFrontend -- cgit 1.4.1 From ab7a702accc0c4f28867762621357ff1ef3f1443 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Thu, 14 Mar 2024 12:49:42 +0300 Subject: Cleaned code --- src/assets/javascripts/services.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/assets/javascripts/services.js') diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index b23295db..8bbc6de4 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -67,15 +67,16 @@ async function redirectAsync(url, type, initiator, forceRedirection) { * @param randomInstance * @returns {undefined|string} */ -function rewrite(url, frontend, randomInstance){ +function rewrite(url, frontend, randomInstance) { if (!frontend || !randomInstance) return switch (frontend) { case "hyperpipe": { return `${randomInstance}${url.pathname}${url.search}`.replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/")) } case "searx": - case "searxng": + case "searxng": { return `${randomInstance}/${url.search}` + } case "whoogle": { return `${randomInstance}/search${url.search}` } @@ -101,7 +102,6 @@ function rewrite(url, frontend, randomInstance){ case "freetubePwa": { return 'freetube://' + url.href } - case "poketube": { if (url.pathname.startsWith('/channel')) { const reg = /\/channel\/(.*)\/?$/.exec(url.pathname) @@ -526,18 +526,17 @@ function redirect(url, type, initiator, forceRedirection, incognito) { frontend = options[service].frontend - if (config.services[service].frontends[frontend].desktopApp && type != "main_frame" && options[service].redirectType != "main_frame") frontend = options[service].embedFrontend - if (!regexArray(service, url, config, frontend)) { frontend = null continue } if ( - config.services[service].embeddable && + config.services[service].embeddable + && type != options[service].redirectType && options[service].redirectType != "both" ) { if (options[service].unsupportedUrls == 'block') return 'CANCEL' @@ -548,11 +547,7 @@ function redirect(url, type, initiator, forceRedirection, incognito) { if (instanceList === undefined) break if (instanceList.length === 0) return null - if ( - initiator - && - instanceList.includes(initiator.origin) - ) { + if (initiator && instanceList.includes(initiator.origin)) { if (type != "main_frame") return null else return "BYPASSTAB" } -- cgit 1.4.1 From 95ddb93edd0a0372c033e7dbb78cd5fc57a50a8a Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Thu, 14 Mar 2024 13:50:28 +0300 Subject: Added UNfunny https://github.com/libredirect/browser_extension/issues/888 --- src/assets/images/ifunny-icon.svg | 56 ++++++++++++++++++++++++++++++++++++++ src/assets/javascripts/services.js | 1 + src/config.json | 20 ++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/assets/images/ifunny-icon.svg (limited to 'src/assets/javascripts/services.js') diff --git a/src/assets/images/ifunny-icon.svg b/src/assets/images/ifunny-icon.svg new file mode 100644 index 00000000..b8f37515 --- /dev/null +++ b/src/assets/images/ifunny-icon.svg @@ -0,0 +1,56 @@ + + + + diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 8bbc6de4..96595fda 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -717,6 +717,7 @@ const defaultInstances = { 'biblioReads': ['https://biblioreads.ml'], 'wikiless': ['https://wikiless.org'], 'suds': ['https://sd.vern.cc'], + 'unfunny': ['https://uf.vern.cc'], 'waybackClassic': ['https://wayback-classic.net'], 'gothub': ['https://gh.odyssey346.dev'], 'mikuInvidious': ['https://mikuinv.resrv.org'], diff --git a/src/config.json b/src/config.json index b70cb074..808a32b9 100644 --- a/src/config.json +++ b/src/config.json @@ -717,6 +717,26 @@ "imageType": "svg", "url": "https://www.snopes.com" }, + "ifunny": { + "frontends": { + "unfunny": { + "name": "UNfunny", + "instanceList": true, + "url": "https://git.vern.cc/cobra/UNfunny" + } + }, + "targets": [ + "^https?:\\/{2}(www\\.)?ifunny\\.co\\/" + ], + "name": "iFunny", + "options": { + "enabled": false, + "unsupportedUrls": "bypass", + "frontend": "unfunny" + }, + "imageType": "svg", + "url": "https://ifunny.co" + }, "urbanDictionary": { "frontends": { "ruralDictionary": { -- cgit 1.4.1 From b9b2a53fd38a6573231ceee86b2c9ab2b55003e7 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Thu, 14 Mar 2024 14:03:10 +0300 Subject: Added Soprano https://github.com/libredirect/browser_extension/issues/888 --- src/assets/images/tenor-icon.svg | 51 ++++++++++++++++++++++++++++++++++++++ src/assets/javascripts/services.js | 1 + src/config.json | 20 +++++++++++++++ src/pages/stylesheets/styles.css | 2 +- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/assets/images/tenor-icon.svg (limited to 'src/assets/javascripts/services.js') diff --git a/src/assets/images/tenor-icon.svg b/src/assets/images/tenor-icon.svg new file mode 100644 index 00000000..8cdc1214 --- /dev/null +++ b/src/assets/images/tenor-icon.svg @@ -0,0 +1,51 @@ + +TENOR_VECTORCreated with Sketch. diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 96595fda..dceb1c2d 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -718,6 +718,7 @@ const defaultInstances = { 'wikiless': ['https://wikiless.org'], 'suds': ['https://sd.vern.cc'], 'unfunny': ['https://uf.vern.cc'], + 'soprano': ['https://sp.vern.cc'], 'waybackClassic': ['https://wayback-classic.net'], 'gothub': ['https://gh.odyssey346.dev'], 'mikuInvidious': ['https://mikuinv.resrv.org'], diff --git a/src/config.json b/src/config.json index 808a32b9..cf4ed558 100644 --- a/src/config.json +++ b/src/config.json @@ -737,6 +737,26 @@ "imageType": "svg", "url": "https://ifunny.co" }, + "tenor": { + "frontends": { + "soprano": { + "name": "Soprano", + "instanceList": true, + "url": "https://git.vern.cc/cobra/Soprano" + } + }, + "targets": [ + "^https?:\\/{2}(www\\.)?tenor\\.com\\/" + ], + "name": "Tenor", + "options": { + "enabled": false, + "unsupportedUrls": "bypass", + "frontend": "soprano" + }, + "imageType": "svg", + "url": "https://tenor.com" + }, "urbanDictionary": { "frontends": { "ruralDictionary": { diff --git a/src/pages/stylesheets/styles.css b/src/pages/stylesheets/styles.css index 5de72477..e3212a66 100644 --- a/src/pages/stylesheets/styles.css +++ b/src/pages/stylesheets/styles.css @@ -131,7 +131,7 @@ section.links { flex-wrap: wrap; flex-direction: column; width: 350px; - max-height: 930px; + max-height: 970px; } section.links div { -- cgit 1.4.1 From b3457faf1bdcca0b17872e30b379a7ae55bc8fd0 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Thu, 14 Mar 2024 14:21:20 +0300 Subject: Added MeMe https://github.com/libredirect/browser_extension/issues/888 --- src/assets/images/knowyourmeme-icon.svg | 76 +++++++++++++++++++++++++++++++++ src/assets/javascripts/services.js | 1 + src/config.json | 20 +++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/assets/images/knowyourmeme-icon.svg (limited to 'src/assets/javascripts/services.js') diff --git a/src/assets/images/knowyourmeme-icon.svg b/src/assets/images/knowyourmeme-icon.svg new file mode 100644 index 00000000..9f249b08 --- /dev/null +++ b/src/assets/images/knowyourmeme-icon.svg @@ -0,0 +1,76 @@ + +TENOR_VECTORCreated with Sketch.TENOR_VECTOR diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index dceb1c2d..01e79493 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -719,6 +719,7 @@ const defaultInstances = { 'suds': ['https://sd.vern.cc'], 'unfunny': ['https://uf.vern.cc'], 'soprano': ['https://sp.vern.cc'], + 'meme': ['https://mm.vern.cc'], 'waybackClassic': ['https://wayback-classic.net'], 'gothub': ['https://gh.odyssey346.dev'], 'mikuInvidious': ['https://mikuinv.resrv.org'], diff --git a/src/config.json b/src/config.json index cf4ed558..0b4a3ee6 100644 --- a/src/config.json +++ b/src/config.json @@ -757,6 +757,26 @@ "imageType": "svg", "url": "https://tenor.com" }, + "knowyourmeme": { + "frontends": { + "meme": { + "name": "MeMe", + "instanceList": true, + "url": "https://git.vern.cc/cobra/MeMe" + } + }, + "targets": [ + "^https?:\\/{2}(www\\.)?knowyourmeme\\.com\\/" + ], + "name": "KnowYourMeme", + "options": { + "enabled": false, + "unsupportedUrls": "bypass", + "frontend": "meme" + }, + "imageType": "svg", + "url": "https://knowyourmeme.com" + }, "urbanDictionary": { "frontends": { "ruralDictionary": { -- cgit 1.4.1 From 2a3ae7d9151dcc46545b4e70eb5f96506bdd4d30 Mon Sep 17 00:00:00 2001 From: Solomon Victorino Date: Wed, 20 Mar 2024 22:29:36 -0600 Subject: Redirect Bandcamp /music to Tent artist page --- src/assets/javascripts/services.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/assets/javascripts/services.js') diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 1a9c3f29..d63f0fab 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -415,7 +415,7 @@ function redirect(url, type, initiator, forceRedirection, incognito) { if (url.hostname.endsWith('bandcamp.com')) { const regex = /^(.*)\.bandcamp\.com/.exec(url.hostname) const artist = regex[1] - if (url.pathname == '/') { + if (url.pathname == '/' || url.pathname == '/music') { return `${randomInstance}/artist.php?name=${artist}` } else { const regex = /^\/(.*)\/(.*)/.exec(url.pathname) -- cgit 1.4.1