Merge pull request #395 from NDevTK/patch-1

Added config option for excluding skipped content from the video duration
This commit is contained in:
Ajay Ramachandran
2020-07-03 20:58:01 -04:00
committed by GitHub
5 changed files with 65 additions and 3 deletions

View File

@@ -289,6 +289,12 @@
"audioNotificationDescription": { "audioNotificationDescription": {
"message": "Audio notification on skip will play a sound whenever a sponsor is skipped. If disabled (or auto skip is disabled), no sound will be played." "message": "Audio notification on skip will play a sound whenever a sponsor is skipped. If disabled (or auto skip is disabled), no sound will be played."
}, },
"showTimeWithSkips": {
"message": "Show Time With Skips Removed"
},
"showTimeWithSkipsDescription": {
"message": "This time appears in brackets next to the current time on below the seekbar. This shows the total video duration minus any segments. This includes segments marked as only \"Show In Seekbar\"."
},
"youHaveSkipped": { "youHaveSkipped": {
"message": "You have skipped " "message": "You have skipped "
}, },

View File

@@ -271,6 +271,23 @@
<br/> <br/>
<br/> <br/>
<div option-type="toggle" sync-option="showTimeWithSkips">
<label class="switch-container" label-name="__MSG_showTimeWithSkips__">
<label class="switch">
<input type="checkbox" checked>
<span class="slider round"></span>
</label>
</label>
<br/>
<br/>
<div class="small-description">__MSG_showTimeWithSkipsDescription__</div>
</div>
<br/>
<br/>
<div option-type="toggle" sync-option="trackViewCount"> <div option-type="toggle" sync-option="trackViewCount">
<label class="switch-container" label-name="__MSG_enableViewTracking__"> <label class="switch-container" label-name="__MSG_enableViewTracking__">
<label class="switch"> <label class="switch">

View File

@@ -15,6 +15,7 @@ interface SBConfig {
skipCount: number, skipCount: number,
sponsorTimesContributed: number, sponsorTimesContributed: number,
submissionCountSinceCategories: number, // New count used to show the "Read The Guidelines!!" message submissionCountSinceCategories: number, // New count used to show the "Read The Guidelines!!" message
showTimeWithSkips: boolean,
unsubmittedWarning: boolean, unsubmittedWarning: boolean,
disableSkipping: boolean, disableSkipping: boolean,
trackViewCount: boolean, trackViewCount: boolean,
@@ -133,6 +134,7 @@ var Config: SBObject = {
skipCount: 0, skipCount: 0,
sponsorTimesContributed: 0, sponsorTimesContributed: 0,
submissionCountSinceCategories: 0, submissionCountSinceCategories: 0,
showTimeWithSkips: true,
unsubmittedWarning: true, unsubmittedWarning: true,
disableSkipping: false, disableSkipping: false,
trackViewCount: true, trackViewCount: true,

View File

@@ -818,6 +818,10 @@ function updatePreviewBar() {
previewBar.set(utils.getSegmentsFromSponsorTimes(allSponsorTimes), types, video.duration) previewBar.set(utils.getSegmentsFromSponsorTimes(allSponsorTimes), types, video.duration)
if (Config.config.showTimeWithSkips) {
showTimeWithoutSkips(allSponsorTimes);
}
//update last video id //update last video id
lastPreviewBarUpdate = sponsorVideoID; lastPreviewBarUpdate = sponsorVideoID;
} }
@@ -1593,3 +1597,36 @@ function updateAdFlag() {
updateVisibilityOfPlayerControlsButton(); updateVisibilityOfPlayerControlsButton();
} }
} }
function showTimeWithoutSkips(allSponsorTimes): void {
let skipDuration = 0;
// Calculate skipDuration based from the segments in the preview bar
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 = utils.getFormattedTime(video.duration - skipDuration);
const durationID = "sponsorBlockDurationAfterSkips";
let duration = document.getElementById(durationID);
// Create span if needed
if(duration === null) {
duration = document.createElement('span');
duration.id = durationID;
duration.classList.add("ytp-time-duration");
display.appendChild(duration);
}
duration.innerText = (skipDuration <= 0 || isNaN(skipDuration)) ? "" : " ("+formatedTime+")";
}

View File

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