ylLinksSpammer

adds links

  1. // ==UserScript==
  2. // @name ylLinksSpammer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.69
  5. // @description adds links
  6. // @author kostrzak16
  7. // @match https://www.managerzone.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=managerzone.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. function processLeagueLinks() {
  15. // Define all language variants
  16. const titleVariants = [
  17. "Liga Światowa U18",
  18. "U18 World League",
  19. "Liga Mundial U18",
  20. "Liga Mundial Sub18",
  21. "Liga Mundial Sub-18",
  22. "U18 Dünya Ligi"
  23. ];
  24.  
  25. // Step 1: Check for h1 with any of the language variants
  26. const h1Elements = Array.from(document.getElementsByTagName('h1'));
  27. const targetH1 = h1Elements.find(h1 =>
  28. titleVariants.some(variant => h1.textContent.trim() === variant)
  29. );
  30.  
  31. if (!targetH1) {
  32. console.log("Target H1 not found in any language variant");
  33. return;
  34. }
  35.  
  36. // Check if link already exists next to h1
  37. const nextElement = targetH1.nextElementSibling;
  38. if (nextElement && nextElement.tagName === 'A') {
  39. console.log("Link already exists next to H1");
  40. return;
  41. }
  42.  
  43. // Step 2: Find link containing specific href pattern
  44. const links = document.getElementsByTagName('a');
  45. const teamLink = Array.from(links).find(link => link.href.includes('?p=team&tid='));
  46.  
  47. if (!teamLink) {
  48. console.log("Team link not found");
  49. return;
  50. }
  51.  
  52. // Step 3: Perform AJAX call
  53. fetch(teamLink.href)
  54. .then(response => response.text())
  55. .then(html => {
  56. // Create a temporary DOM parser
  57. const parser = new DOMParser();
  58. const doc = parser.parseFromString(html, 'text/html');
  59.  
  60. // Step 4: Look for league link specifically in infoAboutTeam div
  61. const infoDiv = doc.getElementById('infoAboutTeam');
  62. if (!infoDiv) {
  63. console.log("Info div not found in AJAX response");
  64. return;
  65. }
  66.  
  67. const leagueLinks = Array.from(infoDiv.getElementsByTagName('a'));
  68. const leagueLink = leagueLinks.find(link =>
  69. link.href.includes('/?p=league&type=u18_world') ||
  70. link.href.includes('/?p=league&type=u18_world')
  71. );
  72.  
  73. if (!leagueLink) {
  74. console.log("League link not found in info div");
  75. return;
  76. }
  77.  
  78. // Step 5: Add new link next to h1
  79. const newLink = document.createElement('a');
  80. newLink.href = leagueLink.href;
  81. newLink.textContent = leagueLink.textContent;
  82. newLink.style.marginLeft = '10px';
  83.  
  84. targetH1.parentNode.insertBefore(newLink, targetH1.nextSibling);
  85. })
  86. .catch(error => {
  87. console.error("Error during AJAX request:", error);
  88. });
  89. }
  90. // Your code here...
  91.  
  92. // Control variable to ensure we only process once per tab
  93. let hasProcessed = false;
  94.  
  95. // Function to handle visibility change
  96. function handleVisibilityChange() {
  97. if (document.visibilityState === 'visible' && !hasProcessed) {
  98. hasProcessed = true;
  99. setTimeout(processLeagueLinks, 6000);
  100. }
  101. }
  102.  
  103. // Add visibility change listener
  104. document.addEventListener('visibilitychange', handleVisibilityChange);
  105.  
  106. // Also check initial state in case tab is already active
  107. if (document.visibilityState === 'visible') {
  108. hasProcessed = true;
  109. setTimeout(processLeagueLinks, 500);
  110. }
  111.  
  112.  
  113.  
  114. })();