You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.3 KiB
99 lines
3.3 KiB
console.log((function(document, clipboard) {
|
|
const LOWERCASE_A_OFFSET = 0x61
|
|
const CIRCLED_SPACE = 0x25CF
|
|
const CIRCLED_A_OFFSET = 0x24B6
|
|
const NEGATIVE_CIRCLED_A_OFFSET = 0x1F150
|
|
const SQUARED_A_OFFSET = 0x1F130
|
|
const NEGATIVE_SQUARED_A_OFFSET = 0x1F170
|
|
const UNFILLED = " "
|
|
const UNFILLED_EMOJI_CODEPOINT = 0x2754
|
|
const FILLED_EMOJI_CODEPOINT = 0x2753
|
|
const ABSENT = "absent"
|
|
const ABSENT_EMOJI_CODEPOINT = 0x2B1B
|
|
const PRESENT = "present"
|
|
const PRESENT_EMOJI_CODEPOINT = 0x1F7E8
|
|
const CORRECT = "correct"
|
|
const CORRECT_EMOJI_CODEPOINT = 0x1F7E9
|
|
const IN_PROGRESS = "IN_PROGRESS"
|
|
const FAIL = "FAIL"
|
|
const WIN = "WIN"
|
|
const NON_EMOJI_VARIANT = 0xfe0e
|
|
|
|
function letterToEvaluatedCodePoints(letter, evaluation) {
|
|
if (letter === UNFILLED) {
|
|
return CIRCLED_SPACE
|
|
}
|
|
let offset
|
|
switch (evaluation) {
|
|
case CORRECT:
|
|
offset = NEGATIVE_SQUARED_A_OFFSET
|
|
break
|
|
case PRESENT:
|
|
offset = SQUARED_A_OFFSET
|
|
break
|
|
case null:
|
|
offset = NEGATIVE_CIRCLED_A_OFFSET
|
|
break
|
|
case ABSENT:
|
|
default:
|
|
offset = CIRCLED_A_OFFSET
|
|
break
|
|
}
|
|
return [letter.codePointAt(0) - LOWERCASE_A_OFFSET + offset, NON_EMOJI_VARIANT]
|
|
}
|
|
|
|
function evaluationsToEmoji(word, evaluations) {
|
|
if (evaluations === null) {
|
|
return String.fromCodePoint(...Array.from(word).map((letter) => letter === UNFILLED ? UNFILLED_EMOJI_CODEPOINT : FILLED_EMOJI_CODEPOINT))
|
|
}
|
|
return String.fromCodePoint(...evaluations.map((eval) => {
|
|
switch (eval) {
|
|
case CORRECT:
|
|
return CORRECT_EMOJI_CODEPOINT
|
|
case PRESENT:
|
|
return PRESENT_EMOJI_CODEPOINT
|
|
case ABSENT:
|
|
default:
|
|
return ABSENT_EMOJI_CODEPOINT
|
|
}
|
|
}))
|
|
}
|
|
|
|
function wordToEvaluatedWord(word, evaluations) {
|
|
return String.fromCodePoint(...Array.from(word).map((letter, index) =>
|
|
letterToEvaluatedCodePoints(letter, evaluations !== null ? evaluations[index] : null)
|
|
).flat())
|
|
}
|
|
|
|
function wordToResultLine(word, evaluations) {
|
|
return `${evaluationsToEmoji(word, evaluations)} ||${wordToEvaluatedWord(word, evaluations)}||`
|
|
}
|
|
|
|
function count(rowIndex, gameStatus) {
|
|
switch (gameStatus) {
|
|
case WIN:
|
|
return rowIndex
|
|
case FAIL:
|
|
return "X"
|
|
case IN_PROGRESS:
|
|
default:
|
|
return "?"
|
|
}
|
|
}
|
|
|
|
function gameStateToResults(game) {
|
|
return `Wordle ${game.dayOffset} ${count(game.rowIndex, game.gameStatus)}/6${game.hardMode ? "*" : ""}\n\n${game.boardState
|
|
.map((word, index) => [word, game.evaluations[index]])
|
|
.filter(([word]) => word !== "")
|
|
.map(([word, evaluation]) => wordToResultLine(word.padEnd(5, UNFILLED), evaluation))
|
|
.join('\n')}`
|
|
}
|
|
|
|
function findGame() {
|
|
return document.querySelector("game-app")
|
|
}
|
|
|
|
const results = gameStateToResults(findGame())
|
|
clipboard.writeText(results)
|
|
return results
|
|
})(document, navigator.clipboard))
|
|
|