Add voltorbflip spinner userscript
This commit is contained in:
		
							
								
								
									
										5
									
								
								VoltorbFlipSpinners/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								VoltorbFlipSpinners/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| # Default ignored files | ||||
| /shelf/ | ||||
| /workspace.xml | ||||
| # Editor-based HTTP Client requests | ||||
| /httpRequests/ | ||||
							
								
								
									
										12
									
								
								VoltorbFlipSpinners/.idea/VoltorbFlipSpinners.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								VoltorbFlipSpinners/.idea/VoltorbFlipSpinners.iml
									
									
									
										generated
									
									
									
										Normal 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> | ||||
							
								
								
									
										8
									
								
								VoltorbFlipSpinners/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								VoltorbFlipSpinners/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal 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> | ||||
							
								
								
									
										6
									
								
								VoltorbFlipSpinners/.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								VoltorbFlipSpinners/.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal 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> | ||||
							
								
								
									
										70
									
								
								VoltorbFlipSpinners/src/VoltorbFlipSpinners.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								VoltorbFlipSpinners/src/VoltorbFlipSpinners.js
									
									
									
									
									
										Normal 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(); | ||||
		Reference in New Issue
	
	Block a user