Derpibooru - Rating Info

Shows image's rating above its thumbnail on Derpibooru.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
    }
})();