Greasy Fork

Hide Unsafe Direct Download Links

9/3/24 Hide Unsafe Direct Download Links

// ==UserScript==
// @name Hide Unsafe Direct Download Links
// @namespace    yyyzzz999
// @author       yyyzzz999
// @description  9/3/24 Hide Unsafe Direct Download Links
// @match        https://www.myanonamouse.net/tor/browse.php*
// @match        https://www.myanonamouse.net/index.php
// @match        https://www.myanonamouse.net/
// @version      0.2
// @icon         https://www.myanonamouse.net/pic/smilies/MoreSmilies/jumping-smiley-002.gif
// @homepage     https://greasyfork.org/en/users/705546-yyyzzz999
// @license      MIT
// @grant        none
// ==/UserScript==
/*jshint esversion: 11 */
/*eslint no-multi-spaces:0 */

//TODO: Add a warning near UTC midnight that some VIP or Site FL torrents may expire soon!

setTimeout(function() {
    'use strict';
    var DEBUG =1; // Debugging mode on (1) or off (0)
    if (DEBUG > 0) console.log('Starting Hide Unsafe Direct Download Links');
        // Select the table with class "newTorTable"
    const table = document.querySelector('table.newTorTable');

    if (table) {
        console.log('Table found:', table);
        // Select all rows starting from the 2nd row
        const rows = table.querySelectorAll('tr:nth-child(n+1)');
        console.log(`Number of rows found: ${rows.length-1}`);

        rows.forEach((row, index) => {

            if (DEBUG > 1) console.log(`Checking Row ${index + 1}`);
            const col2 = row.cells[1]; // Column 2
            const col4 = row.cells[3]; // Column 4
                if (!col2 || !col4) {
                    console.log(`Skipping row ${index } (header or invalid row)`);
                    return;
                }
            // Check if column 2 contains an image with alt="VIP" or alt="freeleech" or a span with textContent "PF"
            const hasValidImage = col2.querySelector('img[alt="VIP"], img[alt="freeleech"]');
            const hasValidSpan = Array.from(col2.querySelectorAll('span')).some(span => span.textContent.trim() === "PF");
            if (DEBUG > 1) console.log(`Row ${index + 1}: hasValidImage=${!!hasValidImage}, hasValidSpan=${hasValidSpan}`);

            if (!hasValidImage && !hasValidSpan) {
                // Remove links with title="Direct Download" in column 4
                const links = col4.querySelectorAll('a[title="Direct Download"]');
                links.forEach(link => {
                    link.remove();
                    if (DEBUG > 0 && index <=10) console.log(`Removed link in row ${index }`); // Don't show all rows in long tables
                });
            }
        });
    }
    else {
        console.log('Table not found');
    }
    if (DEBUG > 0) console.log('Finished Hide Unsafe Direct Download Links');
}, 1500); // Wait for site JS to create table