diff --git a/src/components/ChannelPage.vue b/src/components/ChannelPage.vue index 062bb983..6eaed839 100644 --- a/src/components/ChannelPage.vue +++ b/src/components/ChannelPage.vue @@ -148,6 +148,7 @@ export default { this.contentItems = this.channel.relatedStreams; this.fetchSubscribedStatus(); this.updateWatched(this.channel.relatedStreams); + this.fetchDeArrowContent(this.channel.relatedStreams); this.tabs.push({ translatedName: this.$t("video.videos"), }); @@ -186,6 +187,7 @@ export default { this.loading = false; this.updateWatched(json.relatedStreams); json.relatedStreams.map(stream => this.contentItems.push(stream)); + this.fetchDeArrowContent(this.contentItems); }); }, fetchChannelTabNextPage() { @@ -196,6 +198,7 @@ export default { this.tabs[this.selectedTab].tabNextPage = json.nextpage; this.loading = false; json.content.map(item => this.contentItems.push(item)); + this.fetchDeArrowContent(this.contentItems); this.tabs[this.selectedTab].content = this.contentItems; }); }, @@ -258,6 +261,7 @@ export default { data: this.tabs[index].data, }).then(tab => { this.contentItems = this.tabs[index].content = tab.content; + this.fetchDeArrowContent(this.contentItems); this.tabs[this.selectedTab].tabNextPage = tab.nextpage; }); }, diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue index 41832d59..e3117aaf 100644 --- a/src/components/FeedPage.vue +++ b/src/components/FeedPage.vue @@ -138,18 +138,8 @@ export default { loadMoreVideos() { this.currentVideoCount = Math.min(this.currentVideoCount + this.videoStep, this.videosStore.length); if (this.videos.length != this.videosStore.length) { - const videoIds = this.videosStore - .slice(this.videos.length, this.currentVideoCount) - .map(video => video.url.substr(-11)) - .sort(); - if (this.getPreferenceBoolean("dearrow", false)) - this.fetchDeArrowContent(videoIds).then(json => { - Object.keys(json).forEach(key => { - const video = this.videosStore.find(video => video.url.substr(-11) == key); - video.dearrow = json[key]; - }); - }); this.videos = this.videosStore.slice(0, this.currentVideoCount); + this.fetchDeArrowContent(this.videos); } }, handleScroll() { diff --git a/src/components/PlaylistPage.vue b/src/components/PlaylistPage.vue index 546c10a2..fb7c98f0 100644 --- a/src/components/PlaylistPage.vue +++ b/src/components/PlaylistPage.vue @@ -116,6 +116,7 @@ export default { .then(() => { this.updateTitle(); this.updateWatched(this.playlist.relatedStreams); + this.fetchDeArrowContent(this.playlist.relatedStreams); }); }, async updateTitle() { @@ -132,6 +133,7 @@ export default { this.playlist.nextpage = json.nextpage; this.loading = false; json.relatedStreams.map(stream => this.playlist.relatedStreams.push(stream)); + this.fetchDeArrowContent(this.playlist.relatedStreams); }); } }, diff --git a/src/components/TrendingPage.vue b/src/components/TrendingPage.vue index 143b6dfc..aeefa729 100644 --- a/src/components/TrendingPage.vue +++ b/src/components/TrendingPage.vue @@ -29,13 +29,7 @@ export default { this.fetchTrending(region).then(videos => { this.videos = videos; this.updateWatched(this.videos); - const videoIds = this.videos.map(video => video.url.substr(-11)).sort(); - this.fetchDeArrowContent(videoIds).then(json => { - Object.keys(json).forEach(key => { - const video = this.videos.find(video => video.url.substr(-11) == key); - video.dearrow = json[key]; - }); - }); + this.fetchDeArrowContent(this.videos); }); }, activated() { diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 3b23bd6b..6d669209 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -454,16 +454,7 @@ export default { this.video.description = this.rewriteDescription(xmlDoc.querySelector("body").innerHTML); this.updateWatched(this.video.relatedStreams); - const videoIds = this.video.relatedStreams - .filter(obj => obj.type === "stream") - .map(video => video.url.substr(-11)) - .sort(); - this.fetchDeArrowContent(videoIds).then(json => { - Object.keys(json).forEach(key => { - const video = this.video.relatedStreams.find(video => video.url.substr(-11) == key); - video.dearrow = json[key]; - }); - }); + this.fetchDeArrowContent(this.video.relatedStreams); } }); }, @@ -485,16 +476,7 @@ export default { } }); await this.fetchPlaylistPages().then(() => { - const videoIds = this.playlist.relatedStreams - .filter(obj => obj.type === "stream") - .map(video => video.url.substr(-11)) - .sort(); - this.fetchDeArrowContent(videoIds).then(json => { - Object.keys(json).forEach(key => { - const video = this.playlist.relatedStreams.find(video => video.url.substr(-11) == key); - video.dearrow = json[key]; - }); - }); + this.fetchDeArrowContent(this.playlist.relatedStreams); }); } }, diff --git a/src/main.js b/src/main.js index 601a3d50..e8d2fa4d 100644 --- a/src/main.js +++ b/src/main.js @@ -542,10 +542,24 @@ const mixin = { return undefined; } }, - fetchDeArrowContent(videoIds) { - if (!this.getPreferenceBoolean("dearrow", false)) return new Promise(resolve => resolve({})); - return this.fetchJson(this.apiUrl() + "/dearrow", { + fetchDeArrowContent(content) { + if (!this.getPreferenceBoolean("dearrow", false)) return; + + const videoIds = content + .filter(item => item.type === "stream") + .filter(item => item.dearrow === undefined) + .map(item => item.url.substr(-11)) + .sort(); + + if (videoIds.length === 0) return; + + this.fetchJson(this.apiUrl() + "/dearrow", { videoIds: videoIds.join(","), + }).then(json => { + Object.keys(json).forEach(videoId => { + const item = content.find(item => item.url.endsWith(videoId)); + if (item) item.dearrow = json[videoId]; + }); }); }, },