Add voltorbflip spinner userscript

This commit is contained in:
Isaac Shoebottom 2024-01-07 00:46:48 -04:00
parent bbb71a7c49
commit 307dd6b0dc
5 changed files with 101 additions and 0 deletions

5
VoltorbFlipSpinners/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/VoltorbFlipSpinners.iml" filepath="$PROJECT_DIR$/.idea/VoltorbFlipSpinners.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,70 @@
// ==UserScript==
// @name Voltorb Flip Spinners
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description Adds spinners to the inputs of numbers
// @author Isaac Shoebottom
// @match http://voltorbflip.com/
// @icon http://voltorbflip.com/favicon.ico
// @grant none
// @run-at document-idle
// ==/UserScript==
// To add spinners I just need to change the input type from text to numbers
/**
* Finds the board element
* @returns {HTMLElement}
*/
function findBoard() {
return document.getElementById("board");
}
/**
* Finds all inputs that are children of the passed element
* @param {HTMLElement} element
* @returns {Array<HTMLElement>}
*/
function findInputs(element) {
// Find all input elements that are children of the root element
// Should have the type="text" attribute
let col = element.getElementsByTagName("input");
// Convert the HTMLCollection to an array
return Array.from(col).filter((input) => input.type === "text");
}
/**
* Adds a spinner to the input element on mouseover
* @param {HTMLElement} inputElement
* @returns {void}
*/
function addMouseOverSpinner(inputElement) {
console.log("Adding mouseover spinner on element: " + inputElement);
inputElement.addEventListener("mouseover", () => {
console.log("Mouseover on element: " + inputElement);
inputElement.type = "number";
});
inputElement.addEventListener("mouseout", () => {
console.log("Mouseout on element: " + inputElement);
inputElement.type = "text";
});
}
/**
* Executes the script
* @returns {void}
*/
function execute() {
let board = findBoard();
if (!board) {
console.log("Could not find board");
return;
}
let inputs = findInputs(board);
console.log("Found " + inputs.length + " inputs");
inputs.forEach(addMouseOverSpinner)
}
execute();