Skip to content

Instantly share code, notes, and snippets.

@mgamini
Created November 18, 2020 22:56
Show Gist options
  • Save mgamini/f5fefefd80a58a06e91779f4d62a61a6 to your computer and use it in GitHub Desktop.
Save mgamini/f5fefefd80a58a06e91779f4d62a61a6 to your computer and use it in GitHub Desktop.
Spelling Bee Hinter
var DOM = {
body: document.querySelector('body'),
parent: document.createElement('div'),
header: document.createElement('p'),
answerList: document.createElement('ul'),
refreshButton: document.createElement('button'),
hintParent: document.createElement('div'),
hintLabel: document.createElement('p'),
hintSlider: document.createElement('input')
}
var hintLevel = 2
DOM.parent.style.cssText = 'display: block; width: 100%; background: #eee; padding: 30px; position: absolute; top: 100%;';
DOM.header.style.marginBottom = '20px';
DOM.answerList.style.columnCount = 2
DOM.refreshButton.style.cssText = 'margin: 20px 0px 100px 0px; text-align: center; border: 1px solid black; padding: 10px; width: 100%;';
DOM.refreshButton.innerText = 'Refresh'
DOM.hintParent.style.cssText = 'display: block; width: 100%; padding: 30px;'
DOM.hintLabel.style.cssText = 'display: inline;'
DOM.hintLabel.innerText = `Reveal the first ${hintLevel} letter(s)`;
DOM.hintSlider.setAttribute('type', 'range');
DOM.hintSlider.setAttribute('min', 1)
DOM.hintSlider.setAttribute('max', 10)
DOM.hintSlider.setAttribute('value', 2)
DOM.hintSlider.setAttribute('id', 'hintSlider')
DOM.body.appendChild(DOM.parent);
DOM.parent.appendChild(DOM.header);
DOM.parent.appendChild(DOM.answerList);
DOM.parent.appendChild(DOM.hintParent);
DOM.hintParent.appendChild(DOM.hintLabel);
DOM.hintParent.appendChild(DOM.hintSlider);
DOM.parent.appendChild(DOM.refreshButton);
DOM.hintSlider.addEventListener('change', (e) => {
hintLevel = e.target.value
DOM.hintLabel.innerText = `Reveal the first ${hintLevel} letter(s)`;
})
a = [...document.scripts].find(script => script.innerText.includes('window.gameData'))
eval(a.innerText)
function makeAnswer(answer, found) {
let l = document.createElement('li');
if (found) {
l.style.cssText = 'text-decoration: line-through; opacity: 0.4; margin-bottom: 10px';
l.innerText = answer;
} else {
l.style.cssText = 'margin-bottom: 10px';
l.innerText = answer.split('').map((letter, idx) => idx >= hintLevel ? '_ ': letter).join('')
}
return l
}
function makeCheatList() {
let DATA = {
found: [...document.querySelectorAll('.sb-has-words > li')].map(el => el.innerText.toLowerCase()),
answers: window.gameData.today.answers
}
DOM.answerList.innerHTML = '';
DOM.header.innerText = `${DATA.found.length} of ${DATA.answers.length} found`;
[
...DATA.answers.filter(answer => !DATA.found.includes(answer)).map(answer => makeAnswer(answer, false)),
...DATA.answers.filter(answer => DATA.found.includes(answer)).map(answer => makeAnswer(answer, true))
].forEach(li => DOM.answerList.appendChild(li))
}
DOM.refreshButton.onclick = makeCheatList;
makeCheatList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment