mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 06:27:14 +03:00
Reuse existing functions
This commit is contained in:
@@ -801,7 +801,7 @@ function updatePreviewBar() {
|
|||||||
if (localSponsorTimes == null) localSponsorTimes = [];
|
if (localSponsorTimes == null) localSponsorTimes = [];
|
||||||
|
|
||||||
let allSponsorTimes = localSponsorTimes.concat(sponsorTimesSubmitting);
|
let allSponsorTimes = localSponsorTimes.concat(sponsorTimesSubmitting);
|
||||||
hideSponsorTime(allSponsorTimes);
|
showTimeWithoutSkips(allSponsorTimes);
|
||||||
|
|
||||||
//create an array of the sponsor types
|
//create an array of the sponsor types
|
||||||
let types = [];
|
let types = [];
|
||||||
@@ -1607,22 +1607,25 @@ function formatTime(seconds) {
|
|||||||
].filter(Boolean).join(':');
|
].filter(Boolean).join(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSponsorTime(barTimes) {
|
function showTimeWithoutSkips(allSponsorTimes): void {
|
||||||
if(!Config.config.timeWithSkips) return
|
if(!Config.config.timeWithSkips) return;
|
||||||
|
|
||||||
let skipDuration = 0;
|
let skipDuration = 0;
|
||||||
|
|
||||||
// Calculate skipDuration based from the segments in the preview bar
|
// Calculate skipDuration based from the segments in the preview bar
|
||||||
for (let i = 0; i < barTimes.length; i++) {
|
for (let i = 0; i < allSponsorTimes.length; i++) {
|
||||||
let time = barTimes[i];
|
// If an end time exists
|
||||||
skipDuration += time.segment[1] - time.segment[0];
|
if (allSponsorTimes[i].segment[1]) {
|
||||||
|
skipDuration += allSponsorTimes[i].segment[1] - allSponsorTimes[i].segment[0];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// YouTube player time display
|
// YouTube player time display
|
||||||
let display = document.getElementsByClassName("ytp-time-display notranslate")[0];
|
let display = document.getElementsByClassName("ytp-time-display notranslate")[0];
|
||||||
if (display === undefined) return
|
if (display === undefined) return
|
||||||
|
|
||||||
let formatedTime = formatTime(video.duration - skipDuration);
|
let formatedTime = utils.getFormattedTime(video.duration - skipDuration);
|
||||||
|
|
||||||
const durationID = "durationAfterSkips";
|
const durationID = "durationAfterSkips";
|
||||||
let duration = document.getElementById(durationID);
|
let duration = document.getElementById(durationID);
|
||||||
@@ -1639,7 +1642,6 @@ function hideSponsorTime(barTimes) {
|
|||||||
duration.innerText = "";
|
duration.innerText = "";
|
||||||
display.getElementsByTagName("span")[2].innerText = formatedTime;
|
display.getElementsByTagName("span")[2].innerText = formatedTime;
|
||||||
} else {
|
} else {
|
||||||
// Empty if the time is the same
|
|
||||||
duration.innerText = (skipDuration === 0) ? "" : " ("+formatedTime+")";
|
duration.innerText = (skipDuration === 0) ? "" : " ("+formatedTime+")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ class Utils {
|
|||||||
secondsNum = Math.floor(secondsNum);
|
secondsNum = Math.floor(secondsNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
let secondsDisplay: string = String(secondsNum.toFixed(3));
|
let secondsDisplay: string = String(precise ? secondsNum.toFixed(3) : secondsNum);
|
||||||
|
|
||||||
if (secondsNum < 10) {
|
if (secondsNum < 10) {
|
||||||
//add a zero
|
//add a zero
|
||||||
|
|||||||
Reference in New Issue
Block a user