This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadElementsSecure(query,root,timeout){ | |
if(timeout===undefined){ | |
timeout=10000; | |
} | |
if(root===undefined){ | |
root=document; | |
} | |
var t0=Date.now(); | |
return new Promise(function(resolve,reject){ | |
function _loadElements(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var [debounceAnimation,removeDebounceAnimation]=(function(){ | |
var id=1; | |
var registeredFunctions=new Map(); | |
var registeredFunctionIds=new Map(); | |
var isLooping=false; | |
function debounceAnimationLoop(){ | |
// iterate over registeredFunctions | |
var entriesIterator=registeredFunctions.entries(); | |
var entry; | |
while(!(entry=entriesIterator.next()).done){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function transpose(matrix){ | |
var n=matrix.length; | |
var m=matrix[0].length; | |
var result=new Array(m); | |
for(var i=0;i<m;i++){ | |
result[i]=new Array(n); | |
for(var j=0;j<n;j++){ | |
result[i][j]=matrix[j][i]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript(script,...args){ | |
if (document.readyState === 'complete' || document.readyState === 'interactive') { | |
script(...args); | |
}else{ | |
document.addEventListener('DOMContentLoaded',script.bind(this,...args)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scroll to id tagged element when there is a fixed sized header bar | |
function executeDelayed(f,...args){ | |
Promise.resolve().then(function(){ | |
window.requestAnimationFrame(function(){ | |
f.call(this,...args); | |
}); | |
}); | |
} | |
var queue=[]; | |
window.addEventListener(/*"DOMContentLoaded"*/"load", processQueue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i=0; | |
setInterval(()=>console.log(i),1000); | |
var a=[]; | |
setInterval(function abc(){i++;a.push([Date.now()])},0); | |
// replace next line with worker | |
//setInterval(function abc(){i++;a[a.length-1].push(Date.now())},0); | |
///// | |
function abcdef() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serializeElementToSelector(element){ | |
if(!element.dataset.hasOwnProperty('__serial_token__')) | |
element.dataset.__serial_token__=''+((Math.random()*1e9)<<0)+((Math.random()*1e9)<<0)+Date.now(); | |
var tagName=element.tagName.toLowerCase(); | |
var selector=tagName; | |
if(element.id!==''){ | |
selector+='#'+element.id; | |
} | |
for(let cls of element.classList){ | |
selector+='.'+CSS.escape(cls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getParentElementByType(element,parentType){ | |
while((element=element.parentElement)!==null){ | |
if(element instanceof parentType) return element; | |
} | |
return element; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLeafElements(root=document.body,result=[]){ | |
if(root.children.length===0) return result.push(root); | |
for(var element of root.children){ | |
getLeafElements(element,result); | |
} | |
return result; | |
} | |
function getElementsByTextContent(reg){ | |
var elements=getLeafElements(); | |
var result=[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var primes=[2]; | |
var maxPrime=2; | |
function generatePrimes(max){ | |
for(var i=maxPrime;i<=max;i++){ | |
maxPrime=i; | |
if(isPrime(i)) if(i>2) primes.push(i); | |
} | |
} | |
function isPrime(n){ | |
var max=Math.floor(Math.sqrt(Math.abs(n))); |