VIBRankFetch

条目页显示VIB排名

当前为 2023-09-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         VIBRankFetch
// @namespace    https://jirehlov.com
// @version      0.1.1
// @description  条目页显示VIB排名
// @include      /^https?://(bangumi|bgm|chii).(tv|in)/subject/.*$/
// @author       Jirehlov
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function getVIBRank(id) {
        return fetch(`https://api.jirehlov.com/vib/${id}`, {
            method: 'GET',
            redirect: 'manual'
        })
            .then(response => {
                if (response.status === 200) {
                    return response.json();
                } else {
                    throw new Error('VIB rank api: Response status is not 200 OK');
                }
            })
            .then(data => data.VIB_rank)
            .catch(error => {
                console.error('Error fetching VIB rank:', error);
                return null;
            });
    }

    const idMatch = window.location.pathname.match(/\/subject\/(\d+)/);
    if (idMatch) {
        const id = idMatch[1];
        getVIBRank(id)
            .then(vibRank => {
                if (vibRank !== null && vibRank !== 0) {
                    const lastDiv = document.querySelector('.global_score > div:last-child');
                    if (lastDiv) {
                        const vibDiv = document.createElement('div');
                        vibDiv.innerHTML = '<small class="grey">Very Important Bangumier Ranked:</small><small class="alarm">#' + vibRank + '</small>';
                        vibDiv.style.marginLeft = '38px';
                        lastDiv.after(vibDiv);
                    }
                }
            });
    }
})();