Skip to content

Instantly share code, notes, and snippets.

@Yarillo4
Last active June 30, 2023 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yarillo4/56898cdb585c3fa13f75495fe36db869 to your computer and use it in GitHub Desktop.
Save Yarillo4/56898cdb585c3fa13f75495fe36db869 to your computer and use it in GitHub Desktop.
Help script for the password game. Feeding Paul, extinguishing the fires, ... https://neal.fun/password-game/
{
let findDeepestChildren_rec = (pwdElem, acc) => {
if (pwdElem.children.length == 0) {
// No more children, deepest child
acc.push(pwdElem);
}
for (v of pwdElem.children) {
acc = findDeepestChildren_rec(v, acc);
}
return acc;
}
let findDeepestChildren = (pwdElem) => {
return findDeepestChildren_rec(pwdElem, []);
}
let findInPwd = (deepestChildren, needle) => {
// Find paul
let elem = null;
for (v of deepestChildren) {
if (v.innerHTML.match(needle) !== null) {
elem = v;
}
}
if (elem === null) {
return {
"elem": null,
"position": -1
};
}
return {
"position": elem.innerHTML.search(needle),
"elem": elem
};
}
// ๐Ÿ”
let lastFeed = Date.now();
let feedPaul = (deepestChildren) => {
// Find paul
const {position: paulPosition, elem: paulElem} = findInPwd(deepestChildren, "๐Ÿ”");
if (paulPosition === -1) {
console.log("Paul isn't there yet :(");
return;
}
const now = Date.now();
if (now - lastFeed >= 19000) { // trying to stay close to 3 per minute
// Detect food
const food = Array.from(paulElem.innerHTML.matchAll("๐Ÿ›"));
if (food.length > 1) {
console.log("Paul has enough food for now");
return;
}
// Insert food
const paulAndBefore = paulElem.innerHTML.substr(0, paulPosition+2); // paul is 2 chars wide
const afterPaul = paulElem.innerHTML.substr(paulPosition+2);
console.log("Feeding Paul :)");
paulElem.innerHTML = paulAndBefore + "๐Ÿ›" + afterPaul;
lastFeed = now;
}
}
let removeFire = (deepestChildren) => {
do {
const {position: position, elem: elem} = findInPwd(deepestChildren, "๐Ÿ”ฅ")
if (position === -1) {
return;
}
const before = elem.innerHTML.substr(0, position);
const after = elem.innerHTML.substr(position+2); // fire is 2 chars wide
elem.innerHTML = `${before}${after}`;
} while (true);
}
let helperInterval = setInterval(() => {
const pwdElem = document.querySelector(".ProseMirror");
const deepestChildren = findDeepestChildren(pwdElem);
feedPaul(deepestChildren);
removeFire(deepestChildren);
}, 500)
console.log(helperInterval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment