NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @namespace https://openuserjs.org/users/yasama018 // @name Bilibili 弹幕统计 // @description B站弹幕信息统计工具 // @copyright 2018, yasama018 (https://openuserjs.org/users/yasama018) // @license MIT // @version 0.0.1 // @match https://www.bilibili.com/video/av* // @match https://www.bilibili.com/bangumi/play/* // ==/UserScript== // ==OpenUserJS== // @author yasama018 // ==/OpenUserJS== /* 统计功能模块 1.统计所有用户,以及用户发送弹幕次数,显示前30名[显名] 2.统计同一个单词出现次数 前30位 [=1不统计] 3.弹幕列表[定位到指定弹幕 并可选择显名] 显示统计结果功能模块 1.列表UI-1 2.列表UI-2 3.列表UI-3 */ (function () { /* global function */ function getCookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); } } return ""; } function userdm(userhash) { this.userhash=userhash; this.dmcount=0; this.dmlist=[]; this.userid=-1; this.setuserid=function(id) { this.userid=id; }; this.adddm=function(dm) { this.dmlist.push(dm); this.dmcount++; }; } function Dictionary() { var items = {}; this.has = function (key) { return key in items; }; this.set = function (key, value) { items[key] = value; }; this.remove = function (key) { if (this.has(key)) { delete items[key]; return true; } return false; }; this.get = function (key) { return this.has(key) ? items[key] : undefined; }; this.values = function () { var values = []; for (var k in items) { if (this.has(k)) { values.push(items[k]); } } return values; }; this.clear = function () { items = {}; }; this.size = function () { var count = 0; for (var prop in items) { if (items.hasOwnProperty(prop)) { ++count; } } return count; }; this.getItems = function () { return items; }; } /* DMTOOL LIB */ var DMTool = {}; DMTool.LoadXML = function (xmlFile) { var xmlDoc; if (window.ActiveXObject) { xmlDoc = new ActiveXObject('Microsoft.XMLDOM');//IE浏览器 xmlDoc.async = false; xmlDoc.load(xmlFile); } else if ((isFirefox = navigator.userAgent.indexOf("Firefox")) > 0) { //火狐浏览器 //else if (document.implementation && document.implementation.createDocument) {//这里主要是对谷歌浏览器进行处理 xmlDoc = document.implementation.createDocument('', '', null); xmlDoc.load(xmlFile); } else { //谷歌浏览器 var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET", xmlFile, false); xmlhttp.send(null); if (xmlhttp.readyState == 4) { xmlDoc = xmlhttp.responseXML.documentElement; } } return xmlDoc; }; DMTool.CheckXMLDocObj = function (xmlFile) { var xmlDoc = DMTool.LoadXML(xmlFile); if (xmlDoc == null) { alert('您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!'); //window.location.href = '../err.html'; } return xmlDoc; }; DMTool.getDMXML = function (cid) { var xmlDoc = DMTool.CheckXMLDocObj("https://comment.bilibili.com/" + cid + ".xml");// var nodes = xmlDoc.getElementsByTagName('d'); var dmlist = []; var usermap=[]; var userdmList=[]; for (var i = 0; i < nodes.length; i++) { var pp = nodes[i].getAttribute('p').split(','); var dm = { // color: parseInt(pp[3]), // fontsize: parseInt(pp[2]), // mode: parseInt(pp[1]),//dm location msg: nodes[i].innerHTML, userid_hash: ''+pp[6], userid:-1, // pool: parseInt(pp[5]),//pool=0 // progress: parseInt(parseFloat(pp[0]) * 1000),//time }; dmlist.push(dm); } function compare(val1,val2){ return val2.length-val1.length; } // user_dm_count.sort(); //user_dm_list=user_dm_list.sort(compare); return {dmlist:dmlist}; }; DMTool.UIInit = function () { $("body").append("<div id='dmby'><div style='clear:left;text-align:center'><label>当前视频CID:</label><label id='curcid'></label></div><div style='clear:left;text-align:center'></div><button id='btn_dmtj'>显示统计信息</button></div>"); $("body").append("<style>#btn_dmby{display:block;width:100px;height:32px;text-align:center;clear:left;}#dmby{border:1px blue solid;position:fixed;left:0px;top:50%;z-index:999;}</style>"); $("#btn_dmtj").click(function () { var Total=DMTool.getDMXML(cid); console.log(Total); }); if (window.__INITIAL_STATE__) console.log(window.__INITIAL_STATE__); if ("undefined" == typeof cid) { } else { $("#curcid").html(cid); } }; DMTool.UI_Ad_Erase = function () { $(".ad-f").hide(); $(".v_small").hide(); $("#arc_toolbar_report").hide(); $("#recommend_report").hide(); $(".reply-notice").hide(); }; $(function () { $.support.cors = true; DMTool.UI_Ad_Erase(); DMTool.UIInit(); }); })();