Skip to content

Commit

Permalink
deploy: 57f1a6e
Browse files Browse the repository at this point in the history
  • Loading branch information
Izumiko committed May 21, 2024
1 parent 01d6734 commit e5cc7b4
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions ede.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @description Jellyfin弹幕插件
// @namespace https://github.com/RyoLee
// @author RyoLee
// @version 1.39
// @version 1.40
// @copyright 2022, RyoLee (https://github.com/RyoLee)
// @license MIT; https://raw.githubusercontent.com/Izumiko/jellyfin-danmaku/jellyfin/LICENSE
// @icon https://github.githubassets.com/pinned-octocat.svg
Expand Down Expand Up @@ -959,12 +959,6 @@
data = isInTampermonkey ? JSON.parse(response) : await response.json();
comments = comments.concat(data.comments);
}
// 去重
comments = comments.filter((comment, index, self) =>
index === self.findIndex((t) => (
t.cid === comment.cid
))
);
}
showDebugInfo('弹幕下载成功: ' + comments.length);
return comments;
Expand Down Expand Up @@ -1184,32 +1178,43 @@
return comments;
}

const limit = 9 - level * 2;
const verticalLimit = 6;
let _container = null;
document.querySelectorAll(mediaContainerQueryStr).forEach((element) => {
if (!element.classList.contains('hide')) {
_container = element;
}
});

const containerWidth = _container.offsetWidth;
const containerHeight = _container.offsetHeight * window.ede.heightRatio - 18;
const duration = Math.ceil(containerWidth / window.ede.speed);
const lines = Math.floor(containerHeight / window.ede.fontSize) - 1;

const limit = (9 - level * 2) * lines;
const verticalLimit = lines - 1 > 0 ? lines - 1 : 1;
const resultComments = [];

const timeBuckets = {};
const verticalTimeBuckets = {};

comments.forEach(comment => {
const timeIndex = Math.ceil(comment.time);
const verticalTimeIndex = Math.ceil(comment.time / 3);
const timeIndex = Math.ceil(comment.time / duration);

if (!timeBuckets[timeIndex]) {
timeBuckets[timeIndex] = [];
timeBuckets[timeIndex] = 0;
}
if (!verticalTimeBuckets[verticalTimeIndex]) {
verticalTimeBuckets[verticalTimeIndex] = [];
if (!verticalTimeBuckets[timeIndex]) {
verticalTimeBuckets[timeIndex] = 0;
}

if (comment.mode === 'top' || comment.mode === 'bottom') {
if (verticalTimeBuckets[verticalTimeIndex].length < verticalLimit) {
verticalTimeBuckets[verticalTimeIndex].push(comment);
if (verticalTimeBuckets[timeIndex] < verticalLimit) {
verticalTimeBuckets[timeIndex]++;
resultComments.push(comment);
}
} else {
if (timeBuckets[timeIndex].length < limit) {
timeBuckets[timeIndex].push(comment);
if (timeBuckets[timeIndex] < limit) {
timeBuckets[timeIndex]++;
resultComments.push(comment);
}
}
Expand All @@ -1218,7 +1223,7 @@
return resultComments;
}

function danmakuParser($obj) {
function danmakuParser(all_cmts) {
const { fontSize, danmakufilter } = window.ede;

const disableBilibili = (danmakufilter & 1) === 1;
Expand All @@ -1234,18 +1239,18 @@
if (filterule === '') { filterule = '!.*'; }
const danmakufilterule = new RegExp(filterule);

return $obj
.filter(($comment) => {
return !danmakufilterule.test($comment.p.split(',').pop());
return all_cmts
.filter((comment, index, self) => {
return !danmakufilterule.test(comment.p.split(',').pop()) && index === self.findIndex((t) => t.cid === comment.cid);
})
.map(($comment) => {
const [time, modeId, colorValue] = $comment.p.split(',').map((v, i) => i === 0 ? parseFloat(v) : parseInt(v, 10));
.map((comment) => {
const [time, modeId, colorValue] = comment.p.split(',').map((v, i) => i === 0 ? parseFloat(v) : parseInt(v, 10));
const mode = { 6: 'ltr', 1: 'rtl', 5: 'top', 4: 'bottom' }[modeId];
if (!mode) return null;

const color = `000000${colorValue.toString(16)}`.slice(-6);
return {
text: $comment.m,
text: comment.m,
mode,
time,
style: {
Expand Down

0 comments on commit e5cc7b4

Please sign in to comment.