-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathredirect.js
More file actions
43 lines (37 loc) · 1.04 KB
/
Copy pathredirect.js
File metadata and controls
43 lines (37 loc) · 1.04 KB
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
const sp = new URLSearchParams(window.location.search)
const r = (sp.get("r") || "").toLowerCase()
const sourceUrl = sp.get("url")
const schemes = {
sidestore: s => "sidestore://source?url=" + s,
altstore: s => "altstore-classic://source?url=" + s,
stikstore: s => "stikstore://add-source?url=" + encodeURIComponent(s),
livecontainer: s => "livecontainer://source?url=" + s,
feather: s => "feather://source/" + s,
trollapps: s => "trollapps://add?url=" + s
}
function resolveTarget(kind, s) {
const fn = schemes[kind]
return fn && s ? fn(s) : ""
}
const target = resolveTarget(r, sourceUrl)
function afterFirstPaint(fn) {
const raf = window.requestAnimationFrame
if (raf) {
raf(() => raf(() => fn()))
} else {
setTimeout(fn, 100)
}
}
function scheduleRedirect() {
if (!target) return
afterFirstPaint(() => {
setTimeout(() => {
window.location.replace(target)
}, 60)
})
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", scheduleRedirect)
} else {
scheduleRedirect()
}