1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
(function () { "use strict";
function getGalleryId() { const match = location.pathname.match(/\/g\/(\d+)/); return match ? match[1] : null; }
function getToken() { const match = location.pathname.match(/\/(\w{10})\/?$/); return match ? match[1] : null; }
function copyToClipboard(text) { const textarea = document.createElement("textarea"); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand("copy"); document.body.removeChild(textarea); }
function createInfoNode(text, isMagnetLink = false) { const infoNode = document.createElement("p"); infoNode.style.wordBreak = "break-all"; infoNode.innerText = text; if (isMagnetLink) { infoNode.style.cursor = "pointer"; infoNode.addEventListener("click", () => { copyToClipboard(text); }); } return infoNode; }
function createSeparatorNode() { const separator = document.createElement("hr"); return separator; }
function displayInfo(container, text, isMagnetLink = false) { const infoNode = createInfoNode(text, isMagnetLink); container.appendChild(infoNode); }
function parseResponse(response, container) { const parser = new DOMParser(); const doc = parser.parseFromString(response.responseText, "text/html"); const tables = doc.getElementsByTagName("table");
if (tables.length === 0) { displayInfo(container, "0 torrents were found for this gallery."); } else { Array.from(tables).forEach((table) => { const cells = table.getElementsByTagName("td"); if (cells.length > 1) { const separator = createSeparatorNode(); container.appendChild(separator);
const sizeText = cells[1].innerText; const magnetLink = table.querySelector("a").href; const magnetHash = magnetLink.match(/[\w\d]{40}/)[0]; const magnetText = `magnet:?xt=urn:btih:${magnetHash}`;
displayInfo(container, sizeText); displayInfo(container, magnetText, true); } }); } }
function main() { const galleryId = getGalleryId(); const token = getToken(); const targetNode = document.querySelector("p.g2:not(.gsp)");
if (galleryId && token && targetNode) { targetNode.style.paddingBottom = "20px";
const container = document.createElement("div"); container.style.maxHeight = "200px"; container.style.overflowY = "auto"; targetNode.insertAdjacentElement("afterend", container);
const baseURL = `https://${location.hostname}/gallerytorrents.php?gid=${galleryId}&t=${token}`;
GM_xmlhttpRequest({ method: "GET", url: baseURL, overrideMimeType: "text/html; charset=UTF-8", onload: (response) => parseResponse(response, container), }); } }
main(); })();
|