aboutsummaryrefslogtreecommitdiffhomepage
path: root/content.js
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-08-02 12:18:56 -0400
committerAjay Ramachandran <[email protected]>2019-08-02 12:18:56 -0400
commit1c1fb6006c6a6389de7aa36c9477bee7d5549079 (patch)
treecaf91be0757d2da9a281924f139165ef55e6fec3 /content.js
parent6cb07b5be3ebe3d714f89f2da73a7c6e6b22d396 (diff)
downloadSponsorBlock-1c1fb6006c6a6389de7aa36c9477bee7d5549079.tar.gz
SponsorBlock-1c1fb6006c6a6389de7aa36c9477bee7d5549079.zip
Added support for loading a channel page first.
Still has some issues on slow PCs, see https://github.com/ajayyy/SponsorBlock/issues/60
Diffstat (limited to 'content.js')
-rw-r--r--content.js24
1 files changed, 20 insertions, 4 deletions
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);
}