条目页显示VIB排名
当前为
// ==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);
}
}
});
}
})();