下载一个油猴插件 http://tampermonkey.net
要匹配的网址是@match https://www.bilibili.com/video/*
然后在'use strict';
下面输入代码:
let currentVideoAddress = "";
setInterval(function() {
let newAddress = document.getElementsByTagName('video')[0].getAttribute('src');
if (newAddress === currentVideoAddress) return;
currentVideoAddress = newAddress;
setTimeout(function() {
changeDanmuFont();
}, 100);
}, 3000);
function changeDanmuFont() {
function changeStyle(obj, level=0) {
try {
// obj.style.fontWeight='normal';
obj.style.fontFamily='PingFang SC';
obj.style.opacity='1';
obj.style.webkitTextStrokeWidth='1.5px';
obj.style.webkitTextStrokeColor='black';
obj.style.textShadow=''; //'0px 0px 10px #000000';
} catch(err) {
console.log('Trying ' + level + ': ');
console.log(obj);
if (level < 3) {
setTimeout(function() {
changeStyle(obj.parentNode, level+1);
}, 100);
}
}
}
let d = document.getElementsByClassName('bilibili-player-video-danmaku')[0];
d.addEventListener('DOMNodeInserted', function(ev) {
changeStyle(ev.target);
});
弹幕的HTML有的在ev.target中, 有的在ev.target.parentNode中, 如果后者的情况下, 不延时直接修改字体有时候无效.