Skip to content

Instantly share code, notes, and snippets.

@corupta
Created February 25, 2021 10:17
Show Gist options
  • Save corupta/2eeb18498f077dee0dcb6fb472457587 to your computer and use it in GitHub Desktop.
Save corupta/2eeb18498f077dee0dcb6fb472457587 to your computer and use it in GitHub Desktop.
Limesurvey auto-submit
/*
copy this to "Run Javascript" extension on a limesurvey survey page
when you click enable on "xxx" it will start working, disable by clicking the checkbox again.
*/
setTimeout(() => {
const a = "aeiou";
const b = "bcdfghjklmnpqrstvwxyz";
const ranf = (i, j, p=1) => Math.pow(Math.random(), p) * (j - i) + i;
const ran = (i, j, p=1) => Math.floor(ranf(i,j,p));
const ranG = (ls) => ls.map(l => l[ran(0,l.length)]).join('');
const fName = ranG([b,a,b,a,b]);
const lName = ranG([b,a,b,b,a,b,a]);
Array.from(document.querySelectorAll('.answer-container')).forEach((q, i) => {
const radios = q.querySelectorAll('input[type=radio]');
if (radios.length) {
radios[ran(0, radios.length, (((i+2) % 4)+3)/5)].click();
return;
}
const numi = q.querySelectorAll('input[type=text].numeric');
if (numi.length) {
Array.from(numi).forEach((nu, nui) => {
nu.click();
nu.value = `${Math.pow(10, (i+nui) % 5) * ran(10,1000, ranf(0.1,10))}`;
});
return;
}
const select = q.querySelector('select');
if (select) {
if (select.getAttribute('name') === '570710X12X100') {
select.selectedIndex = ran(1, select.childElementCount, 3);
} else {
select.selectedIndex = ran(1, select.childElementCount, ranf(0.2,4));
}
return;
}
const texto = q.querySelector('input[type=text]');
if (texto) {
texto.value = Math.random() > 0.5 ? fName : lName;
return;
}
});
const checkboxes = Array.from(document.querySelectorAll('input[type=checkbox]'));
if (checkboxes.length) {
for (let t = 0; t < 8; ++t) {
checkboxes.forEach((c,i) => {
if (ranf(0,1, ranf(0.1,10) * ((i % 7) + 1) * 13 / (i+1) / 7 ) > 0.5) {
c.click();
}
});
}
}
const submit = document.getElementById('ls-button-submit');
if (submit) {
submit.click();
} else {
location.replace(location.href);
}
},10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment