Torrent Game Copier

Adds unique, styled copy buttons to each torrent group on the right side with improved text formatting.

  1. // ==UserScript==
  2. // @name Torrent Game Copier
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Adds unique, styled copy buttons to each torrent group on the right side with improved text formatting.
  6. // @author SleepingGiant
  7. // @license MIT
  8. // @match https://gazellegames.net/torrents.php*
  9. // @exclude https://gazellegames.net/torrents.php*id=*
  10. // @exclude https://gazellegames.net/torrents.php*action=basic*
  11. // @grant GM_setClipboard
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to create a styled button element
  18. function createStyledButton(text, formatFunction, torrentId, groupName, groupYear) {
  19. let button = document.createElement('button');
  20. button.textContent = text;
  21. button.style.display = 'block';
  22. button.style.padding = '5px 10px';
  23. button.style.backgroundColor = '#007BFF';
  24. button.style.color = '#fff';
  25. button.style.border = 'none';
  26. button.style.borderRadius = '4px';
  27. button.style.cursor = 'pointer';
  28. button.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  29. button.style.marginBottom = '20px';
  30.  
  31. // Ensure the text stays within the button box
  32. button.style.whiteSpace = 'nowrap';
  33. button.style.overflow = 'hidden';
  34. button.style.textOverflow = 'ellipsis';
  35. button.style.width = '100%';
  36.  
  37. button.onclick = function() {
  38. let formattedText = formatFunction(torrentId, groupName, groupYear);
  39. GM_setClipboard(formattedText);
  40. button.textContent = 'Copied!';
  41. };
  42.  
  43. button.onmouseover = function() {
  44. button.style.backgroundColor = '#0056b3';
  45. };
  46. button.onmouseout = function() {
  47. button.style.backgroundColor = '#007BFF';
  48. };
  49.  
  50. return button;
  51. }
  52.  
  53. // Function for ByGenre format
  54. function byGenreFormat(torrentId, groupName, groupYear) {
  55. return `[url=https://gazellegames.net/torrents.php?id=${torrentId}]${groupName} ${groupYear}[/url]`;
  56. }
  57.  
  58. // Function for TitleChain/Name format
  59. function titleChainFormat(torrentId, groupName) {
  60. return `[url=https://gazellegames.net/torrents.php?id=${torrentId}]${groupName}[/url]`;
  61. }
  62.  
  63. // Attach styled buttons to each #displayname element
  64. document.querySelectorAll('#displayname').forEach(el => {
  65. let groupName = el.querySelector('#groupname a').textContent.trim();
  66. let groupYear = el.querySelector('#groupyear') ? el.querySelector('#groupyear').textContent.trim() : '';
  67. let linkElement = el.querySelector('#groupname a');
  68. let torrentId = new URLSearchParams(linkElement.href.split('?')[1]).get('id');
  69.  
  70. if (torrentId) {
  71. let buttonContainer = document.createElement('div');
  72. buttonContainer.style.display = 'flex';
  73. buttonContainer.style.flexDirection = 'column';
  74.  
  75. let byGenreButton = createStyledButton('ByGenre', byGenreFormat, torrentId, groupName, groupYear);
  76. let titleChainButton = createStyledButton('TitleChain/Name', titleChainFormat, torrentId, groupName);
  77. buttonContainer.appendChild(byGenreButton);
  78. buttonContainer.appendChild(titleChainButton);
  79.  
  80. el.parentNode.insertBefore(buttonContainer, el.nextSibling);
  81. }
  82. });
  83. })();