Cleanup + Allow setting some parameters over query.

This commit is contained in:
FireMasterK 2021-07-04 00:54:09 +05:30
parent 14b28ba87b
commit 4a10d80804
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
5 changed files with 49 additions and 25 deletions

View file

@ -1,4 +1,3 @@
export default { export default {
BASE_URL: localStorage.getItem("instance") || "https://pipedapi.kavin.rocks", BASE_URL: localStorage.getItem("instance") || "https://pipedapi.kavin.rocks",
AUTO_PLAY: localStorage.getItem("autoplay") === "true",
}; };

View file

@ -152,9 +152,7 @@ export default {
this.player = player; this.player = player;
const disableVideo = const disableVideo = this.getPreferenceBoolean("listen", false) && !this.video.livestream;
((localStorage && localStorage.getItem("audioOnly") === "true") || this.$route.query.listen === "1") &&
!this.video.livestream;
this.player.configure("manifest.disableVideo", disableVideo); this.player.configure("manifest.disableVideo", disableVideo);
const quality = Number(localStorage.getItem("quality")); const quality = Number(localStorage.getItem("quality"));

View file

@ -44,7 +44,7 @@
<br /> <br />
<b>Audio Only</b> <b>Audio Only</b>
<br /> <br />
<input class="uk-checkbox" v-model="audioOnly" @change="onChange($event)" type="checkbox" /> <input class="uk-checkbox" v-model="listen" @change="onChange($event)" type="checkbox" />
<br /> <br />
<b>Default Quality</b> <b>Default Quality</b>
<br /> <br />
@ -104,13 +104,15 @@ export default {
skipMusicOffTopic: true, skipMusicOffTopic: true,
selectedTheme: "dark", selectedTheme: "dark",
autoPlayVideo: true, autoPlayVideo: true,
audioOnly: false, listen: false,
resolutions: [144, 240, 360, 480, 720, 1080, 1440, 2160, 4320], resolutions: [144, 240, 360, 480, 720, 1080, 1440, 2160, 4320],
defaultQuality: 0, defaultQuality: 0,
bufferingGoal: 10, bufferingGoal: 10,
}; };
}, },
mounted() { mounted() {
if (Object.keys(this.$route.query).length > 0) this.$router.replace({ query: {} });
fetch("https://raw.githubusercontent.com/wiki/TeamPiped/Piped-Frontend/Instances.md") fetch("https://raw.githubusercontent.com/wiki/TeamPiped/Piped-Frontend/Instances.md")
.then(resp => resp.text()) .then(resp => resp.text())
.then(body => { .then(body => {
@ -136,7 +138,7 @@ export default {
if (localStorage) { if (localStorage) {
this.selectedInstance = localStorage.getItem("instance") || "https://pipedapi.kavin.rocks"; this.selectedInstance = localStorage.getItem("instance") || "https://pipedapi.kavin.rocks";
this.sponsorBlock = localStorage.getItem("sponsorblock") || true; this.sponsorBlock = this.getPreferenceBoolean("sponsorblock", true);
if (localStorage.getItem("selectedSkip") !== null) { if (localStorage.getItem("selectedSkip") !== null) {
var skipList = localStorage.getItem("selectedSkip").split(","); var skipList = localStorage.getItem("selectedSkip").split(",");
this.skipSponsor = this.skipIntro = this.skipOutro = this.skipInteraction = this.skipSelfPromo = this.skipMusicOffTopic = false; this.skipSponsor = this.skipIntro = this.skipOutro = this.skipInteraction = this.skipSelfPromo = this.skipMusicOffTopic = false;
@ -167,10 +169,9 @@ export default {
}); });
} }
this.selectedTheme = localStorage.getItem("theme") || "dark"; this.selectedTheme = this.getPreferenceString("theme", "dark");
this.autoPlayVideo = this.autoPlayVideo = this.getPreferenceBoolean(localStorage.getItem("playerAutoPlay"), true);
localStorage.getItem("playerAutoPlay") === null || localStorage.getItem("playerAutoPlay") === "true"; this.listen = this.getPreferenceBoolean("listen", false);
this.audioOnly = localStorage.getItem("audioOnly") === "true";
this.defaultQuality = Number(localStorage.getItem("quality")); this.defaultQuality = Number(localStorage.getItem("quality"));
this.bufferingGoal = Math.max(Number(localStorage.getItem("bufferGoal")), 10); this.bufferingGoal = Math.max(Number(localStorage.getItem("bufferGoal")), 10);
} }
@ -180,7 +181,7 @@ export default {
if (localStorage) { if (localStorage) {
var shouldReload = false; var shouldReload = false;
if (localStorage.getItem("playerAutoPlay") !== this.autoPlayVideo) shouldReload = true; if (this.getPreferenceString("theme", "dark") !== this.selectedTheme) shouldReload = true;
localStorage.setItem("instance", this.selectedInstance); localStorage.setItem("instance", this.selectedInstance);
localStorage.setItem("sponsorblock", this.sponsorBlock); localStorage.setItem("sponsorblock", this.sponsorBlock);
@ -196,7 +197,7 @@ export default {
localStorage.setItem("theme", this.selectedTheme); localStorage.setItem("theme", this.selectedTheme);
localStorage.setItem("playerAutoPlay", this.autoPlayVideo); localStorage.setItem("playerAutoPlay", this.autoPlayVideo);
localStorage.setItem("audioOnly", this.audioOnly); localStorage.setItem("listen", this.listen);
localStorage.setItem("quality", this.defaultQuality); localStorage.setItem("quality", this.defaultQuality);
localStorage.setItem("bufferGoal", this.bufferingGoal); localStorage.setItem("bufferGoal", this.bufferingGoal);

View file

@ -125,7 +125,7 @@ export default {
}; };
}, },
mounted() { mounted() {
this.selectedAutoPlay = Constants.AUTO_PLAY; this.selectedAutoPlay = this.getPreferenceBoolean("autoplay", true);
this.getVideoData(); this.getVideoData();
this.getSponsors(); this.getSponsors();
this.getComments(); this.getComments();
@ -150,16 +150,19 @@ export default {
async fetchSponsors() { async fetchSponsors() {
return await this.fetchJson(Constants.BASE_URL + "/sponsors/" + this.getVideoId(), { return await this.fetchJson(Constants.BASE_URL + "/sponsors/" + this.getVideoId(), {
category: category:
localStorage && localStorage.getItem("selectedSkip") !== null '["' +
? '["' + localStorage.getItem("selectedSkip").replace(",", '","') + '"]' this.getPreferenceString("selectedSkip", "sponsor,interaction,selfpromo,music_offtopic").replaceAll(
: '["sponsor", "interaction", "selfpromo", "music_offtopic"]', ",",
'","',
) +
'"]',
}); });
}, },
fetchComments() { fetchComments() {
return this.fetchJson(Constants.BASE_URL + "/comments/" + this.getVideoId()); return this.fetchJson(Constants.BASE_URL + "/comments/" + this.getVideoId());
}, },
onChange() { onChange() {
if (localStorage) localStorage.setItem("autoplay", this.selectedAutoPlay); this.setPreference("autoplay", this.selectedAutoPlay);
}, },
async getVideoData() { async getVideoData() {
this.fetchVideo() this.fetchVideo()
@ -182,7 +185,7 @@ export default {
}); });
}, },
async getSponsors() { async getSponsors() {
if (!localStorage || localStorage.getItem("sponsorblock") !== false) if (this.getPreferenceBoolean("sponsorblock", true))
this.fetchSponsors().then(data => (this.sponsors = data)); this.fetchSponsors().then(data => (this.sponsors = data));
}, },
async getComments() { async getComments() {

View file

@ -67,23 +67,46 @@ const mixin = {
}, },
purifyHTML(original) { purifyHTML(original) {
return DOMPurify.sanitize(original); return DOMPurify.sanitize(original);
},
setPreference(key, value) {
if (localStorage) localStorage.setItem(key, value)
},
getPreferenceBoolean(key, defaultVal) {
var value;
if ((value = this.$route.query[key]) !== undefined || (localStorage && (value = localStorage.getItem(key)) !== null)) {
switch (String(value)) {
case "true":
case "1":
case "on":
case "yes":
return true;
default:
return false;
} }
} else return defaultVal;
},
getPreferenceString(key, defaultVal) {
var value;
if ((value = this.$route.query[key]) !== undefined || (localStorage && (value = localStorage.getItem(key)) !== null)) {
return value;
} else return defaultVal;
},
}, },
computed: { computed: {
backgroundColor() { backgroundColor() {
return localStorage.getItem("theme") === "light" ? "#fff" : "#0b0e0f" return this.getPreferenceString("theme", "dark") === "light" ? "#fff" : "#0b0e0f"
}, },
secondaryBackgroundColor() { secondaryBackgroundColor() {
return localStorage.getItem("theme") === "light" ? "#e5e5e5" : "#242727" return this.getPreferenceString("theme", "dark") === "light" ? "#e5e5e5" : "#242727"
}, },
foregroundColor() { foregroundColor() {
return localStorage.getItem("theme") === "light" ? "#15191a" : "#0b0e0f" return this.getPreferenceString("theme", "dark") === "light" ? "#15191a" : "#0b0e0f"
}, },
secondaryForegroundColor() { secondaryForegroundColor() {
return localStorage.getItem("theme") === "light" ? "#666" : "#393d3d" return this.getPreferenceString("theme", "dark") === "light" ? "#666" : "#393d3d"
}, },
darkMode() { darkMode() {
return localStorage.getItem('theme') !== 'light' return this.getPreferenceString("theme", "dark") !== 'light'
} }
} }
}; };