mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +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;
|
sponsorLookupRetries = 0;
|
||||||
|
|
||||||
//empty the preview bar
|
//empty the preview bar
|
||||||
previewBar = null;
|
previewBar.set([], [], 0);
|
||||||
|
|
||||||
//reset sponsor data found check
|
//reset sponsor data found check
|
||||||
sponsorDataFound = false;
|
sponsorDataFound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function videoIDChange(id) {
|
function videoIDChange(id) {
|
||||||
// ID has not changed return
|
//if the id has not changed return
|
||||||
if (sponsorVideoID === id) 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) {
|
if (previewBar == null) {
|
||||||
//create it
|
//create it
|
||||||
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
|
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
|
||||||
previewBar = new PreviewBar(progressBar);
|
previewBar = new PreviewBar(progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetValues();
|
||||||
|
|
||||||
|
//id is not valid
|
||||||
|
if (id === false) return;
|
||||||
|
|
||||||
//warn them if they had unsubmitted times
|
//warn them if they had unsubmitted times
|
||||||
if (previousVideoID != null) {
|
if (previousVideoID != null) {
|
||||||
//get the sponsor times from storage
|
//get the sponsor times from storage
|
||||||
@@ -256,9 +259,6 @@ function videoIDChange(id) {
|
|||||||
//close popup
|
//close popup
|
||||||
closeInfoMenu();
|
closeInfoMenu();
|
||||||
|
|
||||||
//see if there is a video start time
|
|
||||||
youtubeVideoStartTime = sponsorVideoID;
|
|
||||||
|
|
||||||
sponsorsLookup(id);
|
sponsorsLookup(id);
|
||||||
|
|
||||||
//make sure everything is properly added
|
//make sure everything is properly added
|
||||||
@@ -546,46 +546,51 @@ function reskipSponsorTime(UUID) {
|
|||||||
function removePlayerControlsButton() {
|
function removePlayerControlsButton() {
|
||||||
if (!sponsorVideoID) return;
|
if (!sponsorVideoID) return;
|
||||||
|
|
||||||
document.getElementById("changeStartSponsor").style.display = "none";
|
document.getElementById("startSponsorButton").style.display = "none";
|
||||||
document.getElementById("submitButton").style.display = "none";
|
document.getElementById("submitButton").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function createButton(baseID, title, callback, imageName, isDraggable=false) {
|
function createButton(baseID, title, callback, imageName, isDraggable=false) {
|
||||||
if (document.getElementById(baseID+"Button") != null) return;
|
|
||||||
// Button HTML
|
if (document.getElementById(baseID+"Button") != null) return;
|
||||||
let newButton = document.createElement("button");
|
|
||||||
newButton.draggable = isDraggable;
|
// Button HTML
|
||||||
newButton.id = baseID+"Button";
|
let newButton = document.createElement("button");
|
||||||
newButton.className = "ytp-button playerButton";
|
newButton.draggable = isDraggable;
|
||||||
newButton.setAttribute("title", chrome.i18n.getMessage(title));
|
newButton.id = baseID+"Button";
|
||||||
newButton.addEventListener("click", callback);
|
newButton.className = "ytp-button playerButton";
|
||||||
// Image HTML
|
newButton.setAttribute("title", chrome.i18n.getMessage(title));
|
||||||
let newButtonImage = document.createElement("img");
|
newButton.addEventListener("click", callback);
|
||||||
newButton.draggable = isDraggable;
|
|
||||||
newButtonImage.id = baseID+"Image";
|
// Image HTML
|
||||||
newButtonImage.className = "playerButtonImage";
|
let newButtonImage = document.createElement("img");
|
||||||
newButtonImage.src = chrome.extension.getURL("icons/"+imageName);
|
newButton.draggable = isDraggable;
|
||||||
// Append image to button
|
newButtonImage.id = baseID+"Image";
|
||||||
newButton.appendChild(newButtonImage);
|
newButtonImage.className = "playerButtonImage";
|
||||||
// Add the button to player
|
newButtonImage.src = chrome.extension.getURL("icons/"+imageName);
|
||||||
controls.prepend(newButton);
|
|
||||||
|
// Append image to button
|
||||||
|
newButton.appendChild(newButtonImage);
|
||||||
|
|
||||||
|
// Add the button to player
|
||||||
|
controls.prepend(newButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getControls() {
|
function getControls() {
|
||||||
let controls = document.getElementsByClassName("ytp-right-controls");
|
let controls = document.getElementsByClassName("ytp-right-controls");
|
||||||
return (!controls || controls.length === 0) ? false : controls[controls.length - 1]
|
return (!controls || controls.length === 0) ? false : controls[controls.length - 1]
|
||||||
};
|
};
|
||||||
|
|
||||||
//adds the player controls buttons
|
//adds the player controls buttons
|
||||||
function addButtons() {
|
function addButtons() {
|
||||||
wait(getControls).then(result => {
|
wait(getControls).then(result => {
|
||||||
controls = result; // Global
|
controls = result; // Global
|
||||||
// Add button if does not already exist in html
|
// Add button if does not already exist in html
|
||||||
createButton("startSponsor", "sponsorStart", startSponsorClicked, "PlayerStartIconSponsorBlocker256px.png");
|
createButton("startSponsor", "sponsorStart", startSponsorClicked, "PlayerStartIconSponsorBlocker256px.png");
|
||||||
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker256px.png")
|
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker256px.png")
|
||||||
createButton("delete", "clearTimes", clearSponsorTimes, "PlayerDeleteIconSponsorBlocker256px.png");
|
createButton("delete", "clearTimes", clearSponsorTimes, "PlayerDeleteIconSponsorBlocker256px.png");
|
||||||
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker256px.png");
|
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker256px.png");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//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() {
|
||||||
@@ -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) {
|
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||||
if(!sponsorVideoID) return false;
|
if(!sponsorVideoID) return false;
|
||||||
wait(isSubmitLoaded).then(result => {
|
wait(isSubmitButtonLoaded).then(result => {
|
||||||
//if it isn't visible, there is no data
|
//if it isn't visible, there is no data
|
||||||
let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset":"none"
|
let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset":"none"
|
||||||
document.getElementById("deleteButton").style.display = shouldHide;
|
document.getElementById("deleteButton").style.display = shouldHide;
|
||||||
|
|||||||
12
utils.js
12
utils.js
@@ -38,14 +38,4 @@ function getYouTubeVideoID(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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