From e5cc7b4e4c13dba5f05d420023a50d94e4829e67 Mon Sep 17 00:00:00 2001 From: Izumiko Date: Tue, 21 May 2024 13:03:41 +0000 Subject: [PATCH] deploy: 57f1a6e237f3d072aa59445801f3fe44a0bc2e6c --- ede.user.js | 55 +++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/ede.user.js b/ede.user.js index 7f337fd..83f9a85 100644 --- a/ede.user.js +++ b/ede.user.js @@ -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 @@ -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; @@ -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); } } @@ -1218,7 +1223,7 @@ return resultComments; } - function danmakuParser($obj) { + function danmakuParser(all_cmts) { const { fontSize, danmakufilter } = window.ede; const disableBilibili = (danmakufilter & 1) === 1; @@ -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: {