mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
Fixed formatting issues + previewBar not displaying.
Also changed the isSubmitButtonLoaded function to be checking for the right button and fixed the startSponsorButton not hiding. Useless function was removed.
This commit is contained in:
92
content.js
92
content.js
@@ -206,28 +206,31 @@ function resetValues() {
|
||||
sponsorLookupRetries = 0;
|
||||
|
||||
//empty the preview bar
|
||||
previewBar = null;
|
||||
previewBar.set([], [], 0);
|
||||
|
||||
//reset sponsor data found check
|
||||
sponsorDataFound = false;
|
||||
}
|
||||
|
||||
function videoIDChange(id) {
|
||||
// ID has not changed return
|
||||
//if the id has not changed return
|
||||
if (sponsorVideoID === id) return
|
||||
// Global ID
|
||||
sponsorVideoID = id;
|
||||
resetValues();
|
||||
|
||||
// ID is not valid
|
||||
if (id === false) return;
|
||||
|
||||
//set the global videoID
|
||||
sponsorVideoID = id;
|
||||
|
||||
//setup the preview bar
|
||||
if (previewBar == null) {
|
||||
//create it
|
||||
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
|
||||
previewBar = new PreviewBar(progressBar);
|
||||
}
|
||||
|
||||
resetValues();
|
||||
|
||||
//id is not valid
|
||||
if (id === false) return;
|
||||
|
||||
//warn them if they had unsubmitted times
|
||||
if (previousVideoID != null) {
|
||||
//get the sponsor times from storage
|
||||
@@ -256,9 +259,6 @@ function videoIDChange(id) {
|
||||
//close popup
|
||||
closeInfoMenu();
|
||||
|
||||
//see if there is a video start time
|
||||
youtubeVideoStartTime = sponsorVideoID;
|
||||
|
||||
sponsorsLookup(id);
|
||||
|
||||
//make sure everything is properly added
|
||||
@@ -546,46 +546,51 @@ function reskipSponsorTime(UUID) {
|
||||
function removePlayerControlsButton() {
|
||||
if (!sponsorVideoID) return;
|
||||
|
||||
document.getElementById("changeStartSponsor").style.display = "none";
|
||||
document.getElementById("startSponsorButton").style.display = "none";
|
||||
document.getElementById("submitButton").style.display = "none";
|
||||
}
|
||||
|
||||
function createButton(baseID, title, callback, imageName, isDraggable=false) {
|
||||
if (document.getElementById(baseID+"Button") != null) return;
|
||||
// Button HTML
|
||||
let newButton = document.createElement("button");
|
||||
newButton.draggable = isDraggable;
|
||||
newButton.id = baseID+"Button";
|
||||
newButton.className = "ytp-button playerButton";
|
||||
newButton.setAttribute("title", chrome.i18n.getMessage(title));
|
||||
newButton.addEventListener("click", callback);
|
||||
// Image HTML
|
||||
let newButtonImage = document.createElement("img");
|
||||
newButton.draggable = isDraggable;
|
||||
newButtonImage.id = baseID+"Image";
|
||||
newButtonImage.className = "playerButtonImage";
|
||||
newButtonImage.src = chrome.extension.getURL("icons/"+imageName);
|
||||
// Append image to button
|
||||
newButton.appendChild(newButtonImage);
|
||||
// Add the button to player
|
||||
controls.prepend(newButton);
|
||||
|
||||
if (document.getElementById(baseID+"Button") != null) return;
|
||||
|
||||
// Button HTML
|
||||
let newButton = document.createElement("button");
|
||||
newButton.draggable = isDraggable;
|
||||
newButton.id = baseID+"Button";
|
||||
newButton.className = "ytp-button playerButton";
|
||||
newButton.setAttribute("title", chrome.i18n.getMessage(title));
|
||||
newButton.addEventListener("click", callback);
|
||||
|
||||
// Image HTML
|
||||
let newButtonImage = document.createElement("img");
|
||||
newButton.draggable = isDraggable;
|
||||
newButtonImage.id = baseID+"Image";
|
||||
newButtonImage.className = "playerButtonImage";
|
||||
newButtonImage.src = chrome.extension.getURL("icons/"+imageName);
|
||||
|
||||
// Append image to button
|
||||
newButton.appendChild(newButtonImage);
|
||||
|
||||
// Add the button to player
|
||||
controls.prepend(newButton);
|
||||
}
|
||||
|
||||
function getControls() {
|
||||
let controls = document.getElementsByClassName("ytp-right-controls");
|
||||
return (!controls || controls.length === 0) ? false : controls[controls.length - 1]
|
||||
let controls = document.getElementsByClassName("ytp-right-controls");
|
||||
return (!controls || controls.length === 0) ? false : controls[controls.length - 1]
|
||||
};
|
||||
|
||||
//adds the player controls buttons
|
||||
function addButtons() {
|
||||
wait(getControls).then(result => {
|
||||
controls = result; // Global
|
||||
// Add button if does not already exist in html
|
||||
createButton("startSponsor", "sponsorStart", startSponsorClicked, "PlayerStartIconSponsorBlocker256px.png");
|
||||
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker256px.png")
|
||||
createButton("delete", "clearTimes", clearSponsorTimes, "PlayerDeleteIconSponsorBlocker256px.png");
|
||||
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker256px.png");
|
||||
});
|
||||
wait(getControls).then(result => {
|
||||
controls = result; // Global
|
||||
// Add button if does not already exist in html
|
||||
createButton("startSponsor", "sponsorStart", startSponsorClicked, "PlayerStartIconSponsorBlocker256px.png");
|
||||
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker256px.png")
|
||||
createButton("delete", "clearTimes", clearSponsorTimes, "PlayerDeleteIconSponsorBlocker256px.png");
|
||||
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker256px.png");
|
||||
});
|
||||
}
|
||||
//adds or removes the player controls button to what it should be
|
||||
function updateVisibilityOfPlayerControlsButton() {
|
||||
@@ -638,11 +643,14 @@ function updateSponsorTimesSubmitting() {
|
||||
});
|
||||
}
|
||||
|
||||
isSubmitLoaded = () => (document.getElementById("startSponsorImage") !== null);
|
||||
//is the submit button on the player loaded yet
|
||||
function isSubmitButtonLoaded() {
|
||||
return document.getElementById("submitButton") !== null;
|
||||
}
|
||||
|
||||
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||
if(!sponsorVideoID) return false;
|
||||
wait(isSubmitLoaded).then(result => {
|
||||
wait(isSubmitButtonLoaded).then(result => {
|
||||
//if it isn't visible, there is no data
|
||||
let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset":"none"
|
||||
document.getElementById("deleteButton").style.display = shouldHide;
|
||||
|
||||
12
utils.js
12
utils.js
@@ -38,14 +38,4 @@ function getYouTubeVideoID(url) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//returns the start time of the video if there was one specified (ex. ?t=5s)
|
||||
function getYouTubeVideoStartTime(url) {
|
||||
let searchParams = new URL(url).searchParams;
|
||||
let startTime = searchParams.get("t");
|
||||
if (startTime == null) {
|
||||
startTime = searchParams.get("time_continue");
|
||||
}
|
||||
return startTime;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user