Use getPreference* instead of accessing localStorage directly

This commit is contained in:
novenary 2023-02-02 15:25:45 +02:00
parent d980edd843
commit 7b832a981c
4 changed files with 17 additions and 9 deletions

View file

@ -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);

View file

@ -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";

View file

@ -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",
);

View file

@ -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");
},