Last active
March 17, 2017 03:45
-
-
Save winguse/c4d49be80379e6d24a6ac0de919bbd96 to your computer and use it in GitHub Desktop.
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
const isPrime = {}; | |
const mark = (e, isPrime) => { | |
if (isPrime) { | |
e.style.textShadow = 'yellow 0px 0px 3px'; | |
} else { | |
e.style.opacity = 0; | |
} | |
}; | |
let queue = Promise.resolve(); | |
const find = () => document.querySelectorAll('span,a,p').forEach(e => { | |
const text = e.innerText.replace(/(\s|-)/g, ''); | |
if (!/^\d{11}$/.test(text)) return; | |
const n = +text; | |
if (isPrime[n] !== undefined) { | |
mark(e, isPrime[n]); | |
return; | |
} | |
queue = queue.then(() => | |
fetch('https://winguse.com/0/isprime.php?n=' + n) | |
.then(res => res.json()) | |
.then(res => { | |
isPrime[n] = res.next === n; | |
mark(e, isPrime[n]); | |
}) | |
) | |
}); | |
setInterval(find, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment