Torn Price RRP Auto Input

Automatically sets the price in the item listing page with a button click on Torn.com

目前为 2024-12-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Torn Price RRP Auto Input
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.6
  5. // @description Automatically sets the price in the item listing page with a button click on Torn.com
  6. // @author Gemini 2.0 https://gemini.google.com/ and OctaviusRW https://www.torn.com/profiles.php?XID=3421627
  7. // @match https://www.torn.com/page.php?sid=ItemMarket*
  8. // @match https://*.torn.com/page.php?sid=ItemMarket*
  9. // @license GNU GPLv3
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function addButtonsToPriceElements() {
  17. const priceElements = document.querySelectorAll('div[class*="price___"]');
  18.  
  19. priceElements.forEach(priceElement => {
  20. if (priceElement.querySelector('.tampermonkey-price-button')) return;
  21.  
  22. const button = document.createElement('button');
  23. button.textContent = '$'; // Shorter button text
  24. button.classList.add('tampermonkey-price-button');
  25.  
  26. button.addEventListener('click', () => {
  27. const priceText = priceElement.textContent.trim();
  28. const priceMatch = priceText.match(/[\$£€]?[\s]*([\d,.]+)/i);
  29.  
  30. if (priceMatch) {
  31. const price = priceMatch[1].trim();
  32. const rowElement = priceElement.closest('div[class*="itemRow___"]');
  33.  
  34. if (rowElement) {
  35. const inputMoney = rowElement.querySelector('div.input-money-group input[data-money="Infinity"]');
  36.  
  37. if (inputMoney) {
  38. inputMoney.value = price;
  39. inputMoney.dispatchEvent(new Event('input', { 'bubbles': true, 'cancelable': true }));
  40. inputMoney.dispatchEvent(new Event('change', { 'bubbles': true }));
  41. inputMoney.dispatchEvent(new Event('blur'));
  42. } else {
  43. alert("Could not find the price input in this row.");
  44. }
  45. } else {
  46. alert("Could not find the product row. Check the HTML.");
  47. }
  48. } else {
  49. alert("Could not find price.");
  50. }
  51. });
  52.  
  53. priceElement.appendChild(button);
  54. });
  55. }
  56.  
  57. addButtonsToPriceElements();
  58. const observer = new MutationObserver(mutations => {
  59. let nodesAdded = false;
  60. mutations.forEach(mutation => {
  61. if (mutation.addedNodes.length > 0) {
  62. nodesAdded = true;
  63. }
  64. });
  65. if (nodesAdded) {
  66. addButtonsToPriceElements();
  67. }
  68. });
  69. observer.observe(document.body, { childList: true, subtree: true });
  70.  
  71. const style = document.createElement('style');
  72. style.textContent = `
  73. .tampermonkey-price-button {
  74. background-color: #4CAF50;
  75. border: none;
  76. color: white;
  77. padding: 2px 5px; /* Smaller padding */
  78. text-align: center;
  79. text-decoration: none;
  80. display: inline-block;
  81. font-size: 12px; /* Smaller font */
  82. cursor: pointer;
  83. border-radius: 3px; /* Smaller border radius */
  84. margin-left: 3px; /* Reduced margin */
  85. line-height: 1; /* Added line-height to control vertical spacing */
  86. }
  87. .tampermonkey-price-button:hover {
  88. background-color: #45a049;
  89. }
  90. `;
  91. document.head.appendChild(style);
  92.  
  93. console.log("Set Price to Input script running.");
  94. })();