Replace "Available" with non-clickable Attack-Links

Replaces "available" with non-clickable attack links in the Item Market.

安装此脚本
作者推荐脚本

您可能也喜欢Makes the Attack-Links clickable.

安装此脚本
  1. // ==UserScript==
  2. // @name Replace "Available" with non-clickable Attack-Links
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Replaces "available" with non-clickable attack links in the Item Market.
  6. // @author Grance [3487987]
  7. // @match *://www.torn.com/page.php?sid=ItemMarket*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Function to replace "available" with attack links based on extracted IDs
  16. function replaceAvailableWithAttackLinks() {
  17. // Select only profile links inside the seller list
  18. const sellerList = document.querySelector('ul.sellerList___kgAh_'); // Get the <ul> with class 'sellerList___kgAh_'
  19.  
  20. if (sellerList){
  21. const profileLinks = sellerList.querySelectorAll('a[href^="/profiles.php?XID="]'); // Only anchor tags with href starting with '/profiles.php?XID='
  22.  
  23. // Iterate through the links and extract their IDs
  24. const profileIDs = Array.from(profileLinks).map(link => {
  25. const url = new URL(link.href, 'https://www.torn.com'); // Handle relative URLs
  26. return url.searchParams.get('XID'); // Extract the XID parameter from the href
  27. });
  28.  
  29.  
  30. // Counter to track replacements
  31. let replacementIndex = 0;
  32.  
  33. // Use TreeWalker to find text nodes with "available"
  34. const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, {
  35. acceptNode: function (node) {
  36. if (node.nodeValue.includes('available') && replacementIndex < profileIDs.length) {
  37. return NodeFilter.FILTER_ACCEPT;
  38. }
  39. return NodeFilter.FILTER_REJECT;
  40. }
  41. });
  42.  
  43. let node;
  44. while ((node = walker.nextNode())) {
  45. node.nodeValue = node.nodeValue.replace(/available/, () => {
  46. // Get the ID at the current replacement index
  47. const id = profileIDs[replacementIndex];
  48. replacementIndex++;
  49. return `https://www.torn.com/loader.php?sid=attack&user2ID=${id}`;
  50. });
  51. }}
  52. }
  53.  
  54. // Run the replacement function after the page has fully loaded
  55. window.addEventListener('load', () => {
  56. replaceAvailableWithAttackLinks();
  57. });
  58.  
  59. // Observe for dynamic updates and replace again
  60. const observer = new MutationObserver(() => {
  61. replaceAvailableWithAttackLinks();
  62. });
  63.  
  64. observer.observe(document.body, { childList: true, subtree: true });
  65. })();