From 110c32dbef9ce2e7b90690b1828dabc0424540f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=A2=A6=E5=8D=97?= <1487537121@qq.com> Date: Sun, 10 Aug 2025 07:14:20 +0000 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tampermonkey脚本插件 --- ...n External Player (PotPlayer).DreamLife.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Jellyfin External Player (PotPlayer).DreamLife.js diff --git a/Jellyfin External Player (PotPlayer).DreamLife.js b/Jellyfin External Player (PotPlayer).DreamLife.js new file mode 100644 index 0000000..6bf2a70 --- /dev/null +++ b/Jellyfin External Player (PotPlayer).DreamLife.js @@ -0,0 +1,72 @@ +// ==UserScript== +// @name Jellyfin External Player (PotPlayer) +// @namespace http://dreamlife.top:13000/ +// @version 1.0 +// @description 在 Jellyfin 详情页中添加 PotPlayer 按钮,调用外部potplayer播放器来播放视频文件。 +// @author MengNan Zhang +// @match *://*/web/* +// @grant none +// @run-at document-end +// @downloadURL http://dreamlife.top:13000/Cx330/DreamLife_JellyfinExternalPlayer/src/branch/main/Jellyfin External Player (PotPlayer).DreamLife.js +// @updateURL http://dreamlife.top:13000/Cx330/DreamLife_JellyfinExternalPlayer/src/branch/main/Jellyfin External Player (PotPlayer).DreamLife.js +// ==/UserScript== + +(function () { + 'use strict'; + + // 获取 Jellyfin API 客户端 + function getApiClient() { + return window.ApiClient || window.ConnectionManager?.currentApiClient(); + } + + // 获取播放链接 + async function getPlayUrl(itemId) { + const api = getApiClient(); + if (!api) return null; + + const baseUrl = api._serverAddress || api._serverInfo?.PublicAddress; + const token = api.accessToken(); + if (!baseUrl || !token) return null; + + return `${baseUrl}/Videos/${itemId}/stream?static=true&api_key=${token}`; + } + + // 添加 PotPlayer 按钮 + function addPotPlayerButton(playButton) { + const container = playButton.parentElement; + if (!container || container.querySelector(".external-player-btn")) return; + + const btn = document.createElement("button"); + btn.className = "detailButton external-player-btn"; + btn.style.marginLeft = "8px"; + btn.style.background = "transparent"; + btn.style.border = "none"; + btn.style.cursor = "pointer"; + + const img = document.createElement("img"); + img.src = "https://pc3.gtimg.com/softmgr/logo/48/519_48_1492137107.png"; // PotPlayer logo + img.alt = "PotPlayer"; + img.style.width = "26px"; + img.style.height = "26px"; + + btn.appendChild(img); + + btn.onclick = async () => { + const id = location.href.match(/id=([^&]+)/)?.[1]; + if (!id) return alert("未获取到视频 ID"); + const url = await getPlayUrl(id); + if (url) location.href = `potplayer://${url}`; + }; + + container.appendChild(btn); + } + + // 监听页面变化 + const observer = new MutationObserver(() => { + document.querySelectorAll(".mainDetailButtons .btnPlay").forEach((btn) => { + addPotPlayerButton(btn); + }); + }); + + observer.observe(document.body, { childList: true, subtree: true }); +})();