73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
// ==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 });
|
||
})();
|