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 => {
|
||||
if (!generalHelper.getAutoRedirect()) return null;
|
||||
|
||||
console.log("statusCode", details.statusCode);
|
||||
if (details.type == 'main_frame' && details.statusCode >= 500) {
|
||||
if (details.type == 'main_frame' && (details.statusCode == 503 || details.statusCode == 504)) {
|
||||
// if (details.type == 'main_frame' && details.statusCode >= 200) {
|
||||
console.log("statusCode", details.statusCode);
|
||||
|
||||
const url = new URL(details.url);
|
||||
let newUrl;
|
||||
|
@ -159,10 +160,8 @@ browser.webRequest.onResponseStarted.addListener(
|
|||
|
||||
// if (!newUrl) newUrl = spotifyHelper.changeInstance(url);
|
||||
|
||||
if (newUrl) {
|
||||
browser.tabs.update({ url: '/pages/errors/instance_offline.html' });
|
||||
setTimeout(() => browser.tabs.update({ url: newUrl }), 2000);
|
||||
}
|
||||
if (newUrl) browser.tabs.update(details.tabId, { url: `/pages/errors/instance_offline.html?url=${encodeURIComponent(newUrl)}` });
|
||||
|
||||
}
|
||||
},
|
||||
{ urls: ["<all_urls>"], }
|
||||
|
|
|
@ -9,19 +9,31 @@
|
|||
<link href="../stylesheets/styles.css" rel="stylesheet" />
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 30px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
div {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<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>
|
||||
</body>
|
||||
|
|
|
@ -1,2 +1,20 @@
|
|||
setTimeout(() => document.getElementById("number").innerHTML = '1', 1000);
|
||||
setTimeout(() => document.getElementById("number").innerHTML = '0', 2000);
|
||||
const params = new Proxy(
|
||||
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