diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index 5b488802..b62172be 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -502,8 +502,8 @@ export default { this.selectedAuthInstance = this.getPreferenceString("auth_instance_url", this.selectedInstance); this.sponsorBlock = this.getPreferenceBoolean("sponsorblock", true); - if (localStorage.getItem("skipOptions") !== null) { - const skipOptions = JSON.parse(localStorage.getItem("skipOptions")); + var skipOptions, skipList; + if ((skipOptions = this.getPreferenceJSON("skipOptions")) !== null) { if (skipOptions.sponsor !== undefined) this.skipSponsor = skipOptions.sponsor; if (skipOptions.intro !== undefined) this.skipIntro = skipOptions.intro; if (skipOptions.outro !== undefined) this.skipOutro = skipOptions.outro; @@ -513,8 +513,8 @@ export default { if (skipOptions.music_offtopic !== undefined) this.skipMusicOffTopic = skipOptions.music_offtopic; if (skipOptions.poi_highlight !== undefined) this.skipHighlight = skipOptions.poi_highlight; if (skipOptions.filler !== undefined) this.skipFiller = skipOptions.filler; - } else if (localStorage.getItem("selectedSkip") !== null) { - var skipList = localStorage.getItem("selectedSkip").split(","); + } else if ((skipList = this.getPreferenceString("selectedSkip")) !== null) { + skipList = skipList.split(","); this.skipSponsor = this.skipIntro = this.skipOutro = @@ -562,7 +562,7 @@ export default { } this.showMarkers = this.getPreferenceBoolean("showMarkers", true); - this.minSegmentLength = Math.max(Number(localStorage.getItem("minSegmentLength")), 0); + this.minSegmentLength = Math.max(this.getPreferenceNumber("minSegmentLength", 0), 0); this.selectedTheme = this.getPreferenceString("theme", "dark"); this.autoPlayVideo = this.getPreferenceBoolean("playerAutoPlay", true); this.listen = this.getPreferenceBoolean("listen", false); diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index e3dc8be9..6d1299aa 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -750,7 +750,7 @@ export default { }, watch: { sponsors() { - const skipOptions = JSON.parse(this.getPreferenceString("skipOptions", "{}")); + const skipOptions = this.getPreferenceJSON("skipOptions", {}); this.sponsors?.segments?.forEach(segment => { const option = skipOptions[segment.category]; segment.autoskip = option === undefined || option === "auto"; diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 70680a76..24b4302f 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -371,9 +371,8 @@ export default { "selectedSkip", "sponsor,interaction,selfpromo,music_offtopic", ).split(","); - const skipOptionsJSON = localStorage.getItem("skipOptions"); - if (skipOptionsJSON !== null) { - const skipOptions = JSON.parse(skipOptionsJSON); + const skipOptions = this.getPreferenceJSON("skipOptions"); + if (skipOptions !== null) { selectedSkip = Object.keys(skipOptions).filter( k => skipOptions[k] !== undefined && skipOptions[k] !== "no", ); diff --git a/src/main.js b/src/main.js index 19a037de..e27ff57b 100644 --- a/src/main.js +++ b/src/main.js @@ -162,6 +162,15 @@ const mixin = { return Number(value); } else return defaultVal; }, + getPreferenceJSON(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"); },