From 57eb122fce143a47e3ab4f6ec9e16e75245a419a Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 11 May 2020 21:04:10 -0400 Subject: [PATCH] Changed rough time calculation to only use real time or end time. Also fixed getting the replay button element. --- src/components/SponsorTimeEditComponent.tsx | 2 +- src/content.ts | 29 ++++++--------------- src/types.ts | 2 +- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index d6114788..73e9b422 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -260,7 +260,7 @@ class SponsorTimeEditComponent extends React.Component ({ changeStartSponsorButton, previewTime, videoInfo, - getRoughCurrentTime + getRealCurrentTime: getRealCurrentTime }); //get messages from the background script and the popup @@ -180,7 +180,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any return case "getCurrentTime": sendResponse({ - currentTime: getRoughCurrentTime() + currentTime: getRealCurrentTime() }); break; @@ -1131,29 +1131,16 @@ async function updateVisibilityOfPlayerControlsButton(): Promise { * current time is out of date while scrubbing or at the end of the video. This is not needed * for sponsor skipping as the video is not playing during these times. */ -function getRoughCurrentTime(): number { - let htmlCurrentTimeString = document.querySelector(".ytp-time-current").textContent; - let htmlDurationString = document.querySelector(".ytp-time-duration").textContent; - - if (htmlCurrentTimeString == htmlDurationString) { - // At the end of the video - return video.duration; - } - +function getRealCurrentTime(): number { // Used to check if replay button - let playButtonSVGData = document.querySelector("ytp-play-button")?.querySelector("ytp-svg-fill")?.getAttribute("d"); + let playButtonSVGData = document.querySelector(".ytp-play-button")?.querySelector(".ytp-svg-fill")?.getAttribute("d"); let replaceSVGData = "M 18,11 V 7 l -5,5 5,5 v -4 c 3.3,0 6,2.7 6,6 0,3.3 -2.7,6 -6,6 -3.3,0 -6,-2.7 -6,-6 h -2 c 0,4.4 3.6,8 8,8 4.4,0 8,-3.6 8,-8 0,-4.4 -3.6,-8 -8,-8 z"; + console.log(playButtonSVGData) + if (playButtonSVGData === replaceSVGData) { // At the end of the video return video.duration; - } - - let htmlCurrentTimeSections = htmlCurrentTimeString.split(":")[0]; - let htmlCurrentTime: number = parseInt(htmlCurrentTimeSections[0]) * 60 + parseInt(htmlCurrentTimeSections[1]); - - if (Math.abs(video.currentTime - htmlCurrentTime) > 3) { - return htmlCurrentTime; } else { return video.currentTime; } @@ -1168,11 +1155,11 @@ function startSponsorClicked() { //add to sponsorTimes if (sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) { //it is an end time - sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment[1] = getRoughCurrentTime(); + sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment[1] = getRealCurrentTime(); } else { //it is a start time sponsorTimesSubmitting.push({ - segment: [getRoughCurrentTime()], + segment: [getRealCurrentTime()], UUID: null, // Default to sponsor category: "sponsor" diff --git a/src/types.ts b/src/types.ts index fab2f1db..0bf80bd9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,7 @@ interface ContentContainer { changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise, previewTime: (time: number) => void, videoInfo: any, - getRoughCurrentTime: () => number + getRealCurrentTime: () => number } }