use generated json file for instance list

This commit is contained in:
ChunkyProgrammer 2023-07-26 17:14:05 -07:00
parent 029859082e
commit c342345bc5
9 changed files with 1047 additions and 455 deletions

View file

@ -65,6 +65,7 @@
const health = entry.healthKnown ? entry.health.toFixed(0) : "(unknown)"
q("#instances-tbody").appendChild(
createElement("tr", {}, [
createElement("td", {textContent: `${entry.details.flag} ${entry.details.region}`}),
createElement("td", {textContent: entry.name}),
createElement("td", {className: "column-center "+healthUnknown, textContent: health}),
createElement("td", {className: "column-center"}, [

View file

@ -1,2 +1,2 @@
"use strict";function _createForOfIteratorHelper(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e){throw _e},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var normalCompletion=true,didErr=false,err;return{s:function s(){it=o[Symbol.iterator]()},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e2){didErr=true;err=_e2},f:function f(){try{if(!normalCompletion&&it.return!=null)it.return()}finally{if(didErr)throw err}}}}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2};(function(){var q=function q(s){return document.querySelector(s)};var qa=function qa(s){return document.querySelectorAll(s)};function createElement(tag){var properties=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var children=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var e=document.createElement(tag);for(var _i=0,_Object$keys=Object.keys(properties);_i<_Object$keys.length;_i++){var key=_Object$keys[_i];e[key]=properties[key]}var _iterator=_createForOfIteratorHelper(children),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var child=_step.value;e.appendChild(child)}}catch(err){_iterator.e(err)}finally{_iterator.f()}return e}function shuffle(array){for(var i=0;i<array.length;i++){var j=Math.floor(Math.random()*(array.length-i))+i;var _ref=[array[j],array[i]];array[i]=_ref[0];array[j]=_ref[1]}return array}function request(url,callback){var xhr=new XMLHttpRequest;xhr.addEventListener("readystatechange",function(){if(xhr.readyState===4){if(xhr.status===200){callback(null,JSON.parse(xhr.response))}}});xhr.open("GET",url);xhr.send()}var destinationPath=window.location.href.slice(window.location.origin.length);q("#watch-on-youtube").href="https://www.youtube.com"+destinationPath;var _iterator2=_createForOfIteratorHelper(qa("[data-loading-message]")),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var e=_step2.value;e.textContent=e.getAttribute("data-loading-message")}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}request("https://api.invidious.io/instances.json?sort_by=type,health",function(err,root){shuffle(root);root.map(function(entry){var healthKnown=!!entry[1].monitor;return{name:entry[0],details:entry[1],health:+(healthKnown?entry[1].monitor.dailyRatios[0].ratio:95),healthKnown:healthKnown}}).filter(function(entry){return entry.details.type==="https"&&entry.health>0}).sort(function(a,b){return b.health-a.health}).forEach(function(entry){var target=entry.details.uri.replace(/\/*$/,"")+destinationPath;var healthUnknown=entry.healthKnown?"":"health-unknown ";var health=entry.healthKnown?entry.health.toFixed(0):"(unknown)";q("#instances-tbody").appendChild(createElement("tr",{},[createElement("td",{textContent:entry.name}),createElement("td",{className:"column-center "+healthUnknown,textContent:health}),createElement("td",{className:"column-center"},[createElement("a",{href:target,textContent:"Go \u2192"})])]))});var _iterator3=_createForOfIteratorHelper(qa(".loading")),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var e=_step3.value;e.remove()}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}})})();
"use strict";function _createForOfIteratorHelper(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e){throw _e},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var normalCompletion=true,didErr=false,err;return{s:function s(){it=o[Symbol.iterator]()},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e2){didErr=true;err=_e2},f:function f(){try{if(!normalCompletion&&it.return!=null)it.return()}finally{if(didErr)throw err}}}}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2};(function(){var q=function q(s){return document.querySelector(s)};var qa=function qa(s){return document.querySelectorAll(s)};function createElement(tag){var properties=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var children=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var e=document.createElement(tag);for(var _i=0,_Object$keys=Object.keys(properties);_i<_Object$keys.length;_i++){var key=_Object$keys[_i];e[key]=properties[key]}var _iterator=_createForOfIteratorHelper(children),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var child=_step.value;e.appendChild(child)}}catch(err){_iterator.e(err)}finally{_iterator.f()}return e}function shuffle(array){for(var i=0;i<array.length;i++){var j=Math.floor(Math.random()*(array.length-i))+i;var _ref=[array[j],array[i]];array[i]=_ref[0];array[j]=_ref[1]}return array}function request(url,callback){var xhr=new XMLHttpRequest;xhr.addEventListener("readystatechange",function(){if(xhr.readyState===4){if(xhr.status===200){callback(null,JSON.parse(xhr.response))}}});xhr.open("GET",url);xhr.send()}var destinationPath=window.location.href.slice(window.location.origin.length);q("#watch-on-youtube").href="https://www.youtube.com"+destinationPath;var _iterator2=_createForOfIteratorHelper(qa("[data-loading-message]")),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var e=_step2.value;e.textContent=e.getAttribute("data-loading-message")}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}request("https://api.invidious.io/instances.json?sort_by=type,health",function(err,root){shuffle(root);root.map(function(entry){var healthKnown=!!entry[1].monitor;return{name:entry[0],details:entry[1],health:+(healthKnown?entry[1].monitor.dailyRatios[0].ratio:95),healthKnown:healthKnown}}).filter(function(entry){return entry.details.type==="https"&&entry.health>0}).sort(function(a,b){return b.health-a.health}).forEach(function(entry){var target=entry.details.uri.replace(/\/*$/,"")+destinationPath;var healthUnknown=entry.healthKnown?"":"health-unknown ";var health=entry.healthKnown?entry.health.toFixed(0):"(unknown)";q("#instances-tbody").appendChild(createElement("tr",{},[createElement("td",{textContent:"".concat(entry.details.flag," ").concat(entry.details.region)}),createElement("td",{textContent:entry.name}),createElement("td",{className:"column-center "+healthUnknown,textContent:health}),createElement("td",{className:"column-center"},[createElement("a",{href:target,textContent:"Go \u2192"})])]))});var _iterator3=_createForOfIteratorHelper(qa(".loading")),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var e=_step3.value;e.remove()}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}})})();
//# sourceMappingURL=/static/js/main.min.js.map

File diff suppressed because one or more lines are too long

106
instances.json Normal file
View file

@ -0,0 +1,106 @@
[
{
"flag": "🇺🇸",
"url": "vid.puffyan.us"
},
{
"flag": "🇩🇪",
"url": "invidious.tiekoetter.com"
},
{
"flag": "🇷🇴",
"url": "invidious.flokinet.to"
},
{
"flag": "🇱🇺",
"url": "inv.bp.projectsegfau.lt"
},
{
"flag": "🇩🇪",
"url": "yt.artemislena.eu"
},
{
"flag": "🇫🇷",
"url": "invidious.projectsegfau.lt"
},
{
"flag": "🇩🇪",
"url": "invidious.lunar.icu"
},
{
"flag": "🇫🇷",
"url": "invidious.privacydev.net"
},
{
"flag": "🇺🇸",
"url": "inv.tux.pizza"
},
{
"flag": "🇸🇬",
"url": "vid.priv.au"
},
{
"flag": "🇩🇪",
"url": "yt.oelrichsgarcia.de"
},
{
"flag": "🇨🇱",
"url": "inv.zzls.xyz"
},
{
"flag": "🇫🇮",
"url": "invidious.protokolla.fi"
},
{
"flag": "🇱🇹",
"url": "invidious.0011.lt"
},
{
"flag": "🇺🇸",
"url": "invidious.io.lol"
},
{
"flag": "🇮🇳",
"url": "inv.in.projectsegfau.lt"
},
{
"flag": "🇫🇮",
"url": "iv.nboeck.de"
},
{
"flag": "🇺🇸",
"url": "invidious.slipfox.xyz"
},
{
"flag": "🇸🇪",
"url": "invidious.no-logs.com"
},
{
"flag": "🇩🇪",
"url": "iv.melmac.space"
},
{
"flag": "🇳🇱",
"url": "yewtu.be"
},
{
"flag": "🇪🇸",
"url": "inv.makerlab.tech"
},
{
"flag": "🇳🇱",
"url": "inv.citw.lgbt"
},
{
"flag": "🇯🇵",
"url": "onion.tube"
},
{
"flag": "🇨🇦",
"url": "iv.ggtyler.dev"
},
{
"flag": "🇫🇷",
"url": "inv.pistasjis.net"
}
]

1348
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,12 +5,12 @@
"main": "build.js",
"scripts": {
"build": "node src/build.js",
"update-instances": "node scripts/update-instance-list.js",
"watch": "fish -c 'while true; npm run build; inotifywait (find src -type f) -e close_write -q; end'"
},
"keywords": [],
"author": "",
"license": "AGPL-3.0-only",
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",

View file

@ -0,0 +1,19 @@
const fs = require("fs")
fetch("https://api.invidious.io/instances.json?pretty=1&sort_by=type,users").then(function (data) {
return data.json()
}).then(function (data) {
const instances = data.filter(instance => {
return instance[1].type === 'https'
}).map((instance) => {
return { flag: instance[1].flag, url: instance[0] }
})
if (instances.length === 0) {
throw new Error("No instances found. Likely an issue with the instance list.")
}
fs.writeFile("./instances.json", JSON.stringify(instances, null, 2), (err) => {
})
})

View file

@ -12,7 +12,7 @@ const buildDir = "../build"
const static = new Map()
const links = new Map()
const scripts = []
const pugLocals = {static, scripts, links}
const pugLocals = {static, scripts, links, instancesJson: []}
const spec = [
{
@ -119,6 +119,8 @@ async function addBabel(sourcePath, targetPath) {
;(async () => {
// Stage 1: Register
pugLocals.instancesJson = JSON.parse(await fs.readFile('../instances.json', 'utf8'))
for (const item of spec) {
if (item.type === "pug") {
links.set(item.source, item.target)

View file

@ -50,23 +50,7 @@ html(lang="en")
h2 Available instances
ul.list
-
const instances = [
{url: "yewtu.be", flag: "🇳🇱"},
{url: "vid.puffyan.us", flag: "🇺🇸"},
{url: "invidious.flokinet.to", flag: "🇷🇴"},
{url: "invidious.projectsegfau.lt", flag: "🇫🇷"},
{url: "inv.bp.projectsegfau.lt", flag: "🇱🇺"},
{url: "inv.in.projectsegfau.lt", flag: "🇮🇳"},
{url: "invidious.tiekoetter.com", flag: "🇩🇪"},
{url: "invidious.slipfox.xyz", flag: "🇺🇸"},
{url: "invidious.privacydev.net", flag: "🇫🇷"},
{url: "vid.priv.au", flag: "🇸🇬"},
{url: "iv.ggtyler.dev", flag: "🇨🇦"},
{url: "invidious.0011.lt", flag: "🇱🇹"},
{url: "inv.zzls.xyz", flag: "🇨🇱"},
{url: "invidious.protokolla.fi", flag: "🇫🇮"},
]
for instance in instances
for instance in instancesJson
li
= `${instance.flag} `
a(href=`https://${instance.url}`)= instance.url