diff --git a/ede.js b/ede.js index e449479..e7df013 100644 --- a/ede.js +++ b/ede.js @@ -53,6 +53,21 @@ const mediaContainerQueryStr = "div[data-type='video-osd']"; const mediaQueryStr = 'video'; + let itemId = ''; + + // Intercept XMLHttpRequest + const originalOpen = XMLHttpRequest.prototype.open; + XMLHttpRequest.prototype.open = function (_, url) { + this.addEventListener('load', function () { + console.log('XMLHttpRequest to:', url); + if (url.endsWith('PlaybackInfo')) { + const res = JSON.parse(this.responseText); + itemId = res.MediaSources[0].Id; + } + }); + originalOpen.apply(this, arguments); + }; + const displayButtonOpts = { title: '弹幕开关', id: 'displayDanmaku', @@ -836,15 +851,8 @@ let playingInfo = null; while (!playingInfo) { await new Promise((resolve) => setTimeout(resolve, 200)); - let sessionInfo = await ApiClient.getSessions({ - userId: ApiClient.getCurrentUserId(), - deviceId: ApiClient.deviceId(), - }); - if (!sessionInfo[0].NowPlayingItem) { - await new Promise(resolve => setTimeout(resolve, 150)); - continue; - } - playingInfo = sessionInfo[0].NowPlayingItem; + // params: userId, itemId + playingInfo = await ApiClient.getItem("", itemId); } showDebugInfo('获取Item信息成功: ' + (playingInfo.SeriesName || playingInfo.Name)); return playingInfo;