From beea8181a12fe63856897647b1c8a189105dee4f Mon Sep 17 00:00:00 2001 From: NDevTK <31563761+NDevTK@users.noreply.github.com> Date: Fri, 26 Jun 2020 19:19:51 +0100 Subject: [PATCH 01/10] Added config option --- src/config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 634947a9..066e7fe0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,6 +5,7 @@ import Utils from "./utils"; const utils = new Utils(); interface SBConfig { + timeWithSkips: boolean, userID: string, sponsorTimes: SBMap, whitelistedChannels: string[], @@ -123,6 +124,7 @@ var Config: SBObject = { */ configListeners: [], defaults: { + timeWithSkips: false, userID: null, sponsorTimes: new SBMap("sponsorTimes"), whitelistedChannels: [], @@ -406,4 +408,4 @@ function addDefaults() { // Sync config setupConfig(); -export default Config; \ No newline at end of file +export default Config; From 0ebd7f4f8d1568e548c3ae05c1ef9a4671abbddf Mon Sep 17 00:00:00 2001 From: NDevTK <31563761+NDevTK@users.noreply.github.com> Date: Fri, 26 Jun 2020 19:33:19 +0100 Subject: [PATCH 02/10] Added duration override --- src/content.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index 86ae8342..33a402b2 100644 --- a/src/content.ts +++ b/src/content.ts @@ -801,7 +801,8 @@ function updatePreviewBar() { if (localSponsorTimes == null) localSponsorTimes = []; let allSponsorTimes = localSponsorTimes.concat(sponsorTimesSubmitting); - + hideSponsorTime(allSponsorTimes); + //create an array of the sponsor types let types = []; for (let i = 0; i < localSponsorTimes.length; i++) { @@ -1593,3 +1594,34 @@ function updateAdFlag() { updateVisibilityOfPlayerControlsButton(); } } + +function formatTime(seconds) { + if(isNaN(seconds)) return + const h = Math.floor(seconds / 3600); + const m = Math.floor((seconds % 3600) / 60); + const s = Math.round(seconds % 60); + return [ + h, + m > 9 ? m : (h ? '0' + m : m || '0'), + s > 9 ? s : '0' + s + ].filter(Boolean).join(':'); +} + +function hideSponsorTime(barTimes) { + if(!Config.config.timeWithSkips) return + + let skipDuration = 0; + + // Prevent dupicate UUID + let seen = []; + + for (let i = 0; i < barTimes.length; i++) { + let time = barTimes[i]; + if(seen.includes(time.UUID)) break; + seen.push(time.UUID); + skipDuration += time.segment[1] - time.segment[0]; + } + + let times = document.getElementsByClassName("ytp-time-display notranslate")[0].getElementsByTagName("span"); + times[2].innerText = formatTime(video.duration - skipDuration); +} From 3b59389cabe9ded12eeb9a2bf81523ba0e6dd0e3 Mon Sep 17 00:00:00 2001 From: NDevTK <31563761+NDevTK@users.noreply.github.com> Date: Sat, 27 Jun 2020 15:16:36 +0100 Subject: [PATCH 03/10] Added different ui option --- src/content.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/content.ts b/src/content.ts index 33a402b2..1e324d6f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1622,6 +1622,25 @@ function hideSponsorTime(barTimes) { skipDuration += time.segment[1] - time.segment[0]; } - let times = document.getElementsByClassName("ytp-time-display notranslate")[0].getElementsByTagName("span"); - times[2].innerText = formatTime(video.duration - skipDuration); + let display = document.getElementsByClassName("ytp-time-display notranslate")[0]; + if (display === undefined) return + + if(Config.config.hideRealTime) { + return display.getElementsByTagName("span")[2].innerText = formatTime(video.duration - skipDuration); + } + + const durationID = "durationAfterSkips"; + let duration; + + + duration = document.getElementById(durationID); + + // Create span if needed + if(duration === null) { + duration = document.createElement('span'); + duration.id = durationID; + display.appendChild(duration); + } + + duration.innerText = " ("+formatTime(video.duration - skipDuration)+")"; } From fd77748b15bd79346267f8b494b38ebac9f02162 Mon Sep 17 00:00:00 2001 From: NDevTK <31563761+NDevTK@users.noreply.github.com> Date: Sat, 27 Jun 2020 15:20:00 +0100 Subject: [PATCH 04/10] Updated config --- src/config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 066e7fe0..adf7f0fc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,6 +5,7 @@ import Utils from "./utils"; const utils = new Utils(); interface SBConfig { + hideRealTime: boolean, timeWithSkips: boolean, userID: string, sponsorTimes: SBMap, @@ -124,7 +125,8 @@ var Config: SBObject = { */ configListeners: [], defaults: { - timeWithSkips: false, + hideRealTime: false, + timeWithSkips: true, userID: null, sponsorTimes: new SBMap("sponsorTimes"), whitelistedChannels: [], From ec2950786fbc714a39474423f13060e863dd5c0e Mon Sep 17 00:00:00 2001 From: NDevTK <31563761+NDevTK@users.noreply.github.com> Date: Mon, 29 Jun 2020 17:52:28 +0100 Subject: [PATCH 05/10] Skip if skipDuration is 0 --- src/content.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content.ts b/src/content.ts index 1e324d6f..f6c39de1 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1622,6 +1622,8 @@ function hideSponsorTime(barTimes) { skipDuration += time.segment[1] - time.segment[0]; } + if(skipDuration === 0) return + let display = document.getElementsByClassName("ytp-time-display notranslate")[0]; if (display === undefined) return From 8d53e776b8b461e336541ec8690f7227ec1e690c Mon Sep 17 00:00:00 2001 From: NDevTK <31563761+NDevTK@users.noreply.github.com> Date: Mon, 29 Jun 2020 19:35:11 +0100 Subject: [PATCH 06/10] Do not show if skipDuration is 0 --- src/content.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/content.ts b/src/content.ts index f6c39de1..c01ec56e 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1612,30 +1612,20 @@ function hideSponsorTime(barTimes) { let skipDuration = 0; - // Prevent dupicate UUID - let seen = []; - + // Calculate skipDuration based from the segments in the preview bar for (let i = 0; i < barTimes.length; i++) { let time = barTimes[i]; - if(seen.includes(time.UUID)) break; - seen.push(time.UUID); skipDuration += time.segment[1] - time.segment[0]; } - if(skipDuration === 0) return - + // YouTube player time display let display = document.getElementsByClassName("ytp-time-display notranslate")[0]; if (display === undefined) return - if(Config.config.hideRealTime) { - return display.getElementsByTagName("span")[2].innerText = formatTime(video.duration - skipDuration); - } + let formatedTime = formatTime(video.duration - skipDuration); - const durationID = "durationAfterSkips"; - let duration; - - - duration = document.getElementById(durationID); + const durationID = "durationAfterSkips"; + let duration = document.getElementById(durationID); // Create span if needed if(duration === null) { @@ -1643,6 +1633,13 @@ function hideSponsorTime(barTimes) { duration.id = durationID; display.appendChild(duration); } - - duration.innerText = " ("+formatTime(video.duration - skipDuration)+")"; + + if(Config.config.hideRealTime) { + // Empty if not enabled + duration.innerText = ""; + display.getElementsByTagName("span")[2].innerText = formatedTime; + } else { + // Empty if the time is the same + duration.innerText = (skipDuration === 0) ? "" : " ("+formatedTime+")"; + } } From 77abc1d031d299302b6ac365e7a108d620a9f458 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 19:44:15 -0400 Subject: [PATCH 07/10] Reuse existing functions --- src/content.ts | 18 ++++++++++-------- src/utils.ts | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/content.ts b/src/content.ts index c01ec56e..e28acc26 100644 --- a/src/content.ts +++ b/src/content.ts @@ -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+")"; } } diff --git a/src/utils.ts b/src/utils.ts index 6e12a0e5..db766772 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 From bfafcd07cce81fb40ce8cb2d36b0309e14028a5a Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 19:56:08 -0400 Subject: [PATCH 08/10] Fix font issue, NaN issue and remove hide real time --- src/config.ts | 6 ++---- src/content.ts | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/config.ts b/src/config.ts index adf7f0fc..31880f48 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,8 +5,6 @@ import Utils from "./utils"; const utils = new Utils(); interface SBConfig { - hideRealTime: boolean, - timeWithSkips: boolean, userID: string, sponsorTimes: SBMap, whitelistedChannels: string[], @@ -17,6 +15,7 @@ interface SBConfig { skipCount: number, sponsorTimesContributed: number, submissionCountSinceCategories: number, // New count used to show the "Read The Guidelines!!" message + showTimeWithSkips: boolean, unsubmittedWarning: boolean, disableSkipping: boolean, trackViewCount: boolean, @@ -125,8 +124,6 @@ var Config: SBObject = { */ configListeners: [], defaults: { - hideRealTime: false, - timeWithSkips: true, userID: null, sponsorTimes: new SBMap("sponsorTimes"), whitelistedChannels: [], @@ -137,6 +134,7 @@ var Config: SBObject = { skipCount: 0, sponsorTimesContributed: 0, submissionCountSinceCategories: 0, + showTimeWithSkips: true, unsubmittedWarning: true, disableSkipping: false, trackViewCount: true, diff --git a/src/content.ts b/src/content.ts index e28acc26..6d8ae79b 100644 --- a/src/content.ts +++ b/src/content.ts @@ -801,7 +801,6 @@ function updatePreviewBar() { if (localSponsorTimes == null) localSponsorTimes = []; let allSponsorTimes = localSponsorTimes.concat(sponsorTimesSubmitting); - showTimeWithoutSkips(allSponsorTimes); //create an array of the sponsor types let types = []; @@ -819,6 +818,10 @@ function updatePreviewBar() { previewBar.set(utils.getSegmentsFromSponsorTimes(allSponsorTimes), types, video.duration) + if (Config.config.showTimeWithSkips) { + showTimeWithoutSkips(allSponsorTimes); + } + //update last video id lastPreviewBarUpdate = sponsorVideoID; } @@ -1608,8 +1611,6 @@ function formatTime(seconds) { } function showTimeWithoutSkips(allSponsorTimes): void { - if(!Config.config.timeWithSkips) return; - let skipDuration = 0; // Calculate skipDuration based from the segments in the preview bar @@ -1627,21 +1628,17 @@ function showTimeWithoutSkips(allSponsorTimes): void { let formatedTime = utils.getFormattedTime(video.duration - skipDuration); - const durationID = "durationAfterSkips"; - let duration = document.getElementById(durationID); + const durationID = "sponsorBlockDurationAfterSkips"; + let duration = document.getElementById(durationID); // Create span if needed if(duration === null) { duration = document.createElement('span'); - duration.id = durationID; + duration.id = durationID; + duration.classList.add("ytp-time-duration"); + display.appendChild(duration); } - if(Config.config.hideRealTime) { - // Empty if not enabled - duration.innerText = ""; - display.getElementsByTagName("span")[2].innerText = formatedTime; - } else { - duration.innerText = (skipDuration === 0) ? "" : " ("+formatedTime+")"; - } + duration.innerText = (skipDuration <= 0 || isNaN(skipDuration)) ? "" : " ("+formatedTime+")"; } From 8d41af073d895938c0c555ae4a75e5d13459af30 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 20:55:58 -0400 Subject: [PATCH 09/10] Added option to options page --- public/_locales/en/messages.json | 6 ++++++ public/options/options.html | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index a1beb859..44897364 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -289,6 +289,12 @@ "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." }, + "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": { "message": "You have skipped " }, diff --git a/public/options/options.html b/public/options/options.html index 51001ee6..5a5e6caa 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -268,6 +268,23 @@
__MSG_audioNotificationDescription__
+
+
+ +
+ + +
+
+ +
__MSG_showTimeWithSkipsDescription__
+
+

From c9a2edaf3d8c31a8d4b6ea63a54e89bd56f3a87c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 20:56:45 -0400 Subject: [PATCH 10/10] Remove unused function --- src/content.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/content.ts b/src/content.ts index 6d8ae79b..0feb3e61 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1598,18 +1598,6 @@ function updateAdFlag() { } } -function formatTime(seconds) { - if(isNaN(seconds)) return - const h = Math.floor(seconds / 3600); - const m = Math.floor((seconds % 3600) / 60); - const s = Math.round(seconds % 60); - return [ - h, - m > 9 ? m : (h ? '0' + m : m || '0'), - s > 9 ? s : '0' + s - ].filter(Boolean).join(':'); -} - function showTimeWithoutSkips(allSponsorTimes): void { let skipDuration = 0;