Last active
June 28, 2024 11:06
-
-
Save b3x206/b07541c082de8f4548e5ea8877e1da42 to your computer and use it in GitHub Desktop.
Yüzem Anket Doldur (Üniversite Öğretmen Anketi)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YYÜ YUZEM Anket Doldur | |
// @version 0.4 | |
// @author B3X | |
// @description Unipa'nın yaptığı anket formu sayfasındaki cevapları rastgele olarak doldur. | |
// @namespace https://servis.yyu.edu.tr | |
// @match http://servis.yyu.edu.tr/* | |
// @match https://servis.yyu.edu.tr/* | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
// This is free and unencumbered software released into the public domain. | |
// Anyone is free to copy, modify, publish, use, compile, sell, or | |
// distribute this software, either in source code form or as a compiled | |
// binary, for any purpose, commercial or non-commercial, and by any | |
// means. | |
// (see https://unlicense.org) | |
"use strict"; | |
(function () { | |
/** | |
* Get whether if we are on the poll website. | |
* @returns {boolean} | |
*/ | |
function isInsidePollPage() { | |
const answerContainers = document.getElementsByClassName("form-horizontal"); | |
return answerContainers.length >= 1; | |
} | |
/** | |
* Fills the answers | |
* @param {number} randomLowerInclusive | |
* @param {number} randomUpperExclusive | |
* @returns {void} | |
*/ | |
function fillAnswers(randomLowerInclusive = 0, randomUpperExclusive = 5) { | |
// check params | |
if (typeof randomLowerInclusive === "string") { | |
randomLowerInclusive = Number.parseInt(randomLowerInclusive); | |
} | |
if (typeof randomUpperExclusive === "string") { | |
randomUpperExclusive = Number.parseInt(randomUpperExclusive); | |
} | |
if (!Number.isInteger(randomLowerInclusive)) { | |
randomLowerInclusive = 0; | |
} | |
if (!Number.isInteger(randomUpperExclusive)) { | |
randomUpperExclusive = 5; | |
} | |
if (randomLowerInclusive > randomUpperExclusive) { | |
randomLowerInclusive = randomUpperExclusive; | |
} | |
const answersContainer = document.getElementsByClassName("form-horizontal")[0]; | |
for (let i = 0; i < answersContainer.children.length; i++) { | |
const answerContainer = answersContainer.children[i]; | |
const selectionsContainer = answerContainer.children[1]; | |
// Probably a stray element that is most likely null or undefined. | |
if (selectionsContainer === undefined || selectionsContainer === null) { | |
continue; | |
} | |
// Define a selection behaviour here | |
// This will randomly fill it here. | |
const selectedIdx = Math.floor(randomLowerInclusive + (Math.random() * (randomUpperExclusive - randomLowerInclusive))); | |
/** @type {HTMLDataListElement} */ | |
const selectedListItem = selectionsContainer.children[selectedIdx]; | |
const selectedInput = selectedListItem.getElementsByTagName("input")[0]; | |
selectedInput.click(); | |
} | |
// when done, scroll to bottom to make user click end button faster | |
window.scrollTo(0, document.body.scrollHeight); | |
} | |
if (!isInsidePollPage()) { | |
return; | |
} | |
// ------------------- | |
// SettingsDiv Main | |
// Create a html element (div) that shows a box with an input for fillBias and that's it. | |
const currentDiv = document.getElementById("main"); // Primary website div | |
const settingsDiv = document.createElement("div"); | |
// This div won't contain anything by itself (other than an id, and it being the background) | |
settingsDiv.id = "anketDoldurMainDiv"; | |
settingsDiv.style.display = 'block'; | |
settingsDiv.style.position = 'fixed'; | |
settingsDiv.style.width = '200px'; | |
settingsDiv.style.height = '120px'; | |
settingsDiv.style.top = '10px'; | |
settingsDiv.style.left = '10px'; | |
settingsDiv.style.right = '10px'; | |
settingsDiv.style.bottom = '10px'; | |
settingsDiv.style.color = '#3ea0af'; | |
settingsDiv.style.opacity = '85%'; | |
settingsDiv.style.backgroundColor = '#3ea0af'; | |
settingsDiv.style.borderRadius = '5px'; | |
settingsDiv.style.padding = '5px 5px 5px 5px'; | |
settingsDiv.style.zIndex = 2; | |
settingsDiv.style.pointer = 'default'; | |
// add the newly created element and its content into the DOM | |
document.body.insertBefore(settingsDiv, currentDiv); | |
const titleDiv = document.createElement("div"); | |
titleDiv.style.color = "black"; | |
titleDiv.style.textAlign = "center"; | |
titleDiv.style.fontWeight = "bold"; | |
titleDiv.innerText = "Yuzem Anket Doldur"; | |
settingsDiv.appendChild(titleDiv); | |
// --- | |
// FillBias field | |
const fillBiasDiv = document.createElement("div"); | |
fillBiasDiv.style.color = "black"; // Text color etc. | |
settingsDiv.appendChild(fillBiasDiv); | |
// Add a text description | |
const fillLowerFieldText = document.createElement("div"); | |
fillLowerFieldText.innerText = "Doldurma Alt Değeri (1-5)"; | |
fillBiasDiv.appendChild(fillLowerFieldText); | |
// Add a int field for fillBias | |
const fillLowerInclusiveField = document.createElement("input"); | |
fillLowerInclusiveField.setAttribute("type", "number"); | |
fillLowerInclusiveField.setAttribute("min", "1"); | |
fillLowerInclusiveField.setAttribute("max", "5"); | |
fillLowerInclusiveField.setAttribute("step", "1"); | |
fillLowerInclusiveField.setAttribute("placeholder", "Eşdeğer"); | |
fillLowerInclusiveField.value = 3; | |
fillBiasDiv.appendChild(fillLowerInclusiveField); | |
const fillUpperFieldText = document.createElement("div"); | |
fillUpperFieldText.innerText = "Doldurma Üst Değeri (1-5)"; | |
fillBiasDiv.appendChild(fillUpperFieldText); | |
// Add a int field for fillBias | |
const fillUpperExclusiveField = document.createElement("input"); | |
fillUpperExclusiveField.setAttribute("type", "number"); | |
fillUpperExclusiveField.setAttribute("min", "1"); | |
fillUpperExclusiveField.setAttribute("max", "5"); | |
fillUpperExclusiveField.setAttribute("step", "1"); | |
fillUpperExclusiveField.setAttribute("placeholder", "Eşdeğer"); | |
fillUpperExclusiveField.value = 5; | |
fillBiasDiv.appendChild(fillUpperExclusiveField); | |
// --- | |
// Do thing button | |
// And a button for fill answers | |
const fillButton = document.createElement("button"); | |
fillButton.setAttribute("type", "button"); | |
fillButton.innerText = "Cevapları doldur"; | |
fillButton.addEventListener("click", () => { | |
try { | |
fillAnswers( | |
(fillLowerInclusiveField.value.trim() === "" ? 4 : Number.parseInt(fillLowerInclusiveField.value)) - 1, | |
(fillUpperExclusiveField.value.trim() === "" ? 5 : Number.parseInt(fillUpperExclusiveField.value)) | |
); | |
} catch (err) { | |
alert("# Hata oluştu:\n-----" + err); | |
} | |
}); | |
fillButton.style.position = 'relative'; | |
fillButton.style.width = '50%'; | |
fillButton.style.left = '25%'; | |
settingsDiv.appendChild(fillButton); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment