mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Added clear button.
This commit is contained in:
64
content.js
64
content.js
@@ -160,8 +160,7 @@ function videoIDChange(id) {
|
|||||||
} else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
} else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
||||||
changeStartSponsorButton(false, true);
|
changeStartSponsorButton(false, true);
|
||||||
} else {
|
} else {
|
||||||
changeStartSponsorButton(true, true);
|
changeStartSponsorButton(true, false);
|
||||||
document.getElementById("submitButton").style.display = "none";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -297,6 +296,7 @@ function removePlayerControlsButton() {
|
|||||||
function updateVisibilityOfPlayerControlsButton() {
|
function updateVisibilityOfPlayerControlsButton() {
|
||||||
addPlayerControlsButton();
|
addPlayerControlsButton();
|
||||||
addInfoButton();
|
addInfoButton();
|
||||||
|
addDeleteButton();
|
||||||
addSubmitButton();
|
addSubmitButton();
|
||||||
if (hideVideoPlayerControls) {
|
if (hideVideoPlayerControls) {
|
||||||
removePlayerControlsButton();
|
removePlayerControlsButton();
|
||||||
@@ -318,6 +318,13 @@ function startSponsorClicked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||||
|
//if it isn't visible, there is no data
|
||||||
|
if (uploadButtonVisible) {
|
||||||
|
document.getElementById("deleteButton").style.display = "unset";
|
||||||
|
} else {
|
||||||
|
document.getElementById("deleteButton").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
if (showStartSponsor) {
|
if (showStartSponsor) {
|
||||||
showingStartSponsor = true;
|
showingStartSponsor = true;
|
||||||
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
||||||
@@ -369,6 +376,34 @@ function addInfoButton() {
|
|||||||
referenceNode.prepend(infoButton);
|
referenceNode.prepend(infoButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//shows the delete button on the video player
|
||||||
|
function addDeleteButton() {
|
||||||
|
if (document.getElementById("deleteButton") != null) {
|
||||||
|
//it's already added
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//make a submit button
|
||||||
|
let deleteButton = document.createElement("button");
|
||||||
|
deleteButton.id = "deleteButton";
|
||||||
|
deleteButton.className = "ytp-button playerButton";
|
||||||
|
deleteButton.setAttribute("title", "Clear Sponsor Times");
|
||||||
|
deleteButton.addEventListener("click", clearSponsorTimes);
|
||||||
|
//hide it at the start
|
||||||
|
deleteButton.style.display = "none";
|
||||||
|
|
||||||
|
let deleteImage = document.createElement("img");
|
||||||
|
deleteImage.id = "deleteButtonImage";
|
||||||
|
deleteImage.className = "playerButtonImage";
|
||||||
|
deleteImage.src = chrome.extension.getURL("icons/PlayerDeleteIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
//add the image to the button
|
||||||
|
deleteButton.appendChild(deleteImage);
|
||||||
|
|
||||||
|
let referenceNode = document.getElementsByClassName("ytp-right-controls")[0];
|
||||||
|
referenceNode.prepend(deleteButton);
|
||||||
|
}
|
||||||
|
|
||||||
//shows the submit button on the video player
|
//shows the submit button on the video player
|
||||||
function addSubmitButton() {
|
function addSubmitButton() {
|
||||||
if (document.getElementById("submitButton") != null) {
|
if (document.getElementById("submitButton") != null) {
|
||||||
@@ -445,6 +480,31 @@ function closeInfoMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearSponsorTimes() {
|
||||||
|
//it can't update to this info yet
|
||||||
|
closeInfoMenu();
|
||||||
|
|
||||||
|
let currentVideoID = getYouTubeVideoID(document.URL);
|
||||||
|
|
||||||
|
let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
|
||||||
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
|
let confirmMessage = "Are you sure you want to clear this?\n\n" + getSponsorTimesMessage(sponsorTimes);
|
||||||
|
confirmMessage += "\n\nTo edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
|
||||||
|
if(!confirm(confirmMessage)) return;
|
||||||
|
|
||||||
|
//clear the sponsor times
|
||||||
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
|
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
||||||
|
|
||||||
|
//set buttons to be correct
|
||||||
|
changeStartSponsorButton(true, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Opens the notice that tells the user that a sponsor was just skipped
|
//Opens the notice that tells the user that a sponsor was just skipped
|
||||||
function openSkipNotice(UUID){
|
function openSkipNotice(UUID){
|
||||||
if (dontShowNotice) {
|
if (dontShowNotice) {
|
||||||
|
|||||||
@@ -27,7 +27,9 @@
|
|||||||
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
||||||
"icons/upvote.png",
|
"icons/upvote.png",
|
||||||
"icons/downvote.png",
|
"icons/downvote.png",
|
||||||
"icons/PlayerInfoIconSponsorBlocker256px.png"
|
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerDeleteIconSponsorBlocker256px.png",
|
||||||
|
"popup.html"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
|
|||||||
BIN
icons/PlayerDeleteIconSponsorBlocker256px.png
Normal file
BIN
icons/PlayerDeleteIconSponsorBlocker256px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -28,6 +28,7 @@
|
|||||||
"icons/upvote.png",
|
"icons/upvote.png",
|
||||||
"icons/downvote.png",
|
"icons/downvote.png",
|
||||||
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerDeleteIconSponsorBlocker256px.png",
|
||||||
"popup.html"
|
"popup.html"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
|||||||
Reference in New Issue
Block a user