tampermonkey_script/jellyfin_quick_refresh_meda...

71 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name 快速刷新媒体库元数据
// @namespace http://tampermonkey.net/
// @version 2024-10-11
// @description 简化刷新媒体库路径从原来的鼠标点击6下简化为一键刷新
// @author JK
// @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 });
})();