Torn Transform Text to Numeric Input

Transforms various text inputs to number inputs (Only useful on mobile)

当前为 2025-01-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Torn Transform Text to Numeric Input
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Transforms various text inputs to number inputs (Only useful on mobile)
  6. // @author TheProgrammer
  7. // @match https://www.torn.com/page.php?sid=stocks*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function transformToNumericInput(element) {
  16. element.type = 'number';
  17. // Optional: Set additional attributes if needed
  18. // element.pattern = '[0-9]*';
  19. // element.step = '0.01';
  20. }
  21.  
  22. function processNewInputs(mutationsList, observer) {
  23. for(const mutation of mutationsList) {
  24. if (mutation.type === 'childList') {
  25. mutation.addedNodes.forEach(node => {
  26. if (node.nodeType === Node.ELEMENT_NODE) {
  27. if (node.matches('input.input-money:not([type="hidden"])')) {
  28. transformToNumericInput(node);
  29. } else if (node.hasChildNodes()) {
  30. node.querySelectorAll('input.input-money:not([type="hidden"])').forEach(transformToNumericInput);
  31. }
  32. }
  33. });
  34. }
  35. }
  36. }
  37.  
  38. function observeMutations() {
  39. const observer = new MutationObserver(processNewInputs);
  40. observer.observe(document.body, {
  41. childList: true,
  42. subtree: true
  43. });
  44. }
  45.  
  46. // Run the script on page load and observe for mutations
  47. observeMutations();
  48.  
  49. })();