From 1c1fb6006c6a6389de7aa36c9477bee7d5549079 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 2 Aug 2019 12:18:56 -0400 Subject: Added support for loading a channel page first. Still has some issues on slow PCs, see https://github.com/ajayyy/SponsorBlock/issues/60 --- content.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'content.js') diff --git a/content.js b/content.js index 3d74fb1e..51222df2 100644 --- a/content.js +++ b/content.js @@ -171,6 +171,9 @@ function videoIDChange(id) { sponsorDataFound = false; sponsorsLookup(id); + //make sure everything is properly added + updateVisibilityOfPlayerControlsButton(); + //reset sponsor times submitting sponsorTimesSubmitting = []; @@ -223,6 +226,9 @@ function videoIDChange(id) { function sponsorsLookup(id) { v = document.querySelector('video') // Youtube video player + + //there is no video here + if (v == null) return; //check database for sponsor times sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) { @@ -367,7 +373,8 @@ function addPlayerControlsButton() { //add the image to the button startSponsorButton.appendChild(startSponsorImage); - let referenceNode = document.getElementsByClassName("ytp-right-controls")[0]; + let controls = document.getElementsByClassName("ytp-right-controls"); + let referenceNode = controls[controls.length - 1]; referenceNode.prepend(startSponsorButton); } @@ -379,6 +386,9 @@ function removePlayerControlsButton() { //adds or removes the player controls button to what it should be function updateVisibilityOfPlayerControlsButton() { + //not on a proper video yet + if (!getYouTubeVideoID(document.URL)) return; + addPlayerControlsButton(); addInfoButton(); addDeleteButton(); @@ -482,7 +492,9 @@ function addInfoButton() { //add the image to the button infoButton.appendChild(infoImage); - let referenceNode = document.getElementsByClassName("ytp-right-controls")[0]; + let controls = document.getElementsByClassName("ytp-right-controls"); + let referenceNode = controls[controls.length - 1]; + referenceNode.prepend(infoButton); } @@ -510,7 +522,9 @@ function addDeleteButton() { //add the image to the button deleteButton.appendChild(deleteImage); - let referenceNode = document.getElementsByClassName("ytp-right-controls")[0]; + let controls = document.getElementsByClassName("ytp-right-controls"); + let referenceNode = controls[controls.length - 1]; + referenceNode.prepend(deleteButton); } @@ -538,7 +552,9 @@ function addSubmitButton() { //add the image to the button submitButton.appendChild(submitImage); - let referenceNode = document.getElementsByClassName("ytp-right-controls")[0]; + let controls = document.getElementsByClassName("ytp-right-controls"); + let referenceNode = controls[controls.length - 1]; + referenceNode.prepend(submitButton); } -- cgit v1.2.3