Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jeffalo
GitHub Repository: jeffalo/kahoot-gui
Path: blob/master/Functions.js
1754 views
1
function status(update) {
2
// Update the status in the program status text area
3
var currentStatus = "\n" + document.getElementById("status").innerHTML;
4
document.getElementById("status").innerHTML = update + currentStatus;
5
}
6
7
function random() {
8
// Shuffle the list of names from the bot names list
9
var botNames = document.getElementById("bot-name-list").value.split("\n");
10
var shuffledNames = shuffle(botNames);
11
//var output = document.getElementById("output");
12
var output = "";
13
shuffledNames.forEach(function(currentNumber) {
14
output += currentNumber + "\n";
15
});
16
document.getElementById("bot-name-list").value = output;
17
}
18
19
function inputNames() {
20
// Retrieves a list of generic names from the names.txt file and
21
// inputs the values retrieved in the bot names list in the advanced settings panel
22
fetch("./names.txt")
23
.then(response => response.text())
24
.then(data => {
25
document.getElementById("bot-name-list").value = data;
26
});
27
}
28
29
function shuffle(array) {
30
// Array shuffle function implementation
31
var currentIndex = array.length,
32
temporaryValue,
33
randomIndex;
34
35
// While there remain elements to shuffle...
36
while (0 !== currentIndex) {
37
// Pick a remaining element...
38
randomIndex = Math.floor(Math.random() * currentIndex);
39
currentIndex -= 1;
40
41
// And swap it with the current element.
42
temporaryValue = array[currentIndex];
43
array[currentIndex] = array[randomIndex];
44
array[randomIndex] = temporaryValue;
45
}
46
47
return array;
48
}
49
50
function simpleBotName(prefix, suffix) {
51
// Add prefix + name or suffix + name
52
return prefix + suffix;
53
}
54
55
module.exports = {
56
status: status,
57
random: random,
58
inputNames: inputNames,
59
shuffle: shuffle,
60
simpleBotName: simpleBotName
61
};
62
63