From 51c779c07fc2a55722339b078b8195f2c0f78f92 Mon Sep 17 00:00:00 2001 From: jinglekang Date: Thu, 10 Oct 2024 01:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BF=AB=E9=80=9F=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=AA=92=E4=BD=93=E5=BA=93=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jellyfin_quick_refresh_medatata.js | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 jellyfin_quick_refresh_medatata.js diff --git a/jellyfin_quick_refresh_medatata.js b/jellyfin_quick_refresh_medatata.js new file mode 100644 index 0000000..97f2300 --- /dev/null +++ b/jellyfin_quick_refresh_medatata.js @@ -0,0 +1,69 @@ +// ==UserScript== +// @name 快速刷新媒体库元数据 +// @namespace http://tampermonkey.net/ +// @version 2024-10-09 +// @description try to take over the world! +// @author You +// @match https://media.muster.work:4433/web/index.html +// @icon https://www.google.com/s2/favicons?sz=64&domain=muster.work +// @grant none +// ==/UserScript== + +(function () { + 'use strict'; + const observer = new MutationObserver(() => { + // 检测到 DOM 变化后的操作 + if (document.readyState !== 'complete') { + return + } + // 已存在时忽略 + const refresh_button = document.querySelector('.refresh_metadata_button') + if (refresh_button) { return } + // 没有剧集时忽略 + const list = document.getElementsByClassName('listItem-withContentWrapper') + if (!list) { return } + // 开始遍历增加点击事件 + for (const key in list) { + if (Object.prototype.hasOwnProperty.call(list, key)) { + const item = list[key]; + const info = item.querySelector('.listItemMediaInfo') + const button = document.createElement('button') + button.className = 'refresh_metadata_button paper-icon-button-light emby-button' + button.style.borderRadius = '0.5rem' + button.style.padding = 'revert' + button.innerText = '刷新元数据' + button.onclick = async function () { + try { + Loading.show() + const dataId = item.getAttribute('data-id') + const url = '/Items/' + dataId + '/Refresh?Recursive=true&ImageRefreshMode=FullRefresh&MetadataRefreshMode=FullRefresh&ReplaceAllImages=true&ReplaceAllMetadata=true' + const res = await fetch(url, { method: 'POST', headers: { 'x-emby-authorization': getAuthorization() } }) + console.log('res:', res); + if (res.status == 204) { + return + } + alert(res.statusText) + } finally { + Loading.hide() + } + } + info.appendChild(button) + } + } + }); + + function getAuthorization() { + const result = { + 'MediaBrowser Client': ApiClient._appName, + 'Device': ApiClient._deviceName, + 'DeviceId': ApiClient._deviceId, + 'Version': ApiClient._appVersion, + 'Token': ApiClient._serverInfo.AccessToken + } + return Object.entries(result) + .map(([key, value]) => `${key}="${value}"`) + .join(', '); + } + // 开始观察 + observer.observe(document.body, { childList: true, subtree: true }); +})(); \ No newline at end of file