Renamed Unsupported paths handling => Unsupported iframes handling https://github.com/libredirect/browser_extension/issues/648

This commit is contained in:
ManeraKai 2023-05-30 11:33:56 +03:00
parent 7ff510a1f1
commit d813226928
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 12 additions and 55 deletions

View File

@ -74,7 +74,7 @@ function redirect(url, type, initiator, forceRedirection) {
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 null
if ( if (
initiator initiator
@ -86,7 +86,6 @@ function redirect(url, type, initiator, forceRedirection) {
if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") { if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") {
randomInstance = `http://${frontend}.localhost:8080` randomInstance = `http://${frontend}.localhost:8080`
} }
break break
} }
@ -109,7 +108,6 @@ function redirect(url, type, initiator, forceRedirection) {
if (!frontend) return if (!frontend) return
switch (frontend) { switch (frontend) {
// This is where all instance-specific code must be ran to convert the service url to one that can be understood by the frontend.
case "beatbump": { case "beatbump": {
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
.replace("/watch?v=", "/listen?id=") .replace("/watch?v=", "/listen?id=")
@ -155,7 +153,6 @@ function redirect(url, type, initiator, forceRedirection) {
return `${randomInstance}/pic${url.pathname}${search}` return `${randomInstance}/pic${url.pathname}${search}`
} }
} }
if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${search}` if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${search}`
if (url.host == "t.co") return `${randomInstance}/t.co${url.pathname}` if (url.host == "t.co") return `${randomInstance}/t.co${url.pathname}`
return `${randomInstance}${url.pathname}${search}#m` return `${randomInstance}${url.pathname}${search}#m`
@ -166,19 +163,7 @@ function redirect(url, type, initiator, forceRedirection) {
case "freetube": { case "freetube": {
return `freetube://https://youtu.be${url.pathname}${url.search}`.replace(/watch\?v=/, "") return `freetube://https://youtu.be${url.pathname}${url.search}`.replace(/watch\?v=/, "")
} }
case "invidious":
case "piped":
case "pipedMaterial":
case "cloudtube": {
if (url.pathname.startsWith("/live_chat")) {
return null;
}
return `${randomInstance}${url.pathname}${url.search}`;
}
case "poketube": { case "poketube": {
if (url.pathname.startsWith("/live_chat")) {
return null;
}
if (url.pathname.startsWith('/channel')) { if (url.pathname.startsWith('/channel')) {
const reg = /\/channel\/(.*)\/?$/.exec(url.pathname) const reg = /\/channel\/(.*)\/?$/.exec(url.pathname)
if (reg) { if (reg) {
@ -186,9 +171,7 @@ function redirect(url, type, initiator, forceRedirection) {
return `${randomInstance}/channel?id=${id}${url.search}` return `${randomInstance}/channel?id=${id}${url.search}`
} }
} }
if (/\/@[a-z]+\//.exec(url.pathname)) { if (/\/@[a-z]+\//.exec(url.pathname)) return randomInstance
return randomInstance
}
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
} }
case "libMedium": case "libMedium":
@ -226,7 +209,7 @@ function redirect(url, type, initiator, forceRedirection) {
return randomInstance return randomInstance
} }
case "osm": { case "osm": {
if (initiator && initiator.host === "earth.google.com") return if (initiator && initiator.host === "earth.google.com") return randomInstance
const travelModes = { const travelModes = {
driving: "fossgis_osrm_car", driving: "fossgis_osrm_car",
walking: "fossgis_osrm_foot", walking: "fossgis_osrm_foot",
@ -236,13 +219,6 @@ function redirect(url, type, initiator, forceRedirection) {
function addressToLatLng(address) { function addressToLatLng(address) {
const xmlhttp = new XMLHttpRequest() const xmlhttp = new XMLHttpRequest()
xmlhttp.timeout = 5000
http.ontimeout = () => {
return
}
http.onerror = () => {
return
}
xmlhttp.send() xmlhttp.send()
http.onreadystatechange = () => { http.onreadystatechange = () => {
if (xmlhttp.status === 200) { if (xmlhttp.status === 200) {
@ -266,8 +242,6 @@ function redirect(url, type, initiator, forceRedirection) {
if (url.pathname.includes("/embed")) { if (url.pathname.includes("/embed")) {
// Handle Google Maps Embed API // Handle Google Maps Embed API
// https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Eiffel+Tower,Paris+France // https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Eiffel+Tower,Paris+France
//console.log("embed life")
let query = "" let query = ""
if (url.searchParams.has("q")) query = url.searchParams.get("q") if (url.searchParams.has("q")) query = url.searchParams.get("q")
else if (url.searchParams.has("query")) query = url.searchParams.has("query") else if (url.searchParams.has("query")) query = url.searchParams.has("query")
@ -303,16 +277,12 @@ function redirect(url, type, initiator, forceRedirection) {
} else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { } else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) {
// Get marker from data attribute // Get marker from data attribute
// https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948 // https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948
//console.log("data life")
let [, mlat, mlon] = url.pathname.match(dataLatLngRegex) let [, mlat, mlon] = url.pathname.match(dataLatLngRegex)
return `${randomInstance}/search?query=${mlat}%2C${mlon}` return `${randomInstance}/search?query=${mlat}%2C${mlon}`
} else if (url.searchParams.has("ll")) { } else if (url.searchParams.has("ll")) {
// Get marker from ll param // Get marker from ll param
// https://maps.google.com/?ll=38.882147,-76.99017 // https://maps.google.com/?ll=38.882147,-76.99017
//console.log("ll life")
const [mlat, mlon] = url.searchParams.get("ll").split(",") const [mlat, mlon] = url.searchParams.get("ll").split(",")
return `${randomInstance}/search?query=${mlat}%2C${mlon}` return `${randomInstance}/search?query=${mlat}%2C${mlon}`
@ -344,7 +314,7 @@ function redirect(url, type, initiator, forceRedirection) {
return `${randomInstance}/${mapCentre}&${prefsEncoded}` return `${randomInstance}/${mapCentre}&${prefsEncoded}`
} }
case "facil": { case "facil": {
if (initiator && initiator.host === "earth.google.com") return if (initiator && initiator.host === "earth.google.com") return randomInstance
const travelModes = { const travelModes = {
driving: "car", driving: "car",
walking: "pedestrian", walking: "pedestrian",
@ -384,36 +354,25 @@ function redirect(url, type, initiator, forceRedirection) {
} else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { } else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) {
// Get marker from data attribute // Get marker from data attribute
// https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948 // https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948
//console.log("data life")
let [, mlat, mlon] = url.pathname.match(dataLatLngRegex) let [, mlat, mlon] = url.pathname.match(dataLatLngRegex)
return `${randomInstance}/#q=${mlat}%2C${mlon}` return `${randomInstance}/#q=${mlat}%2C${mlon}`
} else if (url.searchParams.has("ll")) { } else if (url.searchParams.has("ll")) {
// Get marker from ll param // Get marker from ll param
// https://maps.google.com/?ll=38.882147,-76.99017 // https://maps.google.com/?ll=38.882147,-76.99017
//console.log("ll life")
const [mlat, mlon] = url.searchParams.get("ll").split(",") const [mlat, mlon] = url.searchParams.get("ll").split(",")
return `${randomInstance}/#q=${mlat}%2C${mlon}` return `${randomInstance}/#q=${mlat}%2C${mlon}`
} else if (url.searchParams.has("viewpoint")) { } else if (url.searchParams.has("viewpoint")) {
// Get marker from viewpoint param. // Get marker from viewpoint param
// https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80 // https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80
//console.log("viewpoint life")
const [mlat, mlon] = url.searchParams.get("viewpoint").split(",") const [mlat, mlon] = url.searchParams.get("viewpoint").split(",")
return `${randomInstance}/#q=${mlat}%2C${mlon}` return `${randomInstance}/#q=${mlat}%2C${mlon}`
} else { } else {
// Use query as search if present. // Use query as search if present.
//console.log("normal life")
let query let query
if (url.searchParams.has("q")) query = url.searchParams.get("q") if (url.searchParams.has("q")) query = url.searchParams.get("q")
else if (url.searchParams.has("query")) query = url.searchParams.get("query") else if (url.searchParams.has("query")) query = url.searchParams.get("query")
else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1] else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1]
if (query) return `${randomInstance}/${mapCentre}/Mpnk/${query}` if (query) return `${randomInstance}/${mapCentre}/Mpnk/${query}`
} }
} }
@ -466,7 +425,7 @@ function redirect(url, type, initiator, forceRedirection) {
case "neuters": { case "neuters": {
const p = url.pathname const p = url.pathname
if (p.startsWith('/article/') || p.startsWith('/pf/') || p.startsWith('/arc/') || p.startsWith('/resizer/')) { if (p.startsWith('/article/') || p.startsWith('/pf/') || p.startsWith('/arc/') || p.startsWith('/resizer/')) {
return null return randomInstance
} }
return `${randomInstance}${p}` return `${randomInstance}${p}`
} }
@ -476,11 +435,11 @@ function redirect(url, type, initiator, forceRedirection) {
} }
} }
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 randomInstance
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
} }
case "anonymousOverflow": { case "anonymousOverflow": {
if (!url.pathname.startsWith('/questions') && url.pathname != '/') return if (!url.pathname.startsWith('/questions') && url.pathname != '/') return randomInstance
if (url.hostname == "stackoverflow.com") { if (url.hostname == "stackoverflow.com") {
const threadID = /\/(\d+)\/?$/.exec(url.pathname) const threadID = /\/(\d+)\/?$/.exec(url.pathname)
if (threadID) return `${randomInstance}/questions/${threadID[1]}${url.search}` if (threadID) return `${randomInstance}/questions/${threadID[1]}${url.search}`
@ -493,7 +452,7 @@ function redirect(url, type, initiator, forceRedirection) {
} }
} }
case "biblioReads": { case "biblioReads": {
if (!url.pathname.startsWith('/book/show/') && url.pathname != '/') return if (!url.pathname.startsWith('/book/show/') && url.pathname != '/') return randomInstance
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
} }
case "wikiless": { case "wikiless": {
@ -507,7 +466,7 @@ function redirect(url, type, initiator, forceRedirection) {
return `${randomInstance}${url.pathname}${GETArguments.toString()}${url.hash}` return `${randomInstance}${url.pathname}${GETArguments.toString()}${url.hash}`
} }
case "proxiTok": { case "proxiTok": {
if (url.pathname.startsWith('/email')) return if (url.pathname.startsWith('/email')) return randomInstance
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
} }
case "waybackClassic": { case "waybackClassic": {
@ -575,10 +534,8 @@ function redirect(url, type, initiator, forceRedirection) {
} }
} }
case "binternet": { case "binternet": {
console.log("binternet", url.href)
if (url.hostname == "i.pinimg.com") return `${randomInstance}/image_proxy.php?url=${url.href}` if (url.hostname == "i.pinimg.com") return `${randomInstance}/image_proxy.php?url=${url.href}`
if (url.href.endsWith("pinterest.com/")) return randomInstance return randomInstance
return null
} }
default: { default: {
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`

View File

@ -35,7 +35,7 @@ each val, service in services
select(id=service+"-redirectType") select(id=service+"-redirectType")
div(class="some-block option-block") div(class="some-block option-block")
h4 Unsupported paths handling h4 Unsupported iframes handling
select(id=service+"-unsupportedUrls") select(id=service+"-unsupportedUrls")
option(value="bypass") bypass option(value="bypass") bypass
option(value="block") block option(value="block") block