Derpibooru - Rating Info

Shows image's rating above its thumbnail on Derpibooru.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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