You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB
JavaScript

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")
.then(response => response.json())
.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";
});