Skip to turn numeric input
Jump to navigation
Jump to search
This is a userscript that changes the "Skip to turn number" input type to number. This input field currently allows you to enter any text, but in practice only numbers are accepted.
To use this userscript:
- Install a userscript manager extension for your browser
- Chrome: Tampermonkey
- Firefox: Greasemonkey, Tampermonkey, or Violentmonkey
- Safari: Tampermonkey or Userscripts
- Microsoft Edge: Tampermonkey
- Opera: Tampermonkey or Violentmonkey
- Save this script to your computer
- Drag the downloaded script into your userscript manager extension
// ==UserScript==
// @name Skip to turn numeric input
// @namespace https://infiniteworlds.app/
// @version 1.0
// @description Changes the "Skip to turn number" input type to number
// @match https://infiniteworlds.app/
// @icon https://infinite-worlds-images.us-east-1.linodeobjects.com/00000__logo_square_on_background_512.jpg
// @grant none
// ==/UserScript==
(function() {
'use strict';
function skipToTurnHandler(e) {
const modal = document.getElementById("alert-modal");
if (modal === null) {
return;
}
const instructionsSelector = "//h4[starts-with(text(), 'Select a turn number')]";
const instructions = evaluateXpathFirstNode(instructionsSelector, modal);
if (instructions === null) {
return;
}
const regex = /\d+$/;
const turnInputSelector = "//h4[starts-with(text(), 'Select a turn number')]/ancestor::div[@class = 'modal-content']/descendant::input[@type = 'text']";
const turnInput = evaluateXpathFirstNode(turnInputSelector, modal);
if (turnInput !== null) {
turnInput.type = "number";
turnInput.min = "1";
turnInput.max = instructions.textContent.match(regex)[0];
turnInput.value = "1";
}
}
let skipToTurnObserver = new MutationObserver(skipToTurnHandler);
skipToTurnObserver.observe(document.body, { childList: true, subtree: true });
function evaluateXpathFirstNode(expression, contextNode = document) {
return document.evaluate(
expression,
contextNode,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
}
})();
