mirror of
				https://github.com/TeamPiped/Piped.git
				synced 2025-11-03 22:21:55 +00:00 
			
		
		
		
	Use getPreference* instead of accessing localStorage directly
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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";
 | 
			
		||||
 
 | 
			
		||||
@@ -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",
 | 
			
		||||
                );
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
        },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user