Makes the Attack-Links clickable.

Makes the attack-links clickable.

  1. // ==UserScript==
  2. // @name Makes the Attack-Links clickable.
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Makes the attack-links clickable.
  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 convert div into a clickable link
  16. function convertDivToLink() {
  17. //console.log("convertDivToLink triggered at", new Date().toISOString());
  18.  
  19. const divs = document.querySelectorAll('div.available___xegv_');
  20. //console.log(`Found ${divs.length} div(s) with class 'available___xegv_'`);
  21.  
  22. divs.forEach((div, index) => {
  23. //console.log(`Processing div #${index + 1}:`, div.textContent);
  24.  
  25. if (div.textContent.includes('https://') && !div.dataset.linkConverted) {
  26. //console.log("Div contains a URL and hasn't been processed.");
  27.  
  28. const urlMatch = div.textContent.match(/https:\/\/www\.torn\.com\/loader\.php\?sid=attack&user2ID=\d+/);
  29. if (urlMatch) {
  30. const url = urlMatch[0];
  31. const text = div.textContent.replace(url, '').trim();
  32.  
  33. //console.log(`URL: ${url}, Remaining Text: "${text}"`);
  34.  
  35. const link = document.createElement('a');
  36. link.href = url;
  37. link.textContent = `${text} Available`;
  38. link.style.color = 'inherit';
  39. link.style.textDecoration = 'none';
  40. link.target = '_blank';
  41.  
  42. div.innerHTML = '';
  43. div.appendChild(link);
  44. div.dataset.linkConverted = 'true';
  45.  
  46. //console.log("Div converted to clickable link:", div.innerHTML);
  47. } else {
  48. //console.warn("No valid URL found in the div.");
  49. }
  50. } else {
  51. //console.log("Div does not contain a URL or was already processed.");
  52. }
  53. });
  54. }
  55.  
  56. // Observe the page for dynamic content
  57. const observer = new MutationObserver((mutations) => {
  58. //console.log("MutationObserver triggered:", mutations);
  59. convertDivToLink();
  60. });
  61.  
  62. observer.observe(document.body, { childList: true, subtree: true });
  63. //console.log("MutationObserver started.");
  64.  
  65. // Run conversion immediately after page load
  66. window.addEventListener('load', () => {
  67. //console.log("Page loaded. Initializing link conversion...");
  68. convertDivToLink();
  69. });
  70. })();