Added support for loading a channel page first.

Still has some issues on slow PCs, see https://github.com/ajayyy/SponsorBlock/issues/60
This commit is contained in:
Ajay Ramachandran
2019-08-02 12:18:56 -04:00
parent 6cb07b5be3
commit 1c1fb6006c

View File

@@ -171,6 +171,9 @@ function videoIDChange(id) {
sponsorDataFound = false; sponsorDataFound = false;
sponsorsLookup(id); sponsorsLookup(id);
//make sure everything is properly added
updateVisibilityOfPlayerControlsButton();
//reset sponsor times submitting //reset sponsor times submitting
sponsorTimesSubmitting = []; sponsorTimesSubmitting = [];
@@ -224,6 +227,9 @@ function videoIDChange(id) {
function sponsorsLookup(id) { function sponsorsLookup(id) {
v = document.querySelector('video') // Youtube video player v = document.querySelector('video') // Youtube video player
//there is no video here
if (v == null) return;
//check database for sponsor times //check database for sponsor times
sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) { sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
@@ -367,7 +373,8 @@ function addPlayerControlsButton() {
//add the image to the button //add the image to the button
startSponsorButton.appendChild(startSponsorImage); 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); referenceNode.prepend(startSponsorButton);
} }
@@ -379,6 +386,9 @@ function removePlayerControlsButton() {
//adds or removes the player controls button to what it should be //adds or removes the player controls button to what it should be
function updateVisibilityOfPlayerControlsButton() { function updateVisibilityOfPlayerControlsButton() {
//not on a proper video yet
if (!getYouTubeVideoID(document.URL)) return;
addPlayerControlsButton(); addPlayerControlsButton();
addInfoButton(); addInfoButton();
addDeleteButton(); addDeleteButton();
@@ -482,7 +492,9 @@ function addInfoButton() {
//add the image to the button //add the image to the button
infoButton.appendChild(infoImage); 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); referenceNode.prepend(infoButton);
} }
@@ -510,7 +522,9 @@ function addDeleteButton() {
//add the image to the button //add the image to the button
deleteButton.appendChild(deleteImage); 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); referenceNode.prepend(deleteButton);
} }
@@ -538,7 +552,9 @@ function addSubmitButton() {
//add the image to the button //add the image to the button
submitButton.appendChild(submitImage); 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); referenceNode.prepend(submitButton);
} }