From e0ecc1aa09fa2d6b937ac9db5fa93b5cdc06bbe2 Mon Sep 17 00:00:00 2001
From: SAKURA <70046367+Yejia995@users.noreply.github.com>
Date: Wed, 17 Apr 2024 06:04:44 -0400
Subject: [PATCH] Update ede.js
---
ede.js | 578 ++++++++++++++++++++++++++-------------------------------
1 file changed, 263 insertions(+), 315 deletions(-)
diff --git a/ede.js b/ede.js
index 4822890..b173c64 100644
--- a/ede.js
+++ b/ede.js
@@ -3,7 +3,7 @@
// @description Jellyfin弹幕插件
// @namespace https://github.com/RyoLee
// @author RyoLee
-// @version 1.34
+// @version 1.35
// @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
@@ -11,8 +11,8 @@
// @downloadURL https://cdn.jsdelivr.net/gh/Izumiko/jellyfin-danmaku@gh-pages/ede.user.js
// @grant GM_xmlhttpRequest
// @connect *
-// @match *://*/*/web/index.html
-// @match *://*/web/index.html
+// @match *://*/*/web/
+// @match *://*/web/
// @match https://jellyfin-web.pages.dev/
// ==/UserScript==
@@ -27,10 +27,8 @@
let apiPrefix = '';
let ddplayStatus = JSON.parse(localStorage.getItem('ddplayStatus')) || { isLogin: false, token: '', tokenExpire: 0 };
const check_interval = 200;
- // 0:当前状态关闭 1:当前状态打开
const danmaku_icons = ['comments_disabled', 'comment'];
const search_icon = 'find_replace';
- const source_icon = 'library_add';
const log_icons = ['code_off', 'code'];
const settings_icon = 'tune';
const send_icon = 'send';
@@ -59,7 +57,7 @@
if (window.ede.danmaku) {
window.ede.danmakuSwitch == 1 ? window.ede.danmaku.show() : window.ede.danmaku.hide();
}
- },
+ }
};
const searchButtonOpts = {
@@ -73,39 +71,7 @@
}
showDebugInfo('手动匹配弹幕');
reloadDanmaku('search');
- },
- };
-
- const sourceButtonOpts = {
- title: '增加弹幕源',
- id: 'addDanmakuSource',
- class: source_icon,
- onclick: () => {
- showDebugInfo('手动增加弹幕源');
- let source = prompt('请输入弹幕源地址:');
- if (source) {
- getCommentsByUrl(source)
- .then(comments => {
- if (comments !== null) {
- createDanmaku(comments)
- .then(() => {
- showDebugInfo('弹幕就位');
-
- // 如果已经登录,把弹幕源提交给弹弹Play
- if (ddplayStatus.isLogin) {
- postRelatedSource(source);
- }
- })
- .catch(error => {
- console.error('创建弹幕失败:', error);
- });
- }
- }
- )
- } else {
- showDebugInfo('未获取弹幕源地址');
- }
- },
+ }
};
const logButtonOpts = {
@@ -131,86 +97,109 @@
id: 'danmakuSettings',
class: settings_icon,
onclick: () => {
- if (document.getElementById('danmakuModal')) {
- return;
- }
- const modal = document.createElement('div');
- modal.id = 'danmakuModal';
- modal.className = 'dialogContainer';
- modal.innerHTML = `
+ createModal(
+ 'danmakuModal',
+ 'dialogContainer',
+ `
-
-
- 透明度:
-
-
-
- 弹幕速度:
-
-
-
- 字体大小:
-
-
-
- 高度比例:
-
-
-
- 密度限制等级:
-
-
-
-
+
+
+
+
+
+
`,
+ );
+
+ [{ id: 'opacity' }, { id: 'speed' }, { id: 'fontSize' }, { id: 'heightRatio' }, { id: 'danmakuDensityLimit', ticks: ['无', '低', '中', '高'] }].forEach((item) => {
+ const input = document.getElementById(item.id);
+ const label = document.getElementById('lb' + item.id);
+ const updateDisplay = () => {
+ const value = input.value;
+ const prefix = label.innerText.split(':')[0];
+ label.innerText = `${prefix}: ${item.ticks ? item.ticks[value] : value}`;
+ };
- function showCurrentVal(id, ticks) {
- const val = document.getElementById(id).value;
- const span = document.getElementById('lb' + id);
- const prefix = span.innerText.split(':')[0];
- if (ticks) {
- span.innerText = prefix + ': ' + ticks[val];
+ input.oninput = updateDisplay;
+ updateDisplay();
+ });
+
+ document.getElementById('danmakuSource').onchange = () => {
+ const source = document.getElementById('danmakuSource').value;
+ if (source) {
+ getCommentsByUrl(source).then((comments) => {
+ if (comments !== null) {
+ createDanmaku(comments)
+ .then(() => {
+ showDebugInfo('弹幕就位');
+ if (ddplayStatus.isLogin) {
+ postRelatedSource(source);
+ }
+ })
+ .catch((error) => {
+ console.error('创建弹幕失败:', error);
+ });
+ }
+ });
} else {
- span.innerText = prefix + ': ' + val;
+ showDebugInfo('未获取弹幕源地址');
}
- }
-
- showCurrentVal('opacity');
- showCurrentVal('speed');
- showCurrentVal('fontSize');
- showCurrentVal('heightRatio');
- showCurrentVal('danmakuDensityLimit', ['无', '低', '中', '高']);
-
- const closeModal = () => {
- document.body.removeChild(modal);
};
+ document.getElementById('cancelSettings').onclick = () => closeModal('danmakuModal');
document.getElementById('saveSettings').onclick = () => {
try {
+ window.ede.offset = parseFloat(document.getElementById('offset').value);
+ window.localStorage.setItem('danmakuOffset', window.ede.offset.toString());
+ showDebugInfo(`设置弹幕时间偏移:${window.ede.offset}`);
window.ede.opacity = parseFloatOfRange(document.getElementById('opacity').value, 0, 1);
window.localStorage.setItem('danmakuopacity', window.ede.opacity.toString());
showDebugInfo(`设置弹幕透明度:${window.ede.opacity}`);
@@ -223,31 +212,24 @@
window.ede.heightRatio = parseFloatOfRange(document.getElementById('heightRatio').value, 0, 1);
window.localStorage.setItem('danmakuheight', window.ede.heightRatio.toString());
showDebugInfo(`设置弹幕高度:${window.ede.heightRatio}`);
- window.ede.danmakufilter = 0;
- document.querySelectorAll('input[name="danmakufilter"]:checked').forEach(element => {
- window.ede.danmakufilter += parseInt(element.value, 10);
- });
- window.localStorage.setItem('danmakufilter', window.ede.danmakufilter);
- showDebugInfo(`设置弹幕过滤:${window.ede.danmakufilter}`);
window.ede.danmakuDensityLimit = parseInt(document.getElementById('danmakuDensityLimit').value);
window.localStorage.setItem('danmakuDensityLimit', window.ede.danmakuDensityLimit);
showDebugInfo(`设置弹幕密度限制等级:${window.ede.danmakuDensityLimit}`);
window.ede.chConvert = parseInt(document.querySelector('input[name="chConvert"]:checked').value);
window.localStorage.setItem('chConvert', window.ede.chConvert);
showDebugInfo(`设置简繁转换:${window.ede.chConvert}`);
+ window.ede.danmakufilter = 0;
+ document.querySelectorAll('input[name="danmakufilter"]:checked').forEach((element) => {
+ window.ede.danmakufilter += parseInt(element.value, 10);
+ });
+ window.localStorage.setItem('danmakufilter', window.ede.danmakufilter);
+ showDebugInfo(`设置弹幕过滤:${window.ede.danmakufilter}`);
reloadDanmaku('reload');
- closeModal();
+ closeModal('danmakuModal');
} catch (e) {
alert(`Invalid input: ${e.message}`);
}
};
- document.getElementById('cancelSettings').onclick = closeModal;
-
- document.getElementById('opacity').oninput = () => showCurrentVal('opacity');
- document.getElementById('speed').oninput = () => showCurrentVal('speed');
- document.getElementById('fontSize').oninput = () => showCurrentVal('fontSize');
- document.getElementById('heightRatio').oninput = () => showCurrentVal('heightRatio');
- document.getElementById('danmakuDensityLimit').oninput = () => showCurrentVal('danmakuDensityLimit', ['无', '低', '中', '高']);
}
};
@@ -256,36 +238,33 @@
id: 'sendDanmaku',
class: send_icon,
onclick: () => {
- // 登录窗口
- if (!document.getElementById('loginDialog')) {
- const modal = document.createElement('div');
- modal.id = 'loginDialog';
- modal.className = 'dialogContainer';
- modal.style.display = 'none';
- modal.innerHTML = `
-