Changed rough time calculation to only use real time or end time.

Also fixed getting the replay button element.
This commit is contained in:
Ajay Ramachandran
2020-05-11 21:04:10 -04:00
parent aec287f0cf
commit 57eb122fce
3 changed files with 10 additions and 23 deletions

View File

@@ -260,7 +260,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
} }
setTimeToNow(index: number) { setTimeToNow(index: number) {
this.setTimeTo(index, this.props.contentContainer().getRoughCurrentTime()); this.setTimeTo(index, this.props.contentContainer().getRealCurrentTime());
} }
setTimeToEnd() { setTimeToEnd() {

View File

@@ -116,7 +116,7 @@ var skipNoticeContentContainer: ContentContainer = () => ({
changeStartSponsorButton, changeStartSponsorButton,
previewTime, previewTime,
videoInfo, videoInfo,
getRoughCurrentTime getRealCurrentTime: getRealCurrentTime
}); });
//get messages from the background script and the popup //get messages from the background script and the popup
@@ -180,7 +180,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any
return return
case "getCurrentTime": case "getCurrentTime":
sendResponse({ sendResponse({
currentTime: getRoughCurrentTime() currentTime: getRealCurrentTime()
}); });
break; break;
@@ -1131,29 +1131,16 @@ async function updateVisibilityOfPlayerControlsButton(): Promise<boolean> {
* current time is out of date while scrubbing or at the end of the video. This is not needed * 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. * for sponsor skipping as the video is not playing during these times.
*/ */
function getRoughCurrentTime(): number { function getRealCurrentTime(): 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;
}
// Used to check if replay button // 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"; 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) { if (playButtonSVGData === replaceSVGData) {
// At the end of the video // At the end of the video
return video.duration; 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 { } else {
return video.currentTime; return video.currentTime;
} }
@@ -1168,11 +1155,11 @@ function startSponsorClicked() {
//add to sponsorTimes //add to sponsorTimes
if (sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) { if (sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) {
//it is an end time //it is an end time
sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment[1] = getRoughCurrentTime(); sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment[1] = getRealCurrentTime();
} else { } else {
//it is a start time //it is a start time
sponsorTimesSubmitting.push({ sponsorTimesSubmitting.push({
segment: [getRoughCurrentTime()], segment: [getRealCurrentTime()],
UUID: null, UUID: null,
// Default to sponsor // Default to sponsor
category: "sponsor" category: "sponsor"

View File

@@ -18,7 +18,7 @@ interface ContentContainer {
changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise<boolean>, changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise<boolean>,
previewTime: (time: number) => void, previewTime: (time: number) => void,
videoInfo: any, videoInfo: any,
getRoughCurrentTime: () => number getRealCurrentTime: () => number
} }
} }