更新版本号

This commit is contained in:
竟康 2024-10-10 01:13:23 +08:00
parent 51c779c07f
commit 97009f150b
1 changed files with 68 additions and 68 deletions

View File

@ -1,69 +1,69 @@
// ==UserScript== // ==UserScript==
// @name 快速刷新媒体库元数据 // @name 快速刷新媒体库元数据
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 2024-10-09 // @version 2024-10-10
// @description try to take over the world! // @description try to take over the world!
// @author You // @author You
// @match https://media.muster.work:4433/web/index.html // @match https://media.muster.work:4433/web/index.html
// @icon https://www.google.com/s2/favicons?sz=64&domain=muster.work // @icon https://www.google.com/s2/favicons?sz=64&domain=muster.work
// @grant none // @grant none
// ==/UserScript== // ==/UserScript==
(function () { (function () {
'use strict'; 'use strict';
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
// 检测到 DOM 变化后的操作 // 检测到 DOM 变化后的操作
if (document.readyState !== 'complete') { if (document.readyState !== 'complete') {
return return
} }
// 已存在时忽略 // 已存在时忽略
const refresh_button = document.querySelector('.refresh_metadata_button') const refresh_button = document.querySelector('.refresh_metadata_button')
if (refresh_button) { return } if (refresh_button) { return }
// 没有剧集时忽略 // 没有剧集时忽略
const list = document.getElementsByClassName('listItem-withContentWrapper') const list = document.getElementsByClassName('listItem-withContentWrapper')
if (!list) { return } if (!list) { return }
// 开始遍历增加点击事件 // 开始遍历增加点击事件
for (const key in list) { for (const key in list) {
if (Object.prototype.hasOwnProperty.call(list, key)) { if (Object.prototype.hasOwnProperty.call(list, key)) {
const item = list[key]; const item = list[key];
const info = item.querySelector('.listItemMediaInfo') const info = item.querySelector('.listItemMediaInfo')
const button = document.createElement('button') const button = document.createElement('button')
button.className = 'refresh_metadata_button paper-icon-button-light emby-button' button.className = 'refresh_metadata_button paper-icon-button-light emby-button'
button.style.borderRadius = '0.5rem' button.style.borderRadius = '0.5rem'
button.style.padding = 'revert' button.style.padding = 'revert'
button.innerText = '刷新元数据' button.innerText = '刷新元数据'
button.onclick = async function () { button.onclick = async function () {
try { try {
Loading.show() Loading.show()
const dataId = item.getAttribute('data-id') const dataId = item.getAttribute('data-id')
const url = '/Items/' + dataId + '/Refresh?Recursive=true&ImageRefreshMode=FullRefresh&MetadataRefreshMode=FullRefresh&ReplaceAllImages=true&ReplaceAllMetadata=true' 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() } }) const res = await fetch(url, { method: 'POST', headers: { 'x-emby-authorization': getAuthorization() } })
console.log('res:', res); console.log('res:', res);
if (res.status == 204) { if (res.status == 204) {
return return
} }
alert(res.statusText) alert(res.statusText)
} finally { } finally {
Loading.hide() Loading.hide()
} }
} }
info.appendChild(button) info.appendChild(button)
} }
} }
}); });
function getAuthorization() { function getAuthorization() {
const result = { const result = {
'MediaBrowser Client': ApiClient._appName, 'MediaBrowser Client': ApiClient._appName,
'Device': ApiClient._deviceName, 'Device': ApiClient._deviceName,
'DeviceId': ApiClient._deviceId, 'DeviceId': ApiClient._deviceId,
'Version': ApiClient._appVersion, 'Version': ApiClient._appVersion,
'Token': ApiClient._serverInfo.AccessToken 'Token': ApiClient._serverInfo.AccessToken
} }
return Object.entries(result) return Object.entries(result)
.map(([key, value]) => `${key}="${value}"`) .map(([key, value]) => `${key}="${value}"`)
.join(', '); .join(', ');
} }
// 开始观察 // 开始观察
observer.observe(document.body, { childList: true, subtree: true }); observer.observe(document.body, { childList: true, subtree: true });
})(); })();