mirror of
https://gitea.invidious.io/iv-org/invidious-redirect.git
synced 2024-08-15 00:53:24 +00:00
Randomise instance order in list
This commit is contained in:
parent
6a1e8edde6
commit
c79c61ed4e
5 changed files with 64 additions and 28 deletions
|
@ -1,9 +1,9 @@
|
|||
<!DOCTYPE html><html lang="en"><head><title>Select instance - Invidious</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" type="text/css" href="/static/css/main.css?static=48f0608e85"><script src="/static/js/main.js?static=9b9aa0a304" text="text/javascript" defer></script></head><body><noscript><style>.requires-scripts {
|
||||
<!DOCTYPE html><html lang="en"><head><title>Select instance - Invidious</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" type="text/css" href="/static/css/main.css?static=48f0608e85"><script src="/static/js/main.js?static=8c7d4f10f2" text="text/javascript" defer></script></head><body><noscript><style>.requires-scripts {
|
||||
display: none;
|
||||
}</style></noscript><script type="text/javascript">document.body.classList.remove("yesscript")
|
||||
</script><header class="banner"><div class="logo"></div><h1>Invidious</h1></header><noscript><div class="script-warning"><p>You are seeing the fallback version of this page.<br>
|
||||
Some features are missing.</p><p>JavaScript is required to use the regular page.
|
||||
</p></div></noscript><div class="story"><p>As of September 1st 2020, <mark>invidio.us</mark> has closed down.</p><div class="requires-scripts"><p>To see this content, please select another instance,
|
||||
or <a id="watch-on-youtube">watch directly on YouTube.</a></p></div><noscript><p>To see this content, please select another instance,
|
||||
or <a id="watch-on-youtube">visit directly on YouTube.</a></p></div><noscript><p>To see this content, please select another instance,
|
||||
or <a href="https://www.youtube.com">go to YouTube</a> and find it yourself.
|
||||
</p></noscript></div><div class="instances-table requires-scripts"><table><thead><tr><th scope="col">Domain</th><th scope="col">Health</th><th scope="col">Action</th></tr></thead><tbody id="instances-tbody"><tr class="loading"><td class="loading-td" colspan="3">Loading instances...</td></tr></tbody></table></div><noscript><div class="instances-list"><h2>Available instances</h2><ul class="list"><li><a href="https://invidious.snopyta.org">invidious.snopyta.org</a></li><li><a href="https://yewtu.be">yewtu.be</a></li><li><a href="https://watch.nettohikari.com">watch.nettohikari.com</a></li><li><a href="https://invidious.13ad.de">invidious.13ad.de</a></li><li><a href="https://vid.mint.lgbt">vid.mint.lgbt</a></li><li><a href="https://invidiou.site">invidiou.site</a></li></ul></div></noscript></body></html>
|
||||
</p></noscript></div><div class="instances-table requires-scripts"><table><thead><tr><th scope="col">Domain</th><th scope="col">Health</th><th scope="col">Action</th></tr></thead><tbody id="instances-tbody"><tr class="loading"><td class="loading-td" colspan="3">Loading instances...</td></tr></tbody></table></div><noscript><div class="instances-list"><h2>Available instances</h2><ul class="list"><li><a href="https://invidious.snopyta.org">invidious.snopyta.org</a></li><li><a href="https://invidious.ggc-project.de">invidious.ggc-project.de</a></li><li><a href="https://invidious.13ad.de">invidious.13ad.de</a></li><li><a href="https://yewtu.be">yewtu.be</a></li><li><a href="https://invidious.fdn.fr">invidious.fdn.fr</a></li><li><a href="https://invidious.toot.koeln">invidious.toot.koeln</a></li><li><a href="https://invidiou.site">invidiou.site</a></li><li><a href="https://yt.iswleuven.be">yt.iswleuven.be</a></li><li><a href="https://vid.mint.lgbt">vid.mint.lgbt</a></li><li><a href="https://watch.nettohikari.com">watch.nettohikari.com</a></li></ul></div></noscript></body></html>
|
|
@ -15,24 +15,40 @@
|
|||
return e
|
||||
}
|
||||
|
||||
function shuffle(array) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
let j = Math.floor(Math.random() * (array.length-i)) + i
|
||||
;[array[i], array[j]] = [array[j], array[i]]
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
const destinationPath = window.location.href.slice(window.location.origin.length)
|
||||
|
||||
q("#watch-on-youtube").href = "https://www.youtube.com" + destinationPath
|
||||
|
||||
fetch("https://instances.invidio.us/instances.json?pretty=1&sort_by=type,health").then(res => res.json()).then(
|
||||
fetch("https://instances.invidio.us/instances.json?sort_by=type,health").then(res => res.json()).then(
|
||||
/** @param {[string, {monitor: any, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ root => {
|
||||
console.log(root)
|
||||
root.filter(entry => entry[1].type === "https").forEach(entry => {
|
||||
let healthUnknown = "health-unknown "
|
||||
let health = "(unknown)"
|
||||
if (entry[1].monitor && entry[1].monitor.dailyRatios && entry[1].monitor.dailyRatios[0]) {
|
||||
health = entry[1].monitor.dailyRatios[0].ratio
|
||||
healthUnknown = ""
|
||||
shuffle(root)
|
||||
root.map(entry => {
|
||||
const healthKnown = !!entry[1].monitor
|
||||
return {
|
||||
name: entry[0],
|
||||
details: entry[1],
|
||||
health: +(healthKnown ? entry[1].monitor.dailyRatios[0].ratio : 99),
|
||||
healthKnown
|
||||
}
|
||||
let target = entry[1].uri.replace(/\/*$/, "") + destinationPath
|
||||
}).filter(entry => {
|
||||
return entry.details.type === "https"
|
||||
}).sort((a, b) => {
|
||||
return b.health - a.health
|
||||
}).forEach(entry => {
|
||||
let target = entry.details.uri.replace(/\/*$/, "") + destinationPath
|
||||
const healthUnknown = entry.healthKnown ? "" : "health-unknown "
|
||||
const health = entry.healthKnown ? entry.health.toFixed(0) : "(unknown)"
|
||||
q("#instances-tbody").appendChild(
|
||||
createElement("tr", {}, [
|
||||
createElement("td", {textContent: entry[0]}),
|
||||
createElement("td", {textContent: entry.name}),
|
||||
createElement("td", {className: "column-center "+healthUnknown, textContent: health}),
|
||||
createElement("td", {className: "column-center"}, [
|
||||
createElement("a", {href: target, textContent: "Go →"})
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"main": "build.js",
|
||||
"scripts": {
|
||||
"build": "node src/build.js",
|
||||
"watch": "fish -c 'while true; inotifywait (find src -type f) -e close_write -q; npm run build; end'"
|
||||
"watch": "fish -c 'while true; npm run build; inotifywait (find src -type f) -e close_write -q; end'"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
|
@ -35,7 +35,7 @@ html(lang="en")
|
|||
.requires-scripts
|
||||
p.
|
||||
To see this content, please select another instance,
|
||||
or #[a#watch-on-youtube watch directly on YouTube.]
|
||||
or #[a#watch-on-youtube visit directly on YouTube.]
|
||||
noscript
|
||||
p.
|
||||
To see this content, please select another instance,
|
||||
|
@ -58,11 +58,15 @@ html(lang="en")
|
|||
-
|
||||
const instances = [
|
||||
"invidious.snopyta.org",
|
||||
"yewtu.be",
|
||||
"watch.nettohikari.com",
|
||||
"invidious.ggc-project.de",
|
||||
"invidious.13ad.de",
|
||||
"yewtu.be",
|
||||
"invidious.fdn.fr",
|
||||
"invidious.toot.koeln",
|
||||
"invidiou.site",
|
||||
"yt.iswleuven.be",
|
||||
"vid.mint.lgbt",
|
||||
"invidiou.site"
|
||||
"watch.nettohikari.com"
|
||||
]
|
||||
for instance in instances
|
||||
li: a(href=`https://${instance}`)= instance
|
||||
|
|
36
src/main.js
36
src/main.js
|
@ -15,24 +15,40 @@
|
|||
return e
|
||||
}
|
||||
|
||||
function shuffle(array) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
let j = Math.floor(Math.random() * (array.length-i)) + i
|
||||
;[array[i], array[j]] = [array[j], array[i]]
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
const destinationPath = window.location.href.slice(window.location.origin.length)
|
||||
|
||||
q("#watch-on-youtube").href = "https://www.youtube.com" + destinationPath
|
||||
|
||||
fetch("https://instances.invidio.us/instances.json?pretty=1&sort_by=type,health").then(res => res.json()).then(
|
||||
fetch("https://instances.invidio.us/instances.json?sort_by=type,health").then(res => res.json()).then(
|
||||
/** @param {[string, {monitor: any, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ root => {
|
||||
console.log(root)
|
||||
root.filter(entry => entry[1].type === "https").forEach(entry => {
|
||||
let healthUnknown = "health-unknown "
|
||||
let health = "(unknown)"
|
||||
if (entry[1].monitor && entry[1].monitor.dailyRatios && entry[1].monitor.dailyRatios[0]) {
|
||||
health = entry[1].monitor.dailyRatios[0].ratio
|
||||
healthUnknown = ""
|
||||
shuffle(root)
|
||||
root.map(entry => {
|
||||
const healthKnown = !!entry[1].monitor
|
||||
return {
|
||||
name: entry[0],
|
||||
details: entry[1],
|
||||
health: +(healthKnown ? entry[1].monitor.dailyRatios[0].ratio : 99),
|
||||
healthKnown
|
||||
}
|
||||
let target = entry[1].uri.replace(/\/*$/, "") + destinationPath
|
||||
}).filter(entry => {
|
||||
return entry.details.type === "https"
|
||||
}).sort((a, b) => {
|
||||
return b.health - a.health
|
||||
}).forEach(entry => {
|
||||
let target = entry.details.uri.replace(/\/*$/, "") + destinationPath
|
||||
const healthUnknown = entry.healthKnown ? "" : "health-unknown "
|
||||
const health = entry.healthKnown ? entry.health.toFixed(0) : "(unknown)"
|
||||
q("#instances-tbody").appendChild(
|
||||
createElement("tr", {}, [
|
||||
createElement("td", {textContent: entry[0]}),
|
||||
createElement("td", {textContent: entry.name}),
|
||||
createElement("td", {className: "column-center "+healthUnknown, textContent: health}),
|
||||
createElement("td", {className: "column-center"}, [
|
||||
createElement("a", {href: target, textContent: "Go →"})
|
||||
|
|
Loading…
Reference in a new issue