YTS.mx - Copy Magnet Button

Adds a "Copy Magnet" button to every movie quality on YTS.mx for easy access.

  1. // ==UserScript==
  2. // @name YTS.mx - Copy Magnet Button
  3. // @name:id YTS.mx - Tombol Salin Magnet
  4. // @namespace https://github.com/Horyzontalhoror/yts_copymagnet
  5. // @version 2.1
  6. // @description Adds a "Copy Magnet" button to every movie quality on YTS.mx for easy access.
  7. // @description:id Menambahkan tombol "Salin Magnet" di setiap kualitas film YTS.mx untuk menyalin tautan magnet dengan mudah.
  8. // @author Horyzontalhoror
  9. // @license MIT
  10. // @match https://yts.mx/movies/*
  11. // @match https://yts.lt/movies/*
  12. // @match https://yts.am/movies/*
  13. // @match https://yts.ag/movies/*
  14. // @grant GM_setClipboard
  15. // @icon https://raw.githubusercontent.com/Horyzontalhoror/yts_copymagnet/main/icon.png
  16. // @tags YTS.mx, magnet, torrent
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. // Fungsi membuat magnet link dari hash dan judul
  23. function magnetify(hashkey, titlekey) {
  24. return `magnet:?xt=urn:btih:${hashkey}&dn=${titlekey}&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2Fp4p.arenabg.ch%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Fopen.tracker.cl%3A1337%2Fannounce`;
  25. }
  26.  
  27. // Fungsi menampilkan notifikasi "toast"
  28. function showToast(message, icon = "🎉") {
  29. const toast = document.createElement('div');
  30. toast.innerHTML = `<span style="margin-right: 8px;">${icon}</span>${message}`;
  31. Object.assign(toast.style, {
  32. position: 'fixed',
  33. bottom: '20px',
  34. right: '20px',
  35. padding: '10px 15px',
  36. background: '#00e054',
  37. color: 'white',
  38. borderRadius: '5px',
  39. fontWeight: 'bold',
  40. boxShadow: '0 0 10px rgba(0,0,0,0.3)',
  41. zIndex: 10000,
  42. opacity: '1',
  43. display: 'flex',
  44. alignItems: 'center',
  45. transition: 'opacity 0.5s ease'
  46. });
  47.  
  48. document.body.appendChild(toast);
  49.  
  50. setTimeout(() => {
  51. toast.style.opacity = '0';
  52. setTimeout(() => toast.remove(), 500);
  53. }, 3000);
  54. }
  55.  
  56. // Eksekusi saat halaman selesai dimuat
  57. window.addEventListener('load', () => {
  58. setTimeout(() => {
  59. const tLinks = Array.from(document.querySelectorAll("a[href*='torrent/download/']"));
  60.  
  61. tLinks.forEach(link => {
  62. const tHash = link.href.split("/").pop();
  63. const tTitle = encodeURIComponent(
  64. link.getAttribute("title")
  65. .replace(/^Download\s/, "")
  66. .replace(/\sTorrent$/, "")
  67. );
  68. const magnet = magnetify(tHash, tTitle);
  69.  
  70. // Ubah href menjadi magnet link
  71. link.href = magnet;
  72. link.title += " (magnet)";
  73.  
  74. // Hindari duplikasi tombol
  75. if (link.nextSibling && link.nextSibling.classList?.contains('copy-magnet-btn')) return;
  76.  
  77. // Buat tombol "Copy Magnet"
  78. const copyBtn = document.createElement("button");
  79. copyBtn.textContent = "Copy Magnet";
  80. copyBtn.className = "copy-magnet-btn";
  81. Object.assign(copyBtn.style, {
  82. marginLeft: "10px",
  83. padding: "5px 10px",
  84. border: "none",
  85. background: "#00e054",
  86. color: "white",
  87. fontWeight: "bold",
  88. cursor: "pointer",
  89. borderRadius: "5px",
  90. fontFamily: "inherit"
  91. });
  92.  
  93. // Aksi salin magnet saat diklik
  94. copyBtn.addEventListener("click", (e) => {
  95. e.preventDefault();
  96. if (typeof GM_setClipboard === "function") {
  97. GM_setClipboard(magnet);
  98. showToast("Magnet link copied!", "📎");
  99. } else {
  100. showToast("Clipboard copy failed!", "❌");
  101. }
  102. });
  103.  
  104. // Sisipkan tombol di samping link
  105. link.parentNode.insertBefore(copyBtn, link.nextSibling);
  106. });
  107. }, 1000); // Tunggu elemen muncul
  108. });
  109. })();