Last active
June 30, 2023 15:25
-
-
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/
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
{ | |
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