idrlabs.com - Solver

Creates a button to solve the quiz with random answers.

Från och med 2024-04-24. Se den senaste versionen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           idrlabs.com - Solver
// @namespace      idrlabs.com utils
// @match          https://www.idrlabs.com/*/test.php
// @icon           https://www.google.com/s2/favicons?sz=64&domain=idrlabs.com
// @grant          none
// @version        1.0.0
// @author         eye-wave
// @license        GPL-3.0+
// @description    Creates a button to solve the quiz with random answers.
// ==/UserScript==
"use strict";
const select = (selector) => document.querySelector(selector);
const randomInt = (max) => Math.floor(Math.random() * max);
const getRandomElement = (array) => array[randomInt(array.length)];
const container = document.querySelector(".process");
if (container) {
  const button = document.createElement("span");
  button.textContent = "Solve";
  button.className = "qnav";
  button.addEventListener("click", handleButtonClick, { once: true });
  container.appendChild(button);
}
function handleButtonClick() {
  const agreeButton = select(".agree");
  const disagreeButton = select(".disagree");
  const ratingElements = Array.from({ length: 5 }).map((_, index) => select(`.t${index + 1}`));
  const rangeInput = select("input[type='range']");
  const finishButton = select("[data-finish]");
  const minValue = +rangeInput?.getAttribute("min") || 0;
  const maxValue = (+rangeInput?.getAttribute("max") || 5) + 1;
  const clickRandomRating = () => {
    if (ratingElements.every((element) => element)) {
      getRandomElement(ratingElements).click();
    } else if (rangeInput) {
      rangeInput.value = randomInt(maxValue - minValue) + minValue;
    } else if (agreeButton || disagreeButton) {
      Math.random() > 0.5 ? agreeButton.click() : disagreeButton.click();
    } else {
      getRandomElement(document.querySelectorAll(".answer")).click();
    }
  };
  clickRandomRating();
  setTimeout(handleButtonClick, 0);
  finishButton.click();
}