// ==UserScript== // @name Bangumi EpPopuVisualizer // @namespace http://bgm.tv/user/prevails // @version 0.1.5 // @description 用颜色标注ep的讨论人气 // @author "Donuts." // @match http://bgm.tv/subject/* // @match http://bgm.tv/ // @match http://bangumi.tv/subject/* // @match http://bangumi.tv/ // @match http://chii.in/subject/* // @match http://chii.in/ // @encoding utf-8 // @require http://code.jquery.com/jquery-2.2.4.min.js // @grant none // @downloadURL 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('
'); }); } 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();