Derpibooru - Rating Info

Shows image's rating above its thumbnail on Derpibooru.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Derpibooru - Rating Info
// @description Shows image's rating above its thumbnail on Derpibooru.
// @namespace   derpibooru_ratinginfo
// @include     /^https?:\/\/(www\.)?(derpiboo(ru\.org|\.ru)|trixiebooru\.org).*$/
// @version     20171120
// ==/UserScript==

(function() {
    "use strict";

    function addStyle(css) {
        var style = document.createElement('style');
        style.textContent = css;
        document.head.appendChild(style);
    }

    let isRatingTag = tag => tags.includes(tag);

    addStyle('.RI_rating > * {padding-right: 3px; font-weight: bold}');

    const conf = [
        ['safe',             'S',       '#67AF2B'],
        ['explicit',         'E',       '#CF0001'],
        ['questionable',     'Q',       '#C4B246'],
        ['suggestive',       'Sg',      '#C4B246'],
        ['grimdark',         'GD',      '#5E0000'],
        ['semi-grimdark',    'S-GD',    '#5E0000'],
        ['grotesque',        'Gr',      '#000000']
    ];

    const tags = conf.map(value => value[0]);

    for (const tag of conf) {
        addStyle('.RI_' + tag[0] + ':after {content: "' + tag[1] + '"; color:' + tag[2] + '}');
    }

    for (const mediaBox of document.getElementsByClassName("media-box")) {
        const infoBoxEl = mediaBox.getElementsByClassName("media-box__header") [0];
        const imgTags = mediaBox.getElementsByClassName("image-container") [0].dataset.imageTagAliases.split(", ");
        const rTags = imgTags.filter(isRatingTag);

        const ratingNode = document.createElement("span");
        ratingNode.className = "RI_rating";

        for (const rTag of rTags) {
            const tagNode = document.createElement('span');
            tagNode.className  = "RI_" + rTag;
            ratingNode.appendChild(tagNode);
        }

        infoBoxEl.insertBefore(ratingNode, infoBoxEl.firstChild);
    }
})();