// ==UserScript== // @name 快速刷新媒体库元数据 // @namespace http://tampermonkey.net/ // @version 2024-10-10 // @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 // @downloadURL https://git.zaobai.com/public/tampermonkey_script/raw/branch/master/jellyfin_quick_refresh_medatata.user.js // @updateURL https://git.zaobai.com/public/tampermonkey_script/raw/branch/master/jellyfin_quick_refresh_medatata.user.js // ==/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 }); })();