// ==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; } })();