-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
46 lines (41 loc) · 1.3 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
suffix = (navigator.userAgent.includes("Mobile")) ? Date.now() : "";
async function toDataURL(url) {
return fetch(url).then((response) => {
return response.blob();
}).then(blob => {
return URL.createObjectURL(blob);
});
}
function getState(length) {
state = (localStorage.hasOwnProperty("state")) ? parseInt(localStorage.getItem("state")) + 1: 0;
if (isNaN(state) || state > length) state = 0;
if (confirm('Allow state to be saved to localStorage?') || localStorage.getItem("state") !== null) {
localStorage.setItem("state", state);
} else {
location.href = "https://ndev.tk/";
}
}
async function download(url, filename) {
var a = document.createElement("a");
a.href = await toDataURL(url);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function Redirect(url) {
if (navigator.userAgent.includes("Firefox")) { // Bypass not needed for Firefox
JustDoTheThingPlease();
} else {
if (history.next) {
history.forward();
} else {
setTimeout(_ => {
location.href = url;
}, 200);
}
}
}