Added a option for unsupported links https://github.com/libredirect/libredirect/issues/575
This commit is contained in:
parent
b91ae8e816
commit
c5184b277f
|
@ -49,8 +49,6 @@ function redirect(url, type, initiator, forceRedirection) {
|
||||||
let frontend
|
let frontend
|
||||||
for (const service in config.services) {
|
for (const service in config.services) {
|
||||||
if (!forceRedirection && !options[service].enabled) continue
|
if (!forceRedirection && !options[service].enabled) continue
|
||||||
if (config.services[service].embeddable && type != options[service].redirectType && options[service].redirectType != "both") continue
|
|
||||||
if (!config.services[service].embeddable && type != "main_frame") continue
|
|
||||||
|
|
||||||
frontend = options[service].frontend ?? Object.keys(config.services[service].frontends)[0]
|
frontend = options[service].frontend ?? Object.keys(config.services[service].frontends)[0]
|
||||||
|
|
||||||
|
@ -59,6 +57,15 @@ function redirect(url, type, initiator, forceRedirection) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(config.services[service].embeddable && type != options[service].redirectType && options[service].redirectType != "both")
|
||||||
|
||
|
||||||
|
(!config.services[service].embeddable && type != "main_frame")
|
||||||
|
) {
|
||||||
|
if (options[service].unsupportedUrls == 'block') return 'CANCEL'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let instanceList = options[frontend]
|
let instanceList = options[frontend]
|
||||||
if (instanceList === undefined) break
|
if (instanceList === undefined) break
|
||||||
if (instanceList.length === 0) return
|
if (instanceList.length === 0) return
|
||||||
|
@ -390,12 +397,16 @@ function redirect(url, type, initiator, forceRedirection) {
|
||||||
urlpath = url.pathname.match(/(?<=wiki\/w:c:[a-zA-Z0-9-]+:).+/)
|
urlpath = url.pathname.match(/(?<=wiki\/w:c:[a-zA-Z0-9-]+:).+/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (url.href.search(/Special:Search\?query/) > -1) return `${randomInstance}${wiki}${urlpath}${url.search}`.replace(/Special:Search\?query/, "search?q").replace(/\/wiki/, "")
|
if (url.href.search(/Special:Search\?query/) > -1) {
|
||||||
else return `${randomInstance}${wiki}${urlpath}${url.search}`
|
return `${randomInstance}${wiki}${urlpath}${url.search}`.replace(/Special:Search\?query/, "search?q").replace(/\/wiki/, "")
|
||||||
|
}
|
||||||
|
return `${randomInstance}${wiki}${urlpath}${url.search}`
|
||||||
}
|
}
|
||||||
case "rimgo": {
|
case "rimgo": {
|
||||||
if (url.href.search(/^https?:\/{2}(?:[im]\.)?stack\./) > -1) return `${randomInstance}/stack${url.pathname}${url.search}`
|
if (url.href.search(/^https?:\/{2}(?:[im]\.)?stack\./) > -1) {
|
||||||
else return `${randomInstance}${url.pathname}${url.search}`
|
return `${randomInstance}/stack${url.pathname}${url.search}`
|
||||||
|
}
|
||||||
|
return `${randomInstance}${url.pathname}${url.search}`
|
||||||
}
|
}
|
||||||
case "libreddit": {
|
case "libreddit": {
|
||||||
const subdomain = url.hostname.match(/^(?:(?:external-)?preview|i)(?=\.redd\.it)/)
|
const subdomain = url.hostname.match(/^(?:(?:external-)?preview|i)(?=\.redd\.it)/)
|
||||||
|
@ -408,6 +419,7 @@ function redirect(url, type, initiator, forceRedirection) {
|
||||||
case "i":
|
case "i":
|
||||||
return `${randomInstance}/img${url.pathname}`
|
return `${randomInstance}/img${url.pathname}`
|
||||||
}
|
}
|
||||||
|
return randomInstance
|
||||||
}
|
}
|
||||||
case "teddit": {
|
case "teddit": {
|
||||||
if (/^(?:(?:external-)?preview|i)\.redd\.it/.test(url.hostname)) {
|
if (/^(?:(?:external-)?preview|i)\.redd\.it/.test(url.hostname)) {
|
||||||
|
@ -424,7 +436,9 @@ function redirect(url, type, initiator, forceRedirection) {
|
||||||
return `${randomInstance}${p}`
|
return `${randomInstance}${p}`
|
||||||
}
|
}
|
||||||
case "dumb": {
|
case "dumb": {
|
||||||
if (url.pathname.endsWith('-lyrics')) return `${randomInstance}${url.pathname}`
|
if (url.pathname.endsWith('-lyrics')) {
|
||||||
|
return `${randomInstance}${url.pathname}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case "ruralDictionary": {
|
case "ruralDictionary": {
|
||||||
if (!url.pathname.includes('/define.php') && !url.pathname.includes('/random.php') && url.pathname != '/') return
|
if (!url.pathname.includes('/define.php') && !url.pathname.includes('/random.php') && url.pathname != '/') return
|
||||||
|
@ -632,11 +646,16 @@ function initDefaults() {
|
||||||
function upgradeOptions() {
|
function upgradeOptions() {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const oldOptions = await utils.getOptions()
|
const oldOptions = await utils.getOptions()
|
||||||
|
const config = await utils.getConfig()
|
||||||
|
|
||||||
let options = {}
|
let options = {}
|
||||||
options = [...oldOptions]
|
options = [...oldOptions]
|
||||||
options.fetchInstances = 'github'
|
options.fetchInstances = 'github'
|
||||||
|
|
||||||
|
for (service in config.services) {
|
||||||
|
options[service].unsupportedUrls = 'bypass'
|
||||||
|
}
|
||||||
|
|
||||||
browser.storage.local.clear(() => {
|
browser.storage.local.clear(() => {
|
||||||
browser.storage.local.set({ options }, () => {
|
browser.storage.local.set({ options }, () => {
|
||||||
resolve()
|
resolve()
|
||||||
|
|
|
@ -96,7 +96,8 @@
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"redirectType": "main_frame",
|
"redirectType": "main_frame",
|
||||||
"frontend": "invidious"
|
"frontend": "invidious",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": true,
|
"embeddable": true,
|
||||||
|
@ -121,7 +122,8 @@
|
||||||
"name": "YT Music",
|
"name": "YT Music",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"frontend": "beatbump"
|
"frontend": "beatbump",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -145,7 +147,8 @@
|
||||||
"name": "Twitter",
|
"name": "Twitter",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"redirectType": "main_frame"
|
"redirectType": "main_frame",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": true,
|
"embeddable": true,
|
||||||
|
@ -164,7 +167,8 @@
|
||||||
],
|
],
|
||||||
"name": "TikTok",
|
"name": "TikTok",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -190,7 +194,8 @@
|
||||||
"name": "Reddit",
|
"name": "Reddit",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"frontend": "libreddit"
|
"frontend": "libreddit",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -210,7 +215,8 @@
|
||||||
"name": "Imgur",
|
"name": "Imgur",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"redirectType": "main_frame"
|
"redirectType": "main_frame",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": true,
|
"embeddable": true,
|
||||||
|
@ -253,7 +259,8 @@
|
||||||
"name": "Medium",
|
"name": "Medium",
|
||||||
"options": {
|
"options": {
|
||||||
"frontend": "scribe",
|
"frontend": "scribe",
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -272,7 +279,8 @@
|
||||||
],
|
],
|
||||||
"name": "Quora",
|
"name": "Quora",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -291,7 +299,8 @@
|
||||||
],
|
],
|
||||||
"name": "IMDb",
|
"name": "IMDb",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -310,7 +319,8 @@
|
||||||
],
|
],
|
||||||
"name": "Fandom",
|
"name": "Fandom",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -339,7 +349,8 @@
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"frontend": "librarian",
|
"frontend": "librarian",
|
||||||
"redirectType": "main_frame"
|
"redirectType": "main_frame",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": true,
|
"embeddable": true,
|
||||||
|
@ -374,7 +385,8 @@
|
||||||
"name": "Search",
|
"name": "Search",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"frontend": "searxng"
|
"frontend": "searxng",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -405,7 +417,8 @@
|
||||||
"name": "Translate",
|
"name": "Translate",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"frontend": "simplyTranslate"
|
"frontend": "simplyTranslate",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -431,7 +444,8 @@
|
||||||
"name": "Maps",
|
"name": "Maps",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"frontend": "osm"
|
"frontend": "osm",
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -452,7 +466,8 @@
|
||||||
],
|
],
|
||||||
"name": "Send Files",
|
"name": "Send Files",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -471,7 +486,8 @@
|
||||||
],
|
],
|
||||||
"name": "Paste Text",
|
"name": "Paste Text",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -490,7 +506,8 @@
|
||||||
],
|
],
|
||||||
"name": "Reuters",
|
"name": "Reuters",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -509,7 +526,8 @@
|
||||||
],
|
],
|
||||||
"name": "Genius",
|
"name": "Genius",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -528,7 +546,8 @@
|
||||||
],
|
],
|
||||||
"name": "Urban Dictionary",
|
"name": "Urban Dictionary",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -547,7 +566,8 @@
|
||||||
],
|
],
|
||||||
"name": "Stack Overflow",
|
"name": "Stack Overflow",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -566,7 +586,8 @@
|
||||||
],
|
],
|
||||||
"name": "Goodreads",
|
"name": "Goodreads",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -585,7 +606,8 @@
|
||||||
],
|
],
|
||||||
"name": "Wikipedia",
|
"name": "Wikipedia",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -604,7 +626,8 @@
|
||||||
],
|
],
|
||||||
"name": "Snopes",
|
"name": "Snopes",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false
|
"enabled": false,
|
||||||
|
"unsupportedUrls": "bypass"
|
||||||
},
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
|
|
@ -34,6 +34,11 @@ each val, service in services
|
||||||
option(value="sub_frame" data-localise="__MSG_onlyEmbedded__") Only Embedded
|
option(value="sub_frame" data-localise="__MSG_onlyEmbedded__") Only Embedded
|
||||||
option(value="main_frame" data-localise="__MSG_onlyNotEmbedded__") Only Not Embedded
|
option(value="main_frame" data-localise="__MSG_onlyNotEmbedded__") Only Not Embedded
|
||||||
|
|
||||||
|
div(class="some-block option-block")
|
||||||
|
h4 Unsupported paths handling
|
||||||
|
select(id=service+"-unsupportedUrls")
|
||||||
|
option(value="bypass") bypass
|
||||||
|
option(value="block") block
|
||||||
hr
|
hr
|
||||||
|
|
||||||
each val, frontend in services[service].frontends
|
each val, frontend in services[service].frontends
|
||||||
|
|
Loading…
Reference in New Issue