Triggering AutoRedirect on Unknown Host and other Internet connectivity errors #127
This commit is contained in:
parent
75910e13ea
commit
1079e64f0d
@ -97,7 +97,7 @@ function isImgur(url, initiator) {
|
|||||||
initiator &&
|
initiator &&
|
||||||
([...redirects.rimgo.normal, ...rimgoNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))
|
([...redirects.rimgo.normal, ...rimgoNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))
|
||||||
) return false;
|
) return false;
|
||||||
return targets.some((rx) => rx.test(url.href));
|
return targets.some(rx => rx.test(url.href));
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect(url, type) {
|
function redirect(url, type) {
|
||||||
|
@ -123,7 +123,7 @@ function redirect(url, type, initiator) {
|
|||||||
|
|
||||||
if (initiator && ([...redirects.scribe.normal, ...scribeNormalCustomRedirects].includes(initiator.origin))) return;
|
if (initiator && ([...redirects.scribe.normal, ...scribeNormalCustomRedirects].includes(initiator.origin))) return;
|
||||||
|
|
||||||
if (!targets.some((rx) => rx.test(url.host))) return;
|
if (!targets.some(rx => rx.test(url.host))) return;
|
||||||
|
|
||||||
let instancesList;
|
let instancesList;
|
||||||
if (protocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects];
|
if (protocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects];
|
||||||
|
@ -99,7 +99,7 @@ function redirect(url, type, initiator) {
|
|||||||
|
|
||||||
if (disable) return null;
|
if (disable) return null;
|
||||||
if (initiator && ([...redirects.pixivMoe.normal, ...pixivMoeNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
|
if (initiator && ([...redirects.pixivMoe.normal, ...pixivMoeNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return null;
|
if (!targets.some(rx => rx.test(url.href))) return null;
|
||||||
console.log("PixivMoe!!");
|
console.log("PixivMoe!!");
|
||||||
|
|
||||||
if (type != "main_frame" && type != "sub_frame") return null;
|
if (type != "main_frame" && type != "sub_frame") return null;
|
||||||
|
@ -282,7 +282,7 @@ function redirect(url, type, initiator) {
|
|||||||
(isTeddit || isLibreddit) && !isCheckedLibreddit
|
(isTeddit || isLibreddit) && !isCheckedLibreddit
|
||||||
) return switchInstance(url);
|
) return switchInstance(url);
|
||||||
|
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return null;
|
if (!targets.some(rx => rx.test(url.href))) return null;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
bypassWatchOnReddit &&
|
bypassWatchOnReddit &&
|
||||||
|
@ -234,7 +234,7 @@ function initWhoogleCookies() {
|
|||||||
|
|
||||||
function redirect(url) {
|
function redirect(url) {
|
||||||
if (disable) return;
|
if (disable) return;
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return;
|
if (!targets.some(rx => rx.test(url.href))) return;
|
||||||
if (url.searchParams.has('tbm')) return;
|
if (url.searchParams.has('tbm')) return;
|
||||||
|
|
||||||
if (!url.searchParams.has('q') && url.pathname != '/') return;
|
if (!url.searchParams.has('q') && url.pathname != '/') return;
|
||||||
|
@ -138,7 +138,7 @@ function redirect(url, type, initiator) {
|
|||||||
|
|
||||||
if (disable) return null;
|
if (disable) return null;
|
||||||
if (initiator && ([...redirects.send.normal, ...sendNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
|
if (initiator && ([...redirects.send.normal, ...sendNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return null;
|
if (!targets.some(rx => rx.test(url.href))) return null;
|
||||||
|
|
||||||
if (type != "main_frame") return null;
|
if (type != "main_frame") return null;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ function switchInstance(url) {
|
|||||||
function redirect(url, type, initiator) {
|
function redirect(url, type, initiator) {
|
||||||
if (disable) return null;
|
if (disable) return null;
|
||||||
if (initiator && ([...redirects.soju.normal, ...sojuNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
|
if (initiator && ([...redirects.soju.normal, ...sojuNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return null;
|
if (!targets.some(rx => rx.test(url.href))) return null;
|
||||||
|
|
||||||
if (type != "main_frame") return null;
|
if (type != "main_frame") return null;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ function setProtocol(val) {
|
|||||||
function isTiktok(url, initiator) {
|
function isTiktok(url, initiator) {
|
||||||
if (disable) return false;
|
if (disable) return false;
|
||||||
if (initiator && ([...redirects.proxiTok.normal, ...proxiTokNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return false;
|
if (initiator && ([...redirects.proxiTok.normal, ...proxiTokNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return false;
|
||||||
return targets.some((rx) => rx.test(url.href));
|
return targets.some(rx => rx.test(url.href));
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect(url, type) {
|
function redirect(url, type) {
|
||||||
|
@ -120,7 +120,7 @@ function redirect(url, initiator) {
|
|||||||
|
|
||||||
if (disable) return null;
|
if (disable) return null;
|
||||||
|
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return null;
|
if (!targets.some(rx => rx.test(url.href))) return null;
|
||||||
|
|
||||||
if (url.pathname.split("/").includes("home")) {
|
if (url.pathname.split("/").includes("home")) {
|
||||||
console.log("twitter homepage");
|
console.log("twitter homepage");
|
||||||
|
@ -354,7 +354,7 @@ function redirect(url, details, initiator) {
|
|||||||
(isInvidious || isPiped) && !isCheckedPiped
|
(isInvidious || isPiped) && !isCheckedPiped
|
||||||
) return switchInstance(url);
|
) return switchInstance(url);
|
||||||
|
|
||||||
if (!targets.some((rx) => rx.test(url.href))) return null;
|
if (!targets.some(rx => rx.test(url.href))) return null;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
details.type != "main_frame" &&
|
details.type != "main_frame" &&
|
||||||
|
@ -58,7 +58,7 @@ function setDisable(val) {
|
|||||||
|
|
||||||
function isYoutubeMusic(url, initiator) {
|
function isYoutubeMusic(url, initiator) {
|
||||||
if (disable) return false
|
if (disable) return false
|
||||||
return targets.some((rx) => rx.test(url.href));
|
return targets.some(rx => rx.test(url.href));
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect(url, type) {
|
function redirect(url, type) {
|
||||||
|
@ -131,6 +131,35 @@ browser.tabs.onRemoved.addListener(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function redirectOfflineInstance(url, tabId) {
|
||||||
|
let newUrl;
|
||||||
|
|
||||||
|
newUrl = youtubeHelper.switchInstance(url);
|
||||||
|
if (!newUrl) newUrl = twitterHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = instagramHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = redditHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = searchHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = translateHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = mediumHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = imgurHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = wikipediaHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = peertubeHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = lbryHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (!newUrl) newUrl = spotifyHelper.switchInstance(url);
|
||||||
|
|
||||||
|
if (newUrl) browser.tabs.update(tabId, { url: `/pages/errors/instance_offline.html?url=${encodeURIComponent(newUrl)}` });
|
||||||
|
}
|
||||||
|
|
||||||
browser.webRequest.onResponseStarted.addListener(
|
browser.webRequest.onResponseStarted.addListener(
|
||||||
details => {
|
details => {
|
||||||
if (!generalHelper.getAutoRedirect()) return null;
|
if (!generalHelper.getAutoRedirect()) return null;
|
||||||
@ -140,38 +169,21 @@ browser.webRequest.onResponseStarted.addListener(
|
|||||||
console.log("statusCode", details.statusCode);
|
console.log("statusCode", details.statusCode);
|
||||||
|
|
||||||
const url = new URL(details.url);
|
const url = new URL(details.url);
|
||||||
let newUrl;
|
redirectOfflineInstance(url, details.tabId);
|
||||||
|
|
||||||
newUrl = youtubeHelper.switchInstance(url);
|
|
||||||
if (!newUrl) newUrl = twitterHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = instagramHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = redditHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = searchHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = translateHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = mediumHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = imgurHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = wikipediaHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = peertubeHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = lbryHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (!newUrl) newUrl = spotifyHelper.switchInstance(url);
|
|
||||||
|
|
||||||
if (newUrl) browser.tabs.update(details.tabId, { url: `/pages/errors/instance_offline.html?url=${encodeURIComponent(newUrl)}` });
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ urls: ["<all_urls>"], }
|
{ urls: ["<all_urls>"], }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
browser.webRequest.onErrorOccurred.addListener(
|
||||||
|
details => {
|
||||||
|
if (!generalHelper.getAutoRedirect()) return;
|
||||||
|
const url = new URL(details.url);
|
||||||
|
redirectOfflineInstance(url, details.tabId);
|
||||||
|
},
|
||||||
|
{ urls: ["<all_urls>"], }
|
||||||
|
)
|
||||||
|
|
||||||
browser.tabs.onUpdated.addListener(
|
browser.tabs.onUpdated.addListener(
|
||||||
(tabId, changeInfo, _) => {
|
(tabId, changeInfo, _) => {
|
||||||
let url;
|
let url;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user