Restricted auto redirection to only 503, 504. Added a 'Cancel Redirection' btn
This commit is contained in:
parent
12e2a268a8
commit
9de383439e
|
@ -130,8 +130,9 @@ browser.webRequest.onResponseStarted.addListener(
|
||||||
details => {
|
details => {
|
||||||
if (!generalHelper.getAutoRedirect()) return null;
|
if (!generalHelper.getAutoRedirect()) return null;
|
||||||
|
|
||||||
|
if (details.type == 'main_frame' && (details.statusCode == 503 || details.statusCode == 504)) {
|
||||||
|
// if (details.type == 'main_frame' && details.statusCode >= 200) {
|
||||||
console.log("statusCode", details.statusCode);
|
console.log("statusCode", details.statusCode);
|
||||||
if (details.type == 'main_frame' && details.statusCode >= 500) {
|
|
||||||
|
|
||||||
const url = new URL(details.url);
|
const url = new URL(details.url);
|
||||||
let newUrl;
|
let newUrl;
|
||||||
|
@ -159,10 +160,8 @@ browser.webRequest.onResponseStarted.addListener(
|
||||||
|
|
||||||
// if (!newUrl) newUrl = spotifyHelper.changeInstance(url);
|
// if (!newUrl) newUrl = spotifyHelper.changeInstance(url);
|
||||||
|
|
||||||
if (newUrl) {
|
if (newUrl) browser.tabs.update(details.tabId, { url: `/pages/errors/instance_offline.html?url=${encodeURIComponent(newUrl)}` });
|
||||||
browser.tabs.update({ url: '/pages/errors/instance_offline.html' });
|
|
||||||
setTimeout(() => browser.tabs.update({ url: newUrl }), 2000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ urls: ["<all_urls>"], }
|
{ urls: ["<all_urls>"], }
|
||||||
|
|
|
@ -9,19 +9,31 @@
|
||||||
<link href="../stylesheets/styles.css" rel="stylesheet" />
|
<link href="../stylesheets/styles.css" rel="stylesheet" />
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
display: flex;
|
flex-wrap: wrap;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
This instance is offline, you'll be redirected after <span id="number">2</span> seconds
|
<div>
|
||||||
|
<p id="message">This instance is offline, you'll be redirected after <span
|
||||||
|
id="number">2</span> seconds
|
||||||
|
</p>
|
||||||
|
<button id="cancel">Cancel</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="instance_offline.js"></script>
|
<script src="instance_offline.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,2 +1,20 @@
|
||||||
setTimeout(() => document.getElementById("number").innerHTML = '1', 1000);
|
const params = new Proxy(
|
||||||
setTimeout(() => document.getElementById("number").innerHTML = '0', 2000);
|
new URLSearchParams(window.location.search),
|
||||||
|
{ get: (searchParams, prop) => searchParams.get(prop) }
|
||||||
|
);
|
||||||
|
|
||||||
|
let number = document.getElementById("number");
|
||||||
|
setTimeout(() => number.innerHTML = '1', 1000);
|
||||||
|
setTimeout(
|
||||||
|
() => {
|
||||||
|
number.innerHTML = '0'
|
||||||
|
if (!isCanceled) window.location = params.url;
|
||||||
|
},
|
||||||
|
2000
|
||||||
|
);
|
||||||
|
|
||||||
|
let isCanceled = false;
|
||||||
|
document.getElementById("cancel").addEventListener("click", () => {
|
||||||
|
isCanceled = true;
|
||||||
|
document.getElementById("message").innerHTML = "Redirection Canceled";
|
||||||
|
})
|
Loading…
Reference in New Issue