diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index 75e610e8..225ca494 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -185,63 +185,75 @@ - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + - + + Disable + Auto Skip + Show + @@ -470,7 +482,7 @@ export default { this.sponsorBlock = this.getPreferenceBoolean("sponsorblock", true); if (localStorage.getItem("selectedSkip") !== null) { - var skipList = localStorage.getItem("selectedSkip").split(","); + var skipList = JSON.parse(localStorage.getItem("selectedSkip")); this.skipSponsor = this.skipIntro = this.skipOutro = @@ -480,41 +492,41 @@ export default { this.skipMusicOffTopic = this.skipHighlight = this.skipFiller = - false; - skipList.forEach(skip => { + "off"; + for (const skip in skipList) { switch (skip) { case "sponsor": - this.skipSponsor = true; + this.skipSponsor = skipList[skip]; break; case "intro": - this.skipIntro = true; + this.skipIntro = skipList[skip]; break; case "outro": - this.skipOutro = true; + this.skipOutro = skipList[skip]; break; case "preview": - this.skipPreview = true; + this.skipPreview = skipList[skip]; break; case "interaction": - this.skipInteraction = true; + this.skipInteraction = skipList[skip]; break; case "selfpromo": - this.skipSelfPromo = true; + this.skipSelfPromo = skipList[skip]; break; case "music_offtopic": - this.skipMusicOffTopic = true; + this.skipMusicOffTopic = skipList[skip]; break; case "poi_highlight": - this.skipHighlight = true; + this.skipHighlight = skipList[skip]; break; case "filler": - this.skipFiller = true; + this.skipFiller = skipList[skip]; break; default: console.log("Unknown sponsor type: " + skip); break; } - }); + } } this.showMarkers = this.getPreferenceBoolean("showMarkers", true); @@ -566,17 +578,17 @@ export default { localStorage.setItem("auth_instance_url", this.selectedAuthInstance); localStorage.setItem("sponsorblock", this.sponsorBlock); - var sponsorSelected = []; - if (this.skipSponsor) sponsorSelected.push("sponsor"); - if (this.skipIntro) sponsorSelected.push("intro"); - if (this.skipOutro) sponsorSelected.push("outro"); - if (this.skipPreview) sponsorSelected.push("preview"); - if (this.skipInteraction) sponsorSelected.push("interaction"); - if (this.skipSelfPromo) sponsorSelected.push("selfpromo"); - if (this.skipMusicOffTopic) sponsorSelected.push("music_offtopic"); - if (this.skipHighlight) sponsorSelected.push("poi_highlight"); - if (this.skipFiller) sponsorSelected.push("filler"); - localStorage.setItem("selectedSkip", sponsorSelected); + var sponsorSelected = {}; + if (this.skipSponsor !== "off") sponsorSelected["sponsor"] = this.skipSponsor; + if (this.skipIntro !== "off") sponsorSelected["intro"] = this.skipIntro; + if (this.skipOutro !== "off") sponsorSelected["outro"] = this.skipOutro; + if (this.skipPreview !== "off") sponsorSelected["preview"] = this.skipPreview; + if (this.skipInteraction !== "off") sponsorSelected["interaction"] = this.skipInteraction; + if (this.skipSelfPromo !== "off") sponsorSelected["selfpromo"] = this.skipSelfPromo; + if (this.skipMusicOffTopic !== "off") sponsorSelected["music_offtopic"] = this.skipMusicOffTopic; + if (this.skipHighlight !== "off") sponsorSelected["poi_highlight"] = this.skipHighlight; + if (this.skipFiller !== "off") sponsorSelected["filler"] = this.skipFiller; + localStorage.setItem("selectedSkip", JSON.stringify(sponsorSelected)); localStorage.setItem("showMarkers", this.showMarkers); localStorage.setItem("theme", this.selectedTheme); diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 91c95f1f..e399744f 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -363,13 +363,11 @@ export default { return this.fetchJson(this.apiUrl() + "/streams/" + this.getVideoId()); }, async fetchSponsors() { + const skips = this.getPreferenceDict("selectedSkip", null); return await this.fetchJson(this.apiUrl() + "/sponsors/" + this.getVideoId(), { category: '["' + - this.getPreferenceString("selectedSkip", "sponsor,interaction,selfpromo,music_offtopic").replaceAll( - ",", - '","', - ) + + (skips === null ? "sponsor,interaction,selfpromo,music_offtopic" : Object.keys(skips).join('","')) + '"]', }); }, diff --git a/src/main.js b/src/main.js index e5126cc3..58ebc78b 100644 --- a/src/main.js +++ b/src/main.js @@ -156,6 +156,15 @@ const mixin = { return Number(value); } else return defaultVal; }, + getPreferenceDict(key, defaultVal) { + var value; + if ( + (value = new URLSearchParams(window.location.search).get(key)) !== null || + (this.testLocalStorage && (value = localStorage.getItem(key)) !== null) + ) { + return JSON.parse(value); + } else return defaultVal; + }, apiUrl() { return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks"); },