From beaaeb1d309555531a22e350b73ff014cccd1e16 Mon Sep 17 00:00:00 2001 From: Hygna Date: Wed, 5 Oct 2022 19:27:27 +0100 Subject: [PATCH] Added support for i.stack.imgur.com and rimgo embeds Closes https://codeberg.org/LibRedirect/libredirect/issues/18 --- src/assets/javascripts/services.js | 16 ++++++++++++++-- src/config/config.json | 10 +++++++--- src/pages/options/index.html | 10 +++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 944a6d3..98f1776 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -61,6 +61,7 @@ function regexArray(service, url, config) { } function redirect(url, type, initiator) { + if (type != "main_frame" && type != "sub_frame") return let randomInstance let frontend for (const service in config.services) { @@ -392,6 +393,9 @@ function redirect(url, type, initiator) { else wiki = "/" + wiki if (url.href.search(/Special:Search\?query/) > -1) return `${randomInstance}${wiki}${url.pathname}${url.search}`.replace(/Special:Search\?query/, "search?q").replace(/\/wiki/, "") else return `${randomInstance}${wiki}${url.pathname}${url.search}` + case "rimgo": + if (url.href.search(/^https?:\/{2}(?:[im]\.)?stack\./) > -1) return `${randomInstance}/stack${url.pathname}${url.search}` + else return `${randomInstance}${url.pathname}${url.search}` default: return `${randomInstance}${url.pathname}${url.search}` } @@ -440,8 +444,16 @@ function switchInstance(url) { for (const service in config.services) { if (!all(service, null, options, config, redirects).includes(protocolHost)) continue - let instancesList = [...options[options[service].frontend][options.network].enabled, ...options[options[service].frontend][options.network].custom] - if (instancesList.length === 0 && options.networkFallback) instancesList = [...options[options[service].frontend].clearnet.enabled, ...options[options[service].frontend].clearnet.custom] + let instancesList + if (Object.keys(config.services[service].frontends).length == 1) { + const frontend = Object.keys(config.services[service].frontends)[0] + instancesList = [...options[frontend][options.network].enabled, ...options[frontend][options.network].custom] + if (instancesList.length === 0 && options.networkFallback) instancesList = [...options[frontend].clearnet.enabled, ...options[frontend].clearnet.custom] + } else { + const frontend = options[service].frontend + instancesList = [...options[frontend][options.network].enabled, ...options[frontend][options.network].custom] + if (instancesList.length === 0 && options.networkFallback) instancesList = [...options[frontend].clearnet.enabled, ...options[frontend].clearnet.custom] + } let oldInstance const i = instancesList.indexOf(protocolHost) diff --git a/src/config/config.json b/src/config/config.json index 6119583..9716826 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -254,14 +254,18 @@ "frontends": { "rimgo": { "name": "rimgo", + "embeddable": true, "instanceList": true } }, - "targets": ["^https?:\\/{2}([im]\\.)?imgur\\.(com|io)(\\/|$)"], + "targets": ["^https?:\\/{2}([im]\\.)?(stack\\.)?imgur\\.(com|io)(\\/|$)"], "name": "Imgur", - "options": { "enabled": true }, + "options": { + "enabled": true, + "redirectType": "both" + }, "imageType": "png", - "embeddable": false, + "embeddable": true, "url": "https://imgur.com" }, "wikipedia": { diff --git a/src/pages/options/index.html b/src/pages/options/index.html index faeb512..597d7cb 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -1574,7 +1574,15 @@

Enable

-
+
+

Redirect Type

+ +
+