master
parent
580ab0da9d
commit
054a0d0952
@ -1,3 +1,32 @@
|
|||||||
|
function randint (from, to) {
|
||||||
|
return from + Math.floor((Math.random() * (to-from)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function choice (arr) {
|
||||||
|
let ri = randint(0, arr.length-1);
|
||||||
|
let ret = arr[ri];
|
||||||
|
arr.splice(ri, 1);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
fetch("terms.json")
|
fetch("terms.json")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(terms => console.log("terms", terms));
|
.then(terms => {
|
||||||
|
console.log("terms", terms);
|
||||||
|
let call = document.querySelector("#call");
|
||||||
|
let template = call.querySelector(".phrase");
|
||||||
|
for (var i=0; i<20; i++) {
|
||||||
|
let nn = template.cloneNode(true);
|
||||||
|
call.appendChild(nn);
|
||||||
|
nn.querySelector(".actor").innerHTML = choice(terms['actor']);
|
||||||
|
nn.querySelector(".action").innerHTML = choice(terms['action']);
|
||||||
|
if (randint(0, 2) == 0) {
|
||||||
|
nn.querySelector(".prefix").innerHTML = choice(terms['prefix']);
|
||||||
|
} else {
|
||||||
|
nn.querySelector(".prefix").remove();
|
||||||
|
}
|
||||||
|
nn.querySelector(".sort").innerHTML = choice(terms['sort']);
|
||||||
|
nn.querySelector(".media").innerHTML = choice(terms['media']);
|
||||||
|
}
|
||||||
|
template.style.visibility = "hidden";
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue