TorrentGalaxyScript

Torrentgalaxy Special Offer Adblocker + Lazy Dark Theme

目前為 2024-01-19 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TorrentGalaxyScript
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Torrentgalaxy Special Offer Adblocker + Lazy Dark Theme
// @author       nour
// @match        https://torrentgalaxy.to/*
// @match        https://torrentgalaxy.to/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    // Set darkthemev2 to 0 if you want to disable it
    localStorage.setItem('darkthemev2', '1');

    // Helper function to convert RGB to HEX
    function rgbToHex(rgb) {
        // Convert an RGB color value to HEX
        let [r, g, b] = rgb.match(/\d+/g).map(Number);
        return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();
    }

    // Function to replace a specific color across all elements
    function replaceColor(oldColor, newColor) {
        // Normalize oldColor to HEX if it is in RGB format
        if (oldColor.includes('rgb')) {
            oldColor = rgbToHex(oldColor);
        }

        // Ensure oldColor is uppercase since the conversion returns an uppercase HEX code
        oldColor = oldColor.toUpperCase();

        const allElements = document.querySelectorAll('*');
        allElements.forEach(element => {
            const computedStyle = window.getComputedStyle(element);

            // Replace the old color with the new color in all color-related properties
            ['color', 'backgroundColor', 'borderColor'].forEach(property => {
                // Normalize backgroundColor to HEX if it is in RGB format
                let elementColor = computedStyle[property];
                if (elementColor.includes('rgb')) {
                    elementColor = rgbToHex(elementColor);
                }

                if (elementColor === oldColor) {
                    element.style[property] = newColor;
                }
            });
        });
    }


    function removeSpecificDivsAndLogCount() {
        const links = document.querySelectorAll('div.hotpicks a[href^="/hub.php"]');
        if (links.length === 0) {
            console.log('No div.hotpicks elements found with an \'a\' having href starting with \'/hub.php\'.');
        } else {
            console.log(`Number of div.hotpicks elements found with an 'a' having href starting with '/hub.php': ${links.length}`);
            links.forEach(link => {
                let hotpicksDiv = link.closest('div.hotpicks');
                if (hotpicksDiv) {
                    hotpicksDiv.remove();
                }
            });
        }
    }

    // Wait for the document to be fully loaded before observing for changes
    function waitForDocumentBody() {
        if (document.body) {
            if (localStorage.getItem('darkthemev2') === '1') {
            replaceColor('rgb(210, 194, 172)', 'rgb(255, 255, 255)');
            replaceColor('rgb(120, 144, 78)', 'rgb(0, 0, 0)');
            replaceColor('rgb(48, 58, 31)', 'rgb(18, 18, 18)');
            replaceColor('rgb(50, 47, 64)', 'rgb(18, 18, 18)');
            replaceColor('rgb(180, 174, 164)', 'rgb(255, 255, 255)');
            replaceColor('rgb(122, 113, 100)', 'rgb(0, 0, 0)');
            replaceColor('rgb(180, 174, 164)', 'rgb(255, 255, 255)');
            replaceColor('rgb(180, 174, 164)', 'rgb(255, 255, 255)');
            replaceColor('rgb(180, 174, 164)', 'rgb(255, 255, 255)');
            replaceColor('rgb(180, 174, 164)', 'rgb(255, 255, 255)');

            replaceColor('#3c4827', '#000000');
            replaceColor('#d8cab7', '#ffffff');
            replaceColor('#s2f2f2f', '#000000');
            replaceColor('#3f3b50', '#000000');
            replaceColor('#5d87ab', '#ffffff');
            replaceColor('#819FD1', '#ffffff');
            replaceColor('#2f2f2f', '#000000');
            replaceColor('#383838', '#0a0a0a');
            replaceColor('#353535', '#0a0a0a');
            replaceColor('#444444', '#121212');
            replaceColor('#423b48', '#060606');
            replaceColor('#6e236f', '#060606');
            replaceColor('#353146', '#0a0a0a');
            replaceColor('#3c4827', '#000000');
            replaceColor('#3f3b50', '#121212');
            replaceColor('#353146', '#0a0a0a');
        }
            // Configuration of the observer
            const config = { childList: true, subtree: true };

            // Create a MutationObserver to handle dynamically added content
            const observer = new MutationObserver(mutations => {
                mutations.forEach(mutation => {
                    if (mutation.addedNodes) {
                        removeSpecificDivsAndLogCount();
                    }
                });
            });

            // Start observing the document for added nodes
            observer.observe(document.body, config);

            // Initial removal of matching divs and log count or 'none found'
            removeSpecificDivsAndLogCount();
        } else {
            // If the body isn't available yet, set a timeout to try again
            window.setTimeout(waitForDocumentBody, 50);
        }
    }

    // Start the script
    waitForDocumentBody();
})();