Use for..of instead of NodeList#forEach

This commit is contained in:
Cadence Ember 2020-08-08 23:57:24 +12:00
parent 6a72e11a42
commit ac1b68e5c2
No known key found for this signature in database
GPG key ID: 128B99B1B74A6412
5 changed files with 17 additions and 7 deletions

View file

@ -1,4 +1,4 @@
<!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=dfaa1273d6"><script src="/static/js/main.min.js?static=b065c796c9" 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=dfaa1273d6"><script src="/static/js/main.min.js?static=26819fe5e7" text="text/javascript" defer></script></head><body><noscript><style>.requires-scripts {
display: none;
}
</style></noscript><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>

View file

@ -40,7 +40,9 @@
q("#watch-on-youtube").href = "https://www.youtube.com" + destinationPath
qa("[data-loading-message]").forEach(e => e.textContent = e.getAttribute("data-loading-message"))
for (const e of qa("[data-loading-message]")) {
e.textContent = e.getAttribute("data-loading-message")
}
request("https://instances.invidio.us/instances.json?sort_by=type,health",
/** @param {[string, {monitor: any, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ (err, root) => {
@ -71,6 +73,9 @@
])
)
})
qa(".loading").forEach(e => e.remove())
for (const e of qa(".loading")) {
e.remove()
}
})
})()

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;qa("[data-loading-message]").forEach(function(e){return e.textContent=e.getAttribute("data-loading-message")});request("https://instances.invidio.us/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"})])]))});qa(".loading").forEach(function(e){return e.remove()})})})();
"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://instances.invidio.us/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()}})})();
//# sourceMappingURL=/static/js/main.min.js.map

File diff suppressed because one or more lines are too long

View file

@ -40,7 +40,9 @@
q("#watch-on-youtube").href = "https://www.youtube.com" + destinationPath
qa("[data-loading-message]").forEach(e => e.textContent = e.getAttribute("data-loading-message"))
for (const e of qa("[data-loading-message]")) {
e.textContent = e.getAttribute("data-loading-message")
}
request("https://instances.invidio.us/instances.json?sort_by=type,health",
/** @param {[string, {monitor: any, flag: string, region: string, stats: any, type: string, uri: string}][]} root */ (err, root) => {
@ -71,6 +73,9 @@
])
)
})
qa(".loading").forEach(e => e.remove())
for (const e of qa(".loading")) {
e.remove()
}
})
})()