VIBRankFetch

条目页显示VIB排名

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         VIBRankFetch
// @namespace    https://jirehlov.com
// @version      0.1.3
// @description  条目页显示VIB排名
// @include      /^https?://(bangumi|bgm|chii).(tv|in)/subject/.*$/
// @author       Jirehlov
// @grant        none
// @license      MIT
// ==/UserScript==
(function () {
	'use strict';
	function getVIB(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 api errors');
			}
		});
	}
	const idMatch = window.location.pathname.match(/\/subject\/(\d+)/);
	if (idMatch) {
		const id = idMatch[1];
		getVIB(id).then(response => {
			const vibRank = response.VIB_rank;
			const vibScore = response.VIB_score;
			if (vibRank !== null && vibRank !== 0) {
				const globalScore = document.querySelector('.global_score');
				if (globalScore) {
					const firstDiv = globalScore.querySelector('div');
					if (firstDiv) {
						const spanElement = document.createElement('span');
						spanElement.style.display = 'block';
						spanElement.classList.add('ScoreBlock');
						while (globalScore.firstChild !== firstDiv) {
							spanElement.appendChild(globalScore.firstChild);
						}
						globalScore.insertBefore(spanElement, firstDiv);
						const clonedSpanElement = spanElement.cloneNode(true);
						globalScore.insertBefore(clonedSpanElement, firstDiv);
						const ins1 = document.createElement('span');
						ins1.textContent = '表面评分 ';
						spanElement.prepend(ins1);
						const ins2 = document.createElement('span');
						ins2.textContent = 'VIB评分 ';
						clonedSpanElement.prepend(ins2);
						clonedSpanElement.children[1].textContent = Number(vibScore).toFixed(4);
						const stringOptions = [
							'不忍直视',
							'很差',
							'差',
							'较差',
							'不过不失',
							'还行',
							'推荐',
							'力荐',
							'神作',
							'超神作'
						];
						const selectedString = stringOptions[Math.round(vibScore) - 1];
						clonedSpanElement.children[3].textContent = selectedString;
						const vibDiv = document.createElement('div');
						vibDiv.innerHTML = '<small class="grey">VIB Ranked:</small><small class="alarm">#' + vibRank + '</small>';
						vibDiv.style.marginLeft = '38px';
						globalScore.insertBefore(vibDiv, firstDiv);
					}
				}
			}
		});
	}
}());