// ==UserScript==
// @name A9 Product .02
// @version 1.03
// @description preclicks, buttons, enter to submit
// @author SarahAshlee90
// @include /^https://(www|s3)\.(mturkcontent|amazonaws)\.com/
// @grant none
// @require https://code.jquery.com/jquery-3.1.1.min.js
// ==/UserScript==
var sanity = document.querySelectorAll('h4')[0];
if (sanity.innerHTML === "Image 1") {
window.focus();
const radios_and_checkboxes = document.querySelectorAll('[type="radio"]');
function preclick(elements_to_click, ...numbers) {
const radios_and_checkboxes_to_preclick = [];
Array.prototype.slice.call(arguments).forEach(el => radios_and_checkboxes_to_preclick.push(el));
radios_and_checkboxes_to_preclick.forEach(element => radios_and_checkboxes[element].click());
console.log(`There are a total of ${radios_and_checkboxes.length} checkboxes/radio's on this page. The requested preclicks are numbers ${radios_and_checkboxes_to_preclick}`);
}
setTimeout(function () {
preclick(0, 2, 4, 6, 8);
}, 1500);
window.addEventListener("keydown", function (event) {
if (event.code === "NumpadEnter") {
$('[id="submit"]').click();
}
});
function button1_click() {
for (var i = 0; i < radios_and_checkboxes.length; i++) {
radios_and_checkboxes[i].checked = false;
}
setTimeout(function () {
radios_and_checkboxes[1].click();
setTimeout(function () {
$('[id="submit"]').click();
}, 250)
}, 250);
}
function button2_click() {
radios_and_checkboxes[3].click();
}
function button3_click() {
radios_and_checkboxes[8].checked = false;
setTimeout(function () {
radios_and_checkboxes[5].click();
}, 250);
}
function button4_click() {
radios_and_checkboxes[8].checked = false;
setTimeout(function () {
radios_and_checkboxes[7].click();
}, 250);
}
function button5_click() {
radios_and_checkboxes[9].click();
setTimeout(function () {
$('[id="submit"]').click();
}, 250);
}
function createButton(context, func, color, text) {
var button = document.createElement("input");
button.style.backgroundColor = color
button.type = "button";
button.value = text;
button.onclick = func;
context.appendChild(button);
}
const q_1 = document.getElementById("notsure").parentNode;
const q_2 = radios_and_checkboxes[3].parentNode;
const q_3 = radios_and_checkboxes[5].parentNode;
const q_4 = radios_and_checkboxes[7].parentNode;
const q_5 = radios_and_checkboxes[9].parentNode;
const control = document.querySelectorAll('[id="main"]')[0];
createButton(q_1, button1_click, "red", "Clear all answers then click No/Not Sure then click Submit");
createButton(q_2, button2_click, "Chartreuse", "Different Angle");
createButton(q_3, button3_click, "Chartreuse", "Clear Question 5 then click No");
createButton(q_4, button4_click, "Chartreuse", "Clear Question 5 then click No");
createButton(q_5, button5_click, "red", "Click No and Submit");
setTimeout(function () {
windowH();
}, 50);
var retrievedObject = localStorage.getItem('page_resizing');
console.log(retrievedObject);
var option = "on"
if (retrievedObject === null) {
localStorage.setItem("page_resizing", option);
} if (retrievedObject === "off") {
option = "off";
var but = document.querySelectorAll('[value="Toggle page resizing(on)"]')[0];
but.style.backgroundColor = "grey"
but.value = "Toggle page resizing(off)";
}
function button6_click() {
var but = document.querySelectorAll('[value="Toggle page resizing(on)"]')[0] || document.querySelectorAll('[value="Toggle page resizing(off)"]')[0];
if (but.style.backgroundColor === "green") {
but.style.backgroundColor = "grey"
option = "off";
but.value = "Toggle page resizing(off)";
localStorage.setItem("page_resizing", option);
} else if (but.style.backgroundColor === "grey") {
option = "on";
but.style.backgroundColor = "green";
but.value = "Toggle page resizing(on)"
localStorage.setItem("page_resizing", option);
}
}
}