Skip to content

Commit

Permalink
修复第三方弹幕获取和过滤 (#56)
Browse files Browse the repository at this point in the history
* fix bug

* Update ede.js
  • Loading branch information
Xarth-Mai authored Sep 6, 2024
1 parent 5f7f799 commit 47f511b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions ede.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,20 +977,16 @@
try {
let response = await makeGetRequest(url_all);
let data = isInTampermonkey ? JSON.parse(response) : await response.json();
const nonDandan = /^.{3,}\]/; // 匹配非弹弹play弹幕
let hasRelated = false;
for (const c of data.comments) {
if (nonDandan.test(c.p.split(',').pop())) {
hasRelated = true;
break;
const matchBili = /^\[BiliBili\]/;
let hasBili = false;
if ((danmakuFilter & 1) !== 1) {
for (const c of data.comments) {
if (matchBili.test(c.p.split(',').pop())) {
hasBili = true;
break;
}
}
}
if (hasRelated) { // 实际包含第三方弹幕
showDebugInfo('弹幕下载成功: ' + data.comments.length);
return data.comments;
} else {
showDebugInfo('缺少第三方弹幕,尝试获取');
}
let comments = data.comments;
response = await makeGetRequest(url_related);
data = isInTampermonkey ? JSON.parse(response) : await response.json();
Expand All @@ -1000,7 +996,10 @@
// 根据设置过滤弹幕源
let src = [];
for (const s of data.relateds) {
if ((danmakuFilter & 1) !== 1 && s.url.includes('bilibili')) {
if ((danmakuFilter & 1) !== 1 && !hasBili && s.url.includes('bilibili.com/bangumi')) {
src.push(s.url);
}
if ((danmakuFilter & 1) !== 1 && s.url.includes('bilibili.com/video')) {
src.push(s.url);
}
if ((danmakuFilter & 2) !== 2 && s.url.includes('gamer')) {
Expand Down Expand Up @@ -1406,7 +1405,7 @@
.filter((comment) => {
const user = comment.p.split(',')[3];
const modeId = parseInt(comment.p.split(',')[1], 10);
return !danmakuFilteRule.test(comment.m) && enabledMode.includes(modeId);
return !danmakuFilteRule.test(user) && enabledMode.includes(modeId);
})
.map((comment) => {
const [time, modeId, colorValue] = comment.p.split(',').map((v, i) => i === 0 ? parseFloat(v) : parseInt(v, 10));
Expand Down

0 comments on commit 47f511b

Please sign in to comment.