vol.moe 显示分级信息

在 vol.moe 的列表页显示分级信息

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         vol.moe 显示分级信息
// @description  在 vol.moe 的列表页显示分级信息
// @version      0.1
// @match        https://vol.moe/
// @match        https://vol.moe/list/*
// @match        https://vol.moe/u/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/localforage/1.7.3/localforage.min.js
// @namespace https://greasyfork.org/users/216382
// ==/UserScript==

(function() {
    'use strict';

    const store = localforage.createInstance({
        name: "volmoer18"
    });

    function getContent(url) {
        return fetch(url).then(r => r.text())
    }

    const r18RE = /var is_r18 = "(\d)"/

    const R18 = 'r18'
    const R15 = 'r15'
    const OTHER = 'rall'

    function getIsR18(url) {
        return store.getItem(url).then((cached) => {
            if (cached) {
                return cached
            }
            return getContent(url).then(content => {
                 const rv = r18RE.exec(content)
                 if (rv && rv[1]) {
                     let flag = OTHER
                     switch (rv[1]) {
                         case '2':
                             flag = R18;
                             break;
                         case '1':
                             flag = R15;
                     }
                     store.setItem(url, flag);
                     return flag;
                 }
             })
        }, (err) => console.log(err))
    }

    document.querySelectorAll('.book_list .listbg td').forEach(td => {
        try {
            const anchor = td.querySelectorAll('a')[1]
            getIsR18(anchor.href).then(rv => {
                if (rv === R18) {
                    anchor.innerHTML = '<font class="hd_logo" id="logo_r18_2">[18限]</font>' + anchor.innerHTML
                } else if (rv == R15) {
                    anchor.innerHTML = '<font class="hd_logo" id="logo_r18">[15限]</font>' + anchor.innerHTML
                } else {
                    anchor.innerHTML = '<font class="hd_logo">[全年龄]</font>' + anchor.innerHTML
                }
            })
        } catch (e) {
            console.error(e)
        }
    })
})();