// ==UserScript== // @name b站低质弹幕过滤 测试版 bilibili 哔哩哔哩 // @namespace http://tampermonkey.net/ // @version 0.0.1 // @description 低质弹幕屏蔽测试版,屏蔽无意义的弹幕如“哈哈哈哈”,刷屏弹幕如“完结撒花”。随便写的脚本,虽然搞过nlp,但都是语义建模,很少接触表达建模,而且js也不循序太高的复杂度,所以目前用的是简单测词频法,后续还会慢慢优化。 // @author You // @match https://www.bilibili.com/video/* // @grant none // @downloadURL none // ==/UserScript== function GET(url,fun=function(x){console.log(x.responseText)}){ const xhr = new XMLHttpRequest() xhr.open('get',url) xhr.send() xhr.onreadystatechange = function(){ if(xhr.readyState == 4 && xhr.status == 200){ fun(xhr) } } } (function() { 'use strict'; const cid = window.__INITIAL_STATE__.videoData.cid console.log('video cid',cid) const danmuURL = 'https://api.bilibili.com/x/v1/dm/list.so?oid='+cid console.log('danmu url:',danmuURL) const k = 8 //屏蔽强度 1~10,10最强 GET(danmuURL,function(xhr){ const xml = xhr.responseXML xml.getElementsByTagName('d') const danmuList = [] for(let d of xml.getElementsByTagName('d')){ const danmu = d.textContent.replace(/[~!@#$(),.?''""!(),。?“”‘’;:;: +-=\\、·…]/g,'').toLowerCase() if(!!danmu){ danmuList.push(danmu+'#') } } console.log(danmuList) const char_dict = {} const word_dict = {} let total_char = 0 for(let danmu of danmuList){ for(let i=0;i