v560

Automatically scrolls to the bottom of pages with infinite scrolling and then modifies content by removing "Trump", "transgender", "Elon Musk", "MTG", "Marjorie", "SCOTUS", "Supreme Court", "MAGA", and hiding the sections containing those words

当前为 2024-12-23 提交的版本,查看 最新版本

// ==UserScript==
// @name        v560
// @namespace   http://tampermonkey.net/
// @version     1.5
// @description Automatically scrolls to the bottom of pages with infinite scrolling and then modifies content by removing "Trump", "transgender", "Elon Musk", "MTG", "Marjorie", "SCOTUS", "Supreme Court", "MAGA", and hiding the sections containing those words
// @include     https://news.google.com/*
// @grant       none
// ==/UserScript==

(function() {
    'use strict';

    // List of words to filter - easy to edit
    const wordsToFilter = [
        'trump', 'transgender', 'elon musk', 'mtg', 'marjorie',
        'scotus', 'supreme court', 'putin', 'newsmax', 'hegseth',
        'rfk', 'kennedy', 'ukraine', 'zelensky', 'migrant',
        'immigrant', 'migration', 'abortion', 'fox news', 'january 6',
        'guilfoyle', 'jan. 6', 'immigration', 'pelosi', 'republican',
        'republicans', 'dreamers', 'aoc', 'gop', 'biden',
        'inauguration', 'maga', 'democrats', 'democratic party', 'manchin', 'dems', 'democrat', 'trump\'s', 'musk\'s', 'DNC', 'Luigi', 'mangione',
      'gaetz', 'deportation', 'deportations', 'sanctuary', 'deported','ICE'
    ];

    let instancesRemoved = 0;

    function isPageStillLoading() {
        const loadingIndicators = document.querySelectorAll('.loading,.loading-spinner,.infinite-scroll-loading');
        return loadingIndicators.length > 0;
    }

    function scrollToBottom() {
        window.scrollTo(0, document.documentElement.scrollHeight);
    }

    function loadEntirePage() {
        const interval = setInterval(() => {
            scrollToBottom();
            if (!isPageStillLoading()) {
                clearInterval(interval);
            }
        }, 1000);
    }

    // Helper function to check if text contains any filtered words
    function containsFilteredWord(text) {
        const lowerText = text.toLowerCase();
        return wordsToFilter.some(word => lowerText.includes(word));
    }

    function disableAndReplaceWords() {
        const links = document.getElementsByTagName('a');
        for (let link of links) {
            if (containsFilteredWord(link.textContent) || containsFilteredWord(link.href)) {
                let blockParent = link.closest('div, p, section, article, aside, header, footer, main, nav, form');
                
                if (blockParent) {
                    const images = blockParent.getElementsByTagName('img');
                    for (let img of images) {
                        img.style.display = 'none';
                    }
                    blockParent.style.display = 'none';
                }

                link.textContent = '-';
                link.style.pointerEvents = 'none';
                link.style.color = 'gray';
                link.style.textDecoration = 'none';
                link.onclick = function(e) {
                    e.preventDefault();
                };

                instancesRemoved++;
            }
        }
    }

    function replaceWords() {
        const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
        const wordPattern = new RegExp(`\\b(${wordsToFilter.join('|').replace(/\s+/g, '\\s*')})(?:'s)?\\b`, 'gi');
        
        let node;
        while (node = walker.nextNode()) {
            const originalText = node.nodeValue;
            node.nodeValue = node.nodeValue.replace(wordPattern, 'yyy');
            
            if (originalText !== node.nodeValue) {
                instancesRemoved++;
            }
        }
    }

    function waitAndExecute(callback) {
        setTimeout(callback, 2000);
    }

    function waitForPageLoad(callback) {
        if (document.readyState === 'complete') {
            callback();
        } else {
            window.addEventListener('load', callback);
        }
    }

    function showItemsReplacedMessage() {
        const message = document.createElement('div');
        message.textContent = `${instancesRemoved}`;
        message.style.position = 'fixed';
        message.style.top = '10px';
        message.style.right = '10px';
        message.style.backgroundColor = '#4CAF50';
        message.style.color = 'white';
        message.style.padding = '10px 20px';
        message.style.borderRadius = '5px';
        message.style.zIndex = '9998';
        message.style.fontSize = '16px';
        message.style.fontWeight = 'bold';
        message.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.3)';
        document.body.appendChild(message);

        setTimeout(() => {
            message.style.transition = 'opacity 1s';
            message.style.opacity = '0';
            setTimeout(() => message.remove(), 1000);
        }, 6000);
    }

    function showDaysOfFreedomMessage() {
        const startDate = new Date('2024-12-09T00:00:00');
        const currentDate = new Date();
        const diffTime = Math.abs(currentDate - startDate);
        const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

        const message = document.createElement('div');
        message.textContent = `${diffDays}`;
        message.style.position = 'fixed';
        message.style.top = '10px';
        message.style.left = '10px';
        message.style.backgroundColor = '#4CAF50';
        message.style.color = 'white';
        message.style.padding = '10px 20px';
        message.style.borderRadius = '5px';
        message.style.zIndex = '9998';
        message.style.fontSize = '16px';
        message.style.fontWeight = 'bold';
        message.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.3)';
        document.body.appendChild(message);

        setTimeout(() => {
            message.style.transition = 'opacity 1s';
            message.style.opacity = '0';
            setTimeout(() => message.remove(), 1000);
        }, 6000);
    }

    function addReloadButton() {
        const reloadButton = document.createElement('button');
        reloadButton.textContent = 'Reload';
        reloadButton.style.position = 'fixed';
        reloadButton.style.top = '10px';
        reloadButton.style.left = '50%';
        reloadButton.style.transform = 'translateX(-50%)';
        reloadButton.style.backgroundColor = 'blue';
        reloadButton.style.color = 'white';
        reloadButton.style.border = 'none';
        reloadButton.style.padding = '10px 20px';
        reloadButton.style.fontSize = '16px';
        reloadButton.style.zIndex = '9999';
        reloadButton.addEventListener('click', () => {
            location.reload();
        });
        document.body.appendChild(reloadButton);
    }

    function addSTButton() {
        const stButton = document.createElement('button');
        stButton.textContent = 'ST';
        stButton.style.position = 'fixed';
        stButton.style.bottom = '10px';
        stButton.style.right = '10px';
        stButton.style.backgroundColor = 'red';
        stButton.style.color = 'white';
        stButton.style.border = 'none';
        stButton.style.padding = '10px 20px';
        stButton.style.fontSize = '16px';
        stButton.style.zIndex = '9999';
        stButton.addEventListener('click', () => {
            window.scrollTo({ top: 0, behavior: 'smooth' });
        });
        document.body.appendChild(stButton);
    }

    function addHideImageButton(img) {
        const hideButton = document.createElement('button');
        hideButton.textContent = 'Hide Image';
        hideButton.style.position = 'absolute';
        hideButton.style.backgroundColor = 'rgba(255, 0, 0, 0.7)';
        hideButton.style.color = 'white';
        hideButton.style.padding = '5px 10px';
        hideButton.style.border = 'none';
        hideButton.style.borderRadius = '5px';
        hideButton.style.cursor = 'pointer';
        hideButton.style.zIndex = '10000';

        hideButton.style.top = `${img.getBoundingClientRect().top + window.scrollY + 10}px`;
        hideButton.style.left = `${img.getBoundingClientRect().left + window.scrollX + 10}px`;

        img.style.position = 'relative';
        img.addEventListener('mouseover', function() {
            img.parentElement.appendChild(hideButton);
        });

        hideButton.addEventListener('click', function() {
            img.style.display = 'none';
            hideButton.remove();
        });

        img.addEventListener('mouseout', function() {
            hideButton.remove();
        });
    }

    function runProcess() {
        loadEntirePage();
        waitAndExecute(() => {
            disableAndReplaceWords();
            replaceWords();

            const images = document.querySelectorAll('img');
            images.forEach((img) => {
                addHideImageButton(img);
            });

            setTimeout(() => {
                showDaysOfFreedomMessage();
                setTimeout(() => {
                    showItemsReplacedMessage();
                }, 1000);
            }, 1000);
        });
    }

    waitForPageLoad(function() {
        setTimeout(() => {
            addReloadButton();
            addSTButton();
        }, 3000);

        runProcess();
    });

})();