mirror of
https://git.kittycat.homes/zoe/hugo-battheme.git
synced 2024-08-15 03:25:18 +00:00
improve randomizer
This commit is contained in:
parent
d267fc4356
commit
3967fa1027
1 changed files with 15 additions and 8 deletions
|
@ -7,22 +7,29 @@ export function randomizeWords() {
|
|||
function registerButtons() {
|
||||
for (let button of buttons) {
|
||||
button.addEventListener("click", function () {
|
||||
let new_word = processWordlist(button.getAttribute("data-wordlist"));
|
||||
button.innerHTML = processWordlist(
|
||||
button.getAttribute("data-wordlist"),
|
||||
button.innerHTML
|
||||
);
|
||||
// do this so people dont have to click twice
|
||||
if (button.innerHTML == new_word) {
|
||||
button.click();
|
||||
console.log("oh no!!! this was already the value!");
|
||||
} else {
|
||||
button.innerHTML = new_word;
|
||||
}
|
||||
});
|
||||
button.click();
|
||||
}
|
||||
}
|
||||
|
||||
// takes all the words and returns only one
|
||||
function processWordlist(wordlist) {
|
||||
function processWordlist(wordlist, old) {
|
||||
let seperated = wordlist.split(",");
|
||||
for (let word of wordlist) {
|
||||
word = word.trim();
|
||||
}
|
||||
if (seperated.length <= 0) {
|
||||
return "error! empty";
|
||||
}
|
||||
if (seperated.length == 1) {
|
||||
return seperated[0];
|
||||
}
|
||||
seperated = seperated.filter((e) => e !== old);
|
||||
return seperated.random();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue