AudiobookBay Add Magnets Without Login

Add a magnet link next to the InfoHash

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AudiobookBay Add Magnets Without Login
// @version      1.0
// @description  Add a magnet link next to the InfoHash
// @author       Rust1667
// @match        https://audiobookbay.lu/abss/*
// @icon         https://icons.duckduckgo.com/ip3/audiobookbay.lu.ico
// @grant        none
// @namespace https://greasyfork.org/users/980489
// ==/UserScript==

(function() {
    'use strict';

    // Tracker URL to include in the magnet link
    const tracker = 'http://tracker.files.fm:6969/announce';

    // Magnet icon image URL
    const magnetIconUrl = 'https://cdn-icons-png.flaticon.com/512/5405/5405497.png';

    // Get the torrent name from the title element with selector '.postTitle > h1:nth-child(1)'
    const titleElement = document.querySelector('.postTitle > h1:nth-child(1)');
    const torrentName = titleElement ? titleElement.innerText.trim() : 'Unnamed Torrent';

    // Find all table rows in the document
    const rows = document.querySelectorAll('tr');

    // Iterate over the rows to find the one containing "Info Hash:"
    rows.forEach(row => {
        const cells = row.querySelectorAll('td');

        if (cells.length === 2 && cells[0].innerText.trim() === 'Info Hash:') {
            // The second cell contains the hash
            const infoHash = cells[1].innerText.trim();

            // Generate the magnet link with the tracker and the torrent name
            const magnetLink = `magnet:?xt=urn:btih:${infoHash}&tr=${encodeURIComponent(tracker)}&dn=${encodeURIComponent(torrentName)}`;

            // Create a plain text node for the info hash
            const infoHashText = document.createTextNode(infoHash);

            // Create an image element for the magnet icon
            const magnetIconElement = document.createElement('img');
            magnetIconElement.src = magnetIconUrl;
            magnetIconElement.alt = 'Magnet Link';
            magnetIconElement.style = 'width: 20px; height: 20px; vertical-align: middle; margin-left: 10px;'; // Adjust size and spacing

            // Create a clickable link for the magnet icon
            const magnetLinkElement = document.createElement('a');
            magnetLinkElement.href = magnetLink;
            magnetLinkElement.appendChild(magnetIconElement);  // Make the image clickable

            // Clear the existing hash text in the cell
            cells[1].innerHTML = '';

            // Add the plain hash text and the clickable magnet icon to the second cell
            cells[1].appendChild(infoHashText);  // Insert the plain hash text
            cells[1].appendChild(magnetLinkElement);  // Insert the clickable magnet icon
        }
    });

})();