diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 48c0a2d..1c84eff 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -525,7 +525,7 @@ function rewrite(url, originUrl, frontend, randomInstance) { if (artReg) return `${randomInstance}/post/${artReg[1]}/${artReg[2]}${url.search}` const userReg = /^\/([^\/]+)$/.exec(url.pathname) - if (userReg)return `${randomInstance}/group_user?q=${userReg[1]}&type=about` + if (userReg) return `${randomInstance}/group_user?q=${userReg[1]}&type=about` const galleryReg = /^\/(.*?)\/gallery(\/$|$)$/.exec(url.pathname) if (galleryReg) return `${randomInstance}/group_user?q=${galleryReg[1]}&type=gallery` @@ -941,6 +941,7 @@ async function copyRaw(url) { * @param {URL} url */ function isException(url) { + if (!options) return false if (!options.exceptions) return false let exceptions = options.exceptions if (exceptions && url) { diff --git a/src/manifest.json b/src/manifest.json index 16a863f..7bb01fd 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", - "version": "2.9.1", + "version": "3.0.0", "manifest_version": 2, "browser_specific_settings": { "gecko": { diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 1fcba19..d566ff5 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -71,6 +71,7 @@ browser.webRequest.onBeforeRequest.addListener( (newUrl && newUrl.startsWith("https://no-instance.libredirect.invalid")) || (!newUrl && url.href.startsWith("https://no-instance.libredirect.invalid")) ) { + if (details.type != "main_frame") return null newUrl = newUrl ? new URL(newUrl) : url const frontend = newUrl.searchParams.get("frontend") const oldUrl = new URL(newUrl.searchParams.get("url")) @@ -85,17 +86,16 @@ browser.webRequest.onBeforeRequest.addListener( return { cancel: true } } - if (!newUrl) { - if (url.href.match(/^https?:\/{2}(.*\.)?libredirect\.invalid.*/)) { - const params = new URLSearchParams({ - message: "disabled", - url: url.href, - }) - browser.tabs.update({ - url: browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`), - }) - return { cancel: true } - } + if (!newUrl && url.href.match(/^https?:\/{2}(.*\.)?libredirect\.invalid.*/)) { + if (details.type != "main_frame") return null + const params = new URLSearchParams({ + message: "disabled", + url: url.href, + }) + browser.tabs.update({ + url: browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`), + }) + return { cancel: true } } if (newUrl === "CANCEL") { @@ -121,8 +121,9 @@ browser.webRequest.onHeadersReceived.addListener( details => { if (details.statusCode >= 501 || details.statusCode == 429 || details.statusCode == 403) { const url = new URL(details.url) - const { service, frontend } = servicesHelper.computeFrontend(url) - if (!service) return + const r = servicesHelper.computeFrontend(url) + if (!r) return + const { service, frontend } = r const params = new URLSearchParams({ message: "server_error", code: details.statusCode,