Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 自訂字體與字體選項功能 #61

Merged
merged 6 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,21 @@ sub_filter_once on;
並加入新的 location 塊:
```conf
location /ddplay-api/ {
proxy_pass https://api.dandanplay.net/;
proxy_pass https://api.dandanplay.net;
proxy_set_header Host $host;

# 下傳的頭部設置
add_header Access-Control-Allow-Origin "example.com";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization";

if ($request_method = OPTIONS) {
add_header Content-Length 0;
add_header Content-Type text/plain;
return 204;
}
}

location /ddplay-api/ {
proxy_pass https://api.dandanplay.net/;
proxy_set_header Host $host;

add_header Access-Control-Allow-Origin "example.com";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization";

if ($request_method = OPTIONS) {
add_header Content-Length 0;
add_header Content-Type text/plain;
return 204;
}
}

location /ddplay-api/api/v2/login {
proxy_pass https://jellyfin-danmaku.pages.dev;
rewrite ^/ddplay-api/api/v2/login(.*)$ /cors/https://api.dandanplay.net/api/v2/login$1 break;
proxy_pass https://ddplay-api.930524.xyz;
proxy_set_header Host $host;

# 下傳的頭部設置
add_header Access-Control-Allow-Origin "example.com";
add_header Access-Control-Allow-Methods "POST, OPTIONS";
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization";
Expand Down Expand Up @@ -134,18 +116,20 @@ example.com {
header_up Accept-Encoding identity
}

handle_path /ddplay-api/api/v2/login* {
reverse_proxy https://jellyfin-danmaku.pages.dev {
handle_path /ddplay-api/* {
reverse_proxy https://api.dandanplay.net {
header_up Host {upstream_hostport}
header_down Access-Control-Allow-Origin "example.com"
header_down Access-Control-Allow-Methods "POST, OPTIONS"
header_down Access-Control-Allow-Methods "GET, POST, OPTIONS"
header_down Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization"
}
}

handle_path /ddplay-api/* {
reverse_proxy https://api.dandanplay.net {
handle_path /ddplay-api/api/v2/login* {
rewrite * /cors/https://api.dandanplay.net/api/v2/login{http.request.uri.path}
reverse_proxy https://ddplay-api.930524.xyz {
header_up Host {upstream_hostport}
header_down Access-Control-Allow-Origin "example.com"
header_down Access-Control-Allow-Methods "GET, POST, OPTIONS"
header_down Access-Control-Allow-Methods "POST, OPTIONS"
header_down Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization"
}
}
Expand Down
30 changes: 26 additions & 4 deletions ede.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.47
// @version 1.49
// @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 @@ -157,10 +157,18 @@
<span id="lbspeed" style="flex: auto;">弹幕速度:</span>
<input style="width: 50%;" type="range" id="speed" min="20" max="600" step="10" value="${window.ede.speed || 200}" />
</div>
<div style="display: flex;">
<label style="flex: auto;">字体:</label>
<div><input style="flex-grow: 1;" id="danmakuFontFamily" placeholder="sans-serif" value="${window.ede.fontFamily ?? "sans-serif"}" /></div>
</div>
<div style="display: flex;">
<span id="lbfontSize" style="flex: auto;">字体大小:</span>
<input style="width: 50%;" type="range" id="fontSize" min="8" max="80" step="1" value="${window.ede.fontSize || 18}" />
</div>
<div style="display: flex;">
<label style="flex: auto;">其他字体选項:</label>
<div><input style="flex-grow: 1;" id="danmakuFontOptions" placeholder="" value="${window.ede.fontOptions ?? ""}" /></div>
</div>
<div style="display: flex;">
<span id="lbheightRatio" style="flex: auto;">高度比例:</span>
<input style="width: 50%;" type="range" id="heightRatio" min="0" max="1" step="0.05" value="${window.ede.heightRatio || 0.9}" />
Expand Down Expand Up @@ -279,6 +287,12 @@
window.ede.curEpOffset = epOffset;
showDebugInfo(`设置弹幕偏移时间:${window.ede.curEpOffset}`);
}
window.ede.fontFamily = document.getElementById("danmakuFontFamily").value || "sans-serif";
window.localStorage.setItem('danmakuFontFamily', window.ede.fontFamily);
showDebugInfo(`字体:${window.ede.fontFamily}`);
window.ede.fontOptions = document.getElementById("danmakuFontOptions").value;
window.localStorage.setItem('danmakuFontOptions', window.ede.fontOptions);
showDebugInfo(`字体选項:${window.ede.fontOptions}`);
reloadDanmaku('reload');
closeModal();
} catch (e) {
Expand Down Expand Up @@ -480,6 +494,12 @@
// 当前剧集弹幕偏移时间
this.curEpOffset = 0;
this.curEpOffsetModified = false;
// 字體
const fontFamily = window.localStorage.getItem('danmakuFontFamily');
this.fontFamily = fontFamily ?? "sans-serif";
// 字体选項
const fontOptions = window.localStorage.getItem('danmakuFontOptions');
this.fontOptions = fontOptions ?? "";

this.danmaku = null;
this.episode_info = null;
Expand Down Expand Up @@ -719,7 +739,7 @@
mode: modemap,
time: time,
style: {
font: `${window.ede.fontSize}px sans-serif`,
font: `${window.ede.fontOptions} ${window.ede.fontSize}px ${window.ede.fontFamily}`,
fillStyle: `#${colorStr}`,
strokeStyle: colorStr === '000000' ? '#fff' : '#000',
lineWidth: 2.0,
Expand Down Expand Up @@ -1144,6 +1164,8 @@
showDebugInfo(`弹幕来源过滤:${window.ede.danmakuFilter}`);
showDebugInfo(`弹幕模式过滤:${window.ede.danmakuModeFilter}`);
showDebugInfo(`弹幕字号:${window.ede.fontSize}`);
showDebugInfo(`弹幕字体:${window.ede.fontFamily}`);
showDebugInfo(`弹幕字体选項:${window.ede.fontOptions}`);
showDebugInfo(`屏幕分辨率:${window.screen.width}x${window.screen.height}`);
if (window.ede.curEpOffset !== 0) showDebugInfo(`当前弹幕偏移:${window.ede.curEpOffset} 秒`);

Expand Down Expand Up @@ -1374,7 +1396,7 @@
}

function danmakuParser(all_cmts) {
const { fontSize, danmakuFilter, danmakuModeFilter, curEpOffset } = window.ede;
const { fontSize, fontOptions, fontFamily, danmakuFilter, danmakuModeFilter, curEpOffset } = window.ede;

const disableBilibili = (danmakuFilter & 1) === 1;
const disableGamer = (danmakuFilter & 2) === 2;
Expand Down Expand Up @@ -1422,7 +1444,7 @@
mode,
time: time + curEpOffset,
style: {
font: `${fontSize}px sans-serif`,
font: `${fontOptions} ${fontSize}px ${fontFamily}`,
fillStyle: `#${color}`,
strokeStyle: color === '000000' ? '#fff' : '#000',
lineWidth: 2.0,
Expand Down