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