mirror of
https://github.com/TeamPiped/Piped.git
synced 2025-01-21 20:17:00 +00:00
feat: allow timecode to be used as timestamp in Share Modal
This commit is contained in:
parent
73ce4bfb2e
commit
aaeddb3903
@ -70,24 +70,29 @@ export default {
|
||||
timeStamp: null,
|
||||
hasPlaylist: false,
|
||||
showQrCode: false,
|
||||
durations: [1, 60, 60 * 60, 60 * 60 * 24],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
generatedLink() {
|
||||
var baseUrl = this.pipedLink
|
||||
const baseUrl = this.pipedLink
|
||||
? window.location.origin + "/watch?v=" + this.videoId
|
||||
: "https://youtu.be/" + this.videoId;
|
||||
var url = new URL(baseUrl);
|
||||
if (this.withTimeCode && this.timeStamp > 0) url.searchParams.append("t", this.timeStamp);
|
||||
const url = new URL(baseUrl);
|
||||
|
||||
if (this.withTimeCode && this.timeStamp)
|
||||
url.searchParams.append("t", this.parseTimeStampToSeconds(this.timeStamp));
|
||||
|
||||
if (this.hasPlaylist && this.withPlaylist) {
|
||||
url.searchParams.append("list", this.playlistId);
|
||||
url.searchParams.append("index", this.playlistIndex);
|
||||
}
|
||||
|
||||
return url.href;
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.timeStamp = parseInt(this.currentTime);
|
||||
this.timeStamp = this.parseSecondsToTimeStamp(this.currentTime ?? 0);
|
||||
this.withTimeCode = this.getPreferenceBoolean("shareWithTimeCode", true);
|
||||
this.pipedLink = this.getPreferenceBoolean("shareAsPipedLink", true);
|
||||
this.withPlaylist = this.getPreferenceBoolean("shareWithPlaylist", true);
|
||||
@ -108,6 +113,26 @@ export default {
|
||||
alert(this.$t("info.cannot_copy"));
|
||||
}
|
||||
},
|
||||
parseTimeStampToSeconds(timestamp) {
|
||||
const timeArray = timestamp.split(":").reverse();
|
||||
let seconds = 0;
|
||||
for (let i = 0; i < timeArray.length; i++) {
|
||||
seconds += timeArray[i] * this.durations[i];
|
||||
}
|
||||
return seconds;
|
||||
},
|
||||
parseSecondsToTimeStamp(seconds) {
|
||||
const timeArray = [];
|
||||
const durationsReversed = this.durations.toReversed();
|
||||
for (let i in durationsReversed) {
|
||||
const currentValue = Math.floor(seconds / durationsReversed[i]);
|
||||
if (currentValue > 0) {
|
||||
timeArray.push(currentValue.toString().padStart(2, "0"));
|
||||
seconds -= currentValue * durationsReversed[i];
|
||||
}
|
||||
}
|
||||
return timeArray.join(":");
|
||||
},
|
||||
onChange() {
|
||||
this.setPreference("shareWithTimeCode", this.withTimeCode, true);
|
||||
this.setPreference("shareAsPipedLink", this.pipedLink, true);
|
||||
|
@ -128,7 +128,7 @@
|
||||
"piped_link": "Piped link",
|
||||
"follow_link": "Follow link",
|
||||
"copy_link": "Copy link",
|
||||
"time_code": "Time code (in seconds)",
|
||||
"time_code": "Time code (in seconds or HH:MM:SS)",
|
||||
"show_chapters": "Chapters",
|
||||
"store_search_history": "Store Search History",
|
||||
"hide_watched": "Hide watched videos in the feed",
|
||||
|
Loading…
Reference in New Issue
Block a user