Disabled onlyEmbed redirection if documentUrl is the actual target https://codeberg.org/LibRedirect/browser_extension/issues/127
This commit is contained in:
parent
3c3cc17ea4
commit
b4575df159
|
@ -52,12 +52,12 @@ function regexArray(service, url, config, options, frontend) {
|
||||||
/**
|
/**
|
||||||
* @param {URL} url
|
* @param {URL} url
|
||||||
* @param {string} type
|
* @param {string} type
|
||||||
* @param {URL} initiator
|
* @param {URL} originUrl
|
||||||
* @param {boolean} forceRedirection
|
* @param {boolean} forceRedirection
|
||||||
*/
|
*/
|
||||||
async function redirectAsync(url, type, initiator, forceRedirection) {
|
async function redirectAsync(url, type, originUrl, documentUrl, forceRedirection) {
|
||||||
await init()
|
await init()
|
||||||
return redirect(url, type, initiator, forceRedirection)
|
return redirect(url, type, originUrl, documentUrl, forceRedirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,7 +171,7 @@ function rewrite(url, frontend, randomInstance) {
|
||||||
return new URLSearchParams(prefs).toString()
|
return new URLSearchParams(prefs).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initiator && initiator.host === "earth.google.com") return randomInstance
|
if (originUrl && originUrl.host === "earth.google.com") return randomInstance
|
||||||
|
|
||||||
let mapCentre = "#"
|
let mapCentre = "#"
|
||||||
let prefs = { layers: "mapnik" }
|
let prefs = { layers: "mapnik" }
|
||||||
|
@ -595,11 +595,11 @@ function rewrite(url, frontend, randomInstance) {
|
||||||
/**
|
/**
|
||||||
* @param {URL} url
|
* @param {URL} url
|
||||||
* @param {string} type
|
* @param {string} type
|
||||||
* @param {URL} initiator
|
* @param {URL} originUrl
|
||||||
* @param {boolean} forceRedirection
|
* @param {boolean} forceRedirection
|
||||||
* @returns {string | undefined}
|
* @returns {string | undefined}
|
||||||
*/
|
*/
|
||||||
function redirect(url, type, initiator, forceRedirection, incognito) {
|
function redirect(url, type, originUrl, documentUrl, forceRedirection, incognito) {
|
||||||
if (type != "main_frame" && type != "sub_frame" && type != "image") return
|
if (type != "main_frame" && type != "sub_frame" && type != "image") return
|
||||||
let randomInstance
|
let randomInstance
|
||||||
let frontend
|
let frontend
|
||||||
|
@ -623,6 +623,12 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type != "main_frame" && documentUrl && options[service].redirectType == "sub_frame") {
|
||||||
|
if (regexArray(service, documentUrl, config, options, frontend)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
config.services[service].embeddable &&
|
config.services[service].embeddable &&
|
||||||
type != options[service].redirectType &&
|
type != options[service].redirectType &&
|
||||||
|
@ -636,7 +642,7 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
|
||||||
if (instanceList === undefined) break
|
if (instanceList === undefined) break
|
||||||
if (instanceList.length === 0) return null
|
if (instanceList.length === 0) return null
|
||||||
|
|
||||||
if (initiator && instanceList.includes(initiator.origin)) {
|
if (originUrl && instanceList.includes(originUrl.origin)) {
|
||||||
if (type != "main_frame") return null
|
if (type != "main_frame") return null
|
||||||
else return "BYPASSTAB"
|
else return "BYPASSTAB"
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,15 +28,17 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
const old_href = url.href
|
const old_href = url.href
|
||||||
if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest")
|
if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest")
|
||||||
return
|
return
|
||||||
let initiator
|
let originUrl
|
||||||
try {
|
try {
|
||||||
if (details.originUrl) initiator = new URL(details.originUrl)
|
if (details.originUrl) originUrl = new URL(details.originUrl)
|
||||||
else if (details.initiator && details.initiator !== "null") initiator = new URL(details.initiator)
|
|
||||||
} catch {
|
} catch {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
let documentUrl
|
||||||
|
try { if (details.documentUrl) documentUrl = new URL(details.documentUrl) }
|
||||||
|
catch (error) { return null }
|
||||||
if (tabIdRedirects[details.tabId] == false) return null
|
if (tabIdRedirects[details.tabId] == false) return null
|
||||||
let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId], details.incognito)
|
let newUrl = servicesHelper.redirect(url, details.type, originUrl, documentUrl, tabIdRedirects[details.tabId], details.incognito)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
details.frameAncestors &&
|
details.frameAncestors &&
|
||||||
|
@ -103,7 +105,7 @@ browser.runtime.getPlatformInfo(r => {
|
||||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
||||||
if (tabs[0].url) {
|
if (tabs[0].url) {
|
||||||
const url = new URL(tabs[0].url)
|
const url = new URL(tabs[0].url)
|
||||||
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
|
const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
||||||
tabIdRedirects[tabs[0].id] = true
|
tabIdRedirects[tabs[0].id] = true
|
||||||
|
@ -209,7 +211,7 @@ browser.runtime.getPlatformInfo(r => {
|
||||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
||||||
if (tabs[0].url) {
|
if (tabs[0].url) {
|
||||||
const url = new URL(tabs[0].url)
|
const url = new URL(tabs[0].url)
|
||||||
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
|
const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
||||||
tabIdRedirects[tabs[0].id] = true
|
tabIdRedirects[tabs[0].id] = true
|
||||||
|
@ -226,7 +228,7 @@ browser.runtime.getPlatformInfo(r => {
|
||||||
case "redirectLink":
|
case "redirectLink":
|
||||||
case "redirectLinkInNewTab": {
|
case "redirectLinkInNewTab": {
|
||||||
const url = new URL(info.linkUrl)
|
const url = new URL(info.linkUrl)
|
||||||
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
|
const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
if (info.menuItemId == "redirectLink") browser.tabs.update({ url: newUrl })
|
if (info.menuItemId == "redirectLink") browser.tabs.update({ url: newUrl })
|
||||||
else browser.tabs.create({ url: newUrl })
|
else browser.tabs.create({ url: newUrl })
|
||||||
|
@ -274,7 +276,7 @@ browser.runtime.getPlatformInfo(r => {
|
||||||
case "redirectBookmarkInNewTab":
|
case "redirectBookmarkInNewTab":
|
||||||
browser.bookmarks.get(info.bookmarkId, bookmarks => {
|
browser.bookmarks.get(info.bookmarkId, bookmarks => {
|
||||||
const url = new URL(bookmarks[0].url)
|
const url = new URL(bookmarks[0].url)
|
||||||
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
|
const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
if (info.menuItemId == "redirectBookmark") browser.tabs.update({ url: newUrl })
|
if (info.menuItemId == "redirectBookmark") browser.tabs.update({ url: newUrl })
|
||||||
else browser.tabs.create({ url: newUrl })
|
else browser.tabs.create({ url: newUrl })
|
||||||
|
@ -328,7 +330,7 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
||||||
if (tabs[0].url) {
|
if (tabs[0].url) {
|
||||||
const url = new URL(tabs[0].url)
|
const url = new URL(tabs[0].url)
|
||||||
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
|
const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
|
||||||
if (newUrl) browser.tabs.update(tabs[0].id, { url: newUrl }, () => (tabIdRedirects[tabs[0].id] = true))
|
if (newUrl) browser.tabs.update(tabs[0].id, { url: newUrl }, () => (tabIdRedirects[tabs[0].id] = true))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue