VIBRankFetch

条目页显示VIB排名

目前為 2023-09-07 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
                    }
                }
            });
    }
})();