您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
弹幕显示名称,右键弹幕高亮uid
当前为
// ==UserScript== // @name 弹幕显示名称 // @namespace http://tampermonkey.net/ // @version 0.4 // @description 弹幕显示名称,右键弹幕高亮uid // @author You // @match https://live.bilibili.com/* // @grant GM_setValue // @grant GM_getValue // @run-at document-end // ==/UserScript== (function() { 'use strict'; document.body.insertAdjacentHTML('afterBegin',`<style> nav,.wrap{ width: auto !important; max-width: 1400px !important; margin: auto;} .wrap>ul{ display: flex !important; flex-wrap: wrap; justify-content: center;} .bilibili-danmaku i{font-size:60%;text-decoration: underline;opacity:1} .bilibili-danmaku .chat-history-panel {display:inline-block;background:none;} .bilibili-danmaku .chat-history-panel *{margin: 0 1px 0 2px !important; padding:0 !important; vertical-align: middle;} .highline{ outline: 3px solid; } </stype>`); //迁移数据 let localkey = 'iikmkjmpaadaobahmlepeloendndfphd.弹幕显示名称'; let localvalue = JSON.parse(localStorage[localkey]||'null'); if(localvalue){ GM_setValue('userlist', localvalue); delete localStorage[localkey]; } //本地储存 let localdata = new Proxy( GM_getValue('userlist',{}),{ set(self,key,val){ if(val===null) delete self[key]; else self[key] = val; GM_setValue('userlist', self); return true; } }); //高亮边框&右键 let menuObserver = new MutationObserver((mu,obs)=>{ mu.forEach(xx=>{ let el = xx.addedNodes[0]; if(!el||el.className.trim()!="context-menu-submenu"){ return; } let ul = el.querySelector('.context-menu-ul'); let uid = el.querySelector('[href*=http]').getAttribute('href').match(/\d+$/)[0]; let name = document.querySelector(`.chat-history-list [data-uid="${uid}"]`).dataset.uname; el.setAttribute('title',name); ul.insertAdjacentHTML('beforeEnd',`<li class="context-menu-function"><a data-uid='${uid}' data-name='${name}' class="xx">高亮uid/取消高亮</a></li>`); }); document.querySelectorAll('.bilibili-live-player-context-menu-container .xx').forEach(xx=>{ xx.onclick=xxx=>{ xxx = xxx.target; localdata[xxx.dataset.uid] = localdata[xxx.dataset.uid]?null:xxx.dataset.name; document.querySelectorAll(`.bilibili-live-player-video-danmaku [data-uid="${xxx.dataset.uid}"]`).forEach(xx=>{ localdata[xxx.dataset.uid] ? xx.classList.add('highline') : xx.classList.remove('highline') ; }); document.querySelectorAll('.bilibili-live-player-context-menu-container').forEach(xx=>{ xx.setAttribute('style','top: -9999px; left: -9999px;'); }) }; }); }); //名称备注 let danmakuObserver = new MutationObserver((mu, obs) => { document.querySelectorAll('.bilibili-live-player-video-danmaku>:not([style*=done])').forEach(xx=>{ if(xx.querySelector('i')){ xx.setAttribute('style',xx.getAttribute('style')+(';done')); return; } let tt = xx.innerHTML.replaceAll('\\','\\\\').replaceAll('"','\\"'); let lw = document.querySelectorAll(`.chat-items>.danmaku-item[data-danmaku*="${tt}"]:not([style*=done])`); if(lw.length){ lw = lw[lw.length-1]; let ic = lw.querySelector('[class*=-icon]:empty');//加图标 ic && (xx.innerHTML+= `<b class='chat-history-panel'><b class='chat-history-list'><b class='chat-item danmaku-item'>${ic.outerHTML}</b></b></b>`); xx.innerHTML+=`<i style=';'>${lw.dataset.uname}</i>`; let ts = xx.getAttribute('style').match(/transform\s+([\d\.]+)/); ts = parseFloat( ts&&ts[1] ); ts && setTimeout(xxx=>{ xx.setAttribute('style',xx.getAttribute('style')+`;display:none`); xx.classList.remove('highline'); },ts*1000); lw.setAttribute('style',lw.getAttribute('style')+(';done')); xx.setAttribute('style',xx.getAttribute('style')+(';done')); xx.setAttribute('data-uid',lw.dataset.uid); localdata[xx.dataset.uid] && xx.classList.add('highline') ; } }); }); //活动页要等菜单加载? setTimeout(xx=>{ document.querySelectorAll('.bilibili-live-player-context-menu-container>ul').forEach(dm=>{ menuObserver.observe(dm, { attributes: false, childList: true, subtree: false } ); }) document.querySelectorAll('.chat-items,.bilibili-live-player-video-danmaku').forEach(dm=>{ danmakuObserver.observe(dm, { attributes: false, childList: true, subtree: true } ); }); },500); })();