Remove Blacklisted Images

Removes blacklisted images from the DOM on rule34.xxx based on a tag blacklist stored in cookies.

Versión del día 23/8/2024. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name        Remove Blacklisted Images
// @namespace   http://tampermonkey.net/
// @version     1.1
// @description Removes blacklisted images from the DOM on rule34.xxx based on a tag blacklist stored in cookies.
// @author      Dramorian
// @match       https://rule34.xxx/index.php?page=post*
// @match       https://rule34.xxx/index.php?page=favorites*
// @match       https://rule34.xxx/index.php?page=comment*
// @exclude     https://rule34.xxx/index.php?page=post&s=view*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=rule34.xxx
// @grant       none
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to get the tag blacklist from cookies
    function getTagBlacklist() {
        const cookie = document.cookie
            .split('; ')
            .find(row => row.startsWith('tag_blacklist='));
        return cookie ?
            decodeURIComponent(cookie.split('=')[1]).split('%20') : [];
    }

    // Function to remove elements matching the blacklist criteria
    function removeBlacklistedElements() {
        const tagBlacklist = getTagBlacklist();
        if (tagBlacklist.length === 0) {
            console.log('No blacklist found in cookies.');
            return;
        }

        let removedCount = 0;

        // Function to check if the title contains any exact blacklist tag
        function containsExactTag(title, blacklist) {
            return blacklist.some(tag => {
                const regex = new RegExp(`\\b${tag}\\b`, 'i');
                return regex.test(title);
            });
        }

        // Check for post page by detecting spans with the class blacklisted-image
        const postSpans = document.querySelectorAll('span.blacklisted-image');
        if (postSpans.length > 0) {
            postSpans.forEach(span => {
                span.remove();
                removedCount++;
            });
        }

        // Check for favorites page by detecting images with titles
        const favoriteImages = document.querySelectorAll('img[title]');
        if (favoriteImages.length > 0) {
            favoriteImages.forEach(img => {
                const imgTitle = img.getAttribute('title');
                if (imgTitle && containsExactTag(imgTitle, tagBlacklist)) {
                    const spanElement = img.closest('span');
                    if (spanElement) {
                        spanElement.remove();
                        removedCount++;
                    }
                }
            });
        }

        // Check for comment page by detecting images in the comment structure
        const commentImages = document.querySelectorAll('div[id^="p"] > div.col1.thumb > a > img');
        if (commentImages.length > 0) {
            commentImages.forEach(img => {
                const imgTitle = img.getAttribute('title');
                if (imgTitle && containsExactTag(imgTitle, tagBlacklist)) {
                    const divElement = img.closest('div[id^="p"]');
                    if (divElement) {
                        divElement.remove();
                        removedCount++;
                    }
                }
            });
        }

        const message = removedCount > 0 ?
            `Blacklisted images removed: ${removedCount}` :
            'Blacklisted images have not been found';

        const contentElement = document.getElementById('content');
        if (contentElement) {
            const messageElement = document.createElement('div');
            messageElement.textContent = message;
            contentElement.insertAdjacentElement('afterbegin', messageElement);
        }
    }

    removeBlacklistedElements();
})();