Skip to content

Instantly share code, notes, and snippets.

@winguse
Last active March 17, 2017 03:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save winguse/c4d49be80379e6d24a6ac0de919bbd96 to your computer and use it in GitHub Desktop.
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