Sleazy Fork is available in English.

Gelbooru Respect Tag Blacklist Everywhere

Properly hides image thumbnails that have user-blacklisted tags on Profile, Saved Searches, and other users' Favorites pages.

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

// ==UserScript==
// @name         Gelbooru Respect Tag Blacklist Everywhere
// @namespace    http://tampermonkey.net/
// @version      3.0.0
// @description  Properly hides image thumbnails that have user-blacklisted tags on Profile, Saved Searches, and other users' Favorites pages.
// @author       Xerodusk
// @homepage     https://greasyfork.org/en/users/460331-xerodusk
// @include      https://gelbooru.com/index.php*s=saved_search*
// @include      https://gelbooru.com/index.php*page=account*s=profile*
// @include      https://gelbooru.com/index.php*page=favorites*
// @grant        none
// @icon         https://gelbooru.com/favicon.png
// ==/UserScript==
/* jshint esversion: 6 */

/*   configuration   */

// Whether to hide blacklisted image placeholders on page
// If true:  Will blur out blacklisted images, but not remove them completely (like main gallery pages)
// If false: Will completely remove blacklisted image thumbnails from the page (like search pages)
const removeBlacklistedThumbnailsEntirely = false;

/*-------------------*/

// Get cookie by name
// From https://www.w3schools.com/js/js_cookies.asp
function getCookie(cname) {
    'use strict';

    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

// Get current user's user ID, if exists
function getUserID() {
    'use strict';

    // Get user ID from cookie
    let userID = getCookie('user_id');

    return userID ? userID : -1;
}

// Get tag blacklist as list of strings
function GetBlockedTags() {
    'use strict';

    // Get blocked tags string from cookie
    let blockedTags = getCookie('tag_blacklist');

    // Split tags into list
    blockedTags = blockedTags.split('%20');

    return blockedTags;
}

// Decode encoded characters in tags for proper matching
function htmlDecode(input) {
    'use strict';

    let tempElem = document.createElement('div');
    tempElem.innerHTML = input;
    return tempElem.childNodes.length === 0 ? "" : tempElem.childNodes[0].nodeValue;
}

// Get tags list for image thumbnail as list of strings
function GetImageTags(imageThumb) {
    'use strict';

    let tagsString = [];
    if (imageThumb.getElementsByTagName('img')[0].getAttribute('title')) {
        tagsString = imageThumb.getElementsByTagName('img')[0].getAttribute('title');
    } else {
        tagsString = imageThumb.getElementsByTagName('img')[0].getAttribute('alt');
    }
    tagsString = htmlDecode(tagsString);
    let tagsList = tagsString.split(' ');

    return tagsList;
}

// Mark images as blacklisted for saves searches page
function MarkSavedSearchBlacklistedImages(blockedTags) {
    'use strict';
    // Get all image thumbnails on page
    let imageThumbs = document.querySelectorAll('.container-fluid > span.thumb');

    // Apply blacklist to image thumbnails
    imageThumbs.forEach(imageThumb => {
        let tags = GetImageTags(imageThumb);
        if (tags.some(tag => blockedTags.indexOf(tag) >= 0)) {
            if (removeBlacklistedThumbnailsEntirely) {
                imageThumb.parentElement.removeChild(imageThumb);
            } else {
                imageThumb.classList.add('blacklisted');
            }
        }
    });
}

// Mark images as blacklisted for profile page
function MarkProfileBlacklistedImages(blockedTags) {
    'use strict';
    // Get all image thumbnails on page
    let imageThumbs = [...document.getElementsByClassName('profileThumbnailPadding')];

    // Apply blacklist to image thumbnails
    imageThumbs.forEach(imageThumb => {
        let tags = GetImageTags(imageThumb);
        if (tags.some(tag => blockedTags.indexOf(tag) >= 0)) {
            if (removeBlacklistedThumbnailsEntirely) {
                imageThumb.parentElement.removeChild(imageThumb);
            } else {
                imageThumb.classList.add('blacklisted');
            }
        }
    });
}

// Mark images as blacklisted for other users' favorites pages
function MarkFavoritesBlacklistedImages(blockedTags, searchParams) {
    'use strict';

    // Check if it is your own favorites before applying anything
    const userID = getUserID();
    if (searchParams.has('id') && searchParams.get('id') == userID) {
        return;
    }

    // Get all image thumbnails on page
    let imageThumbs = document.querySelectorAll('span.thumb');

    // Apply blacklist to image thumbnails
    imageThumbs.forEach(imageThumb => {
        let tags = GetImageTags(imageThumb);
        if (tags.some(tag => blockedTags.indexOf(tag) >= 0)) {
            if (removeBlacklistedThumbnailsEntirely) {
                imageThumb.parentElement.removeChild(imageThumb);
            } else {
                imageThumb.classList.add('blacklisted');
            }
        }
    });

    let css = document.createElement('style');

    css.innerHTML = `
        .blacklisted {
            opacity: .2;
            filter: blur(10px);
        }
    `;

    document.head.appendChild(css);
}


// Mark images as blacklisted
function MarkBlacklistedImages(blockedTags) {
    'use strict';

    let searchParams = new URLSearchParams(window.location.search);

    if (!searchParams.has('s')) {
        return false;
    }
    if (searchParams.get('s') === 'saved_search') {
        MarkSavedSearchBlacklistedImages(blockedTags);
    } else if (searchParams.get('s') === 'profile') {
        MarkProfileBlacklistedImages(blockedTags);
    } else {
        MarkFavoritesBlacklistedImages(blockedTags, searchParams);
    }
}

(function() {
    'use strict';

    let blockedTags = GetBlockedTags();
    if (blockedTags) {
        MarkBlacklistedImages(blockedTags);
    }
})();