Skip to content

Instantly share code, notes, and snippets.

@l-portet
Created July 31, 2022 21:19
Show Gist options
  • Save l-portet/2a16ff441ce4b0a966c26f7656a86379 to your computer and use it in GitHub Desktop.
Save l-portet/2a16ff441ce4b0a966c26f7656a86379 to your computer and use it in GitHub Desktop.
Check if there's any Google foobar challenge invite in the page comments
// Check if there's any Google foobar challenge invite in the page comments
// https://www.geeksforgeeks.org/google-foo-bar-challenge/
(() => {
function getAllComments() {
const $root = document.documentElement;
const comments = [];
const iterator = document.createNodeIterator($root, NodeFilter.SHOW_COMMENT, () => NodeFilter.FILTER_ACCEPT, false);
let node;
while (node = iterator.nextNode()) {
comments.push(node.nodeValue);
}
return comments;
}
function findFoobarComments() {
if (isFound) {
return;
}
const targets = ['you are speaking our language', 'up for a challenge', 'google.com/foobar', 'foobar.withgoogle.com'];
const comments = getAllComments().map(comment => comment.toLowerCase());
const hasTargetComment = comments.some(comment => targets.some(target => comment.includes(target)));
if (hasTargetComment) {
clearInterval(interval);
isFound = true;
console.log('Found foobar challenge!');
console.log(comments);
alert('Found foobar challenge! -> ' + comments.join`|`)
}
}
let isFound = false;
findFoobarComments();
let interval = setInterval(findFoobarComments, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment