Greasy Fork is available in English.
用颜色标注ep的讨论人气
当前为
// ==UserScript==
// @name Bangumi EpPopuVisualizer
// @namespace http://bgm.tv/user/prevails
// @version 0.1.6
// @description 用颜色标注ep的讨论人气
// @author "Donuts."
// @match http://bgm.tv/subject/*
// @match http://bgm.tv/
// @match https://bgm.tv/subject/*
// @match https://bgm.tv/
// @match http://bangumi.tv/subject/*
// @match http://bangumi.tv/
// @match http://chii.in/subject/*
// @match http://chii.in/
// @encoding utf-8
// @grant none
// ==/UserScript==
function main() {
var $uls = $('ul.prg_list');
$uls.each(function () {
var $lis = $('li:not(.subtitle)', this);
addVisualBar($lis);
});
}
function addVisualBar($lis) {
var ids = [];
$lis.each(function () {
var $a = $(this).find('a');
var id = $a[0].id.replace("prg_", '');
ids.push(id);
});
var values = ids.map(getEpValue);
var max = values.reduce(function (a, b) {
return Math.max(a, b);
});
values = values.map(getColor(max));
$lis.each(function (index) {
var $li = $(this);
$li.prepend('<div style="height:3px;width:85%;background:' + values[index] + ';"></div>');
});
}
function getEpValue(id) {
var value = $("#subject_prg_content > #prginfo_" + id + " > span > span > small.na").html();
value = value.substring(2, value.length - 1);
return parseInt(value);
}
function getColor(max) {
var rfactor = (255 - 0xff) / max;
var gfactor = (255 - 0x80) / max;
var bfactor = (255 - 0x40) / max;
return function (v) {
var r = 255 - Math.floor(v * rfactor);
var g = 255 - Math.floor(v * gfactor);
var b = 255 - Math.floor(v * bfactor);
return "rgb(" + r + "," + g + "," + b + ")";
};
}
main();