Only show instances with api enabled for api links

This commit is contained in:
ChunkyProgrammer 2023-10-17 01:17:57 -04:00
parent d5e4d97f4f
commit 5b82af19c4
4 changed files with 12 additions and 7 deletions

View File

@ -37,6 +37,7 @@
}
const destinationPath = window.location.href.slice(window.location.origin.length)
const isApiUrl = destinationPath.startsWith('/api/v1')
q("#watch-on-youtube").href = "https://www.youtube.com" + destinationPath
@ -45,18 +46,19 @@
}
request("https://api.invidious.io/instances.json?sort_by=type,health",
/** @param {[string, {monitor: any, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ (err, root) => {
/** @param {[string, {monitor: any, api: boolean, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ (err, root) => {
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 : 95),
health: +(healthKnown ? entry[1].monitor.uptime : 95),
apiEnabled: entry[1].api,
healthKnown
}
}).filter(entry => {
return entry.details.type === "https" && entry.health > 0
return entry.details.type === "https" && entry.health > 0 && (!isApiUrl || entry.apiEnabled)
}).sort((a, b) => {
return b.health - a.health
}).forEach(entry => {
@ -65,6 +67,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);var isApiUrl=destinationPath.startsWith("/api/v1");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.uptime:95),apiEnabled:entry[1].api,healthKnown:healthKnown}}).filter(function(entry){return entry.details.type==="https"&&entry.health>0&&(!isApiUrl||entry.apiEnabled)}).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

View File

@ -37,6 +37,7 @@
}
const destinationPath = window.location.href.slice(window.location.origin.length)
const isApiUrl = destinationPath.startsWith('/api/v1')
q("#watch-on-youtube").href = "https://www.youtube.com" + destinationPath
@ -45,7 +46,7 @@
}
request("https://api.invidious.io/instances.json?sort_by=type,health",
/** @param {[string, {monitor: any, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ (err, root) => {
/** @param {[string, {monitor: any, api: boolean, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ (err, root) => {
shuffle(root)
root.map(entry => {
const healthKnown = !!entry[1].monitor
@ -53,10 +54,11 @@
name: entry[0],
details: entry[1],
health: +(healthKnown ? entry[1].monitor.uptime : 95),
apiEnabled: entry[1].api,
healthKnown
}
}).filter(entry => {
return entry.details.type === "https" && entry.health > 0
return entry.details.type === "https" && entry.health > 0 && (!isApiUrl || entry.apiEnabled)
}).sort((a, b) => {
return b.health - a.health
}).forEach(entry => {