Fix regex since Fandom subdomains can contain hyphens (#37)

For example, it wouldn't redirect https://kimetsu-no-yaiba.fandom.com/wiki/Kimetsu_no_Yaiba_Wiki, now it would

Reviewed-on: https://codeberg.org/LibRedirect/libredirect/pulls/37
Co-authored-by: Austin Huang <im@austinhuang.me>
Co-committed-by: Austin Huang <im@austinhuang.me>
This commit is contained in:
Austin Huang 2022-10-10 04:32:20 +02:00 committed by Edward
parent ac4c89de78
commit 91d420b460
2 changed files with 2 additions and 2 deletions

View File

@ -393,7 +393,7 @@ function redirect(url, type, initiator, forceRedirection) {
}
return randomInstance
case "breezeWiki":
let wiki = url.hostname.match(/^[a-zA-Z0-9]+(?=\.fandom\.com)/)
let wiki = url.hostname.match(/^[a-zA-Z0-9-]+(?=\.fandom\.com)/)
if (wiki == "www" || !wiki) wiki = ""
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/, "")

View File

@ -456,7 +456,7 @@
}
},
"targets": [
"^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"
"^https?:\\/{2}(?:[a-zA-Z0-9-]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"
],
"name": "Fandom",
"options": {