diff --git a/content.js b/content.js index 6233a922..c9262d99 100644 --- a/content.js +++ b/content.js @@ -160,8 +160,7 @@ function videoIDChange(id) { } else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { changeStartSponsorButton(false, true); } else { - changeStartSponsorButton(true, true); - document.getElementById("submitButton").style.display = "none"; + changeStartSponsorButton(true, false); } } }); @@ -297,6 +296,7 @@ function removePlayerControlsButton() { function updateVisibilityOfPlayerControlsButton() { addPlayerControlsButton(); addInfoButton(); + addDeleteButton(); addSubmitButton(); if (hideVideoPlayerControls) { removePlayerControlsButton(); @@ -318,6 +318,13 @@ function startSponsorClicked() { } 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) { showingStartSponsor = true; document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png"); @@ -369,6 +376,34 @@ function addInfoButton() { 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 function addSubmitButton() { 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 function openSkipNotice(UUID){ if (dontShowNotice) { diff --git a/firefox_manifest.json b/firefox_manifest.json index 0fb7e834..d8e2296b 100644 --- a/firefox_manifest.json +++ b/firefox_manifest.json @@ -27,7 +27,9 @@ "icons/PlayerUploadFailedIconSponsorBlocker256px.png", "icons/upvote.png", "icons/downvote.png", - "icons/PlayerInfoIconSponsorBlocker256px.png" + "icons/PlayerInfoIconSponsorBlocker256px.png", + "icons/PlayerDeleteIconSponsorBlocker256px.png", + "popup.html" ], "permissions": [ "tabs", diff --git a/icons/PlayerDeleteIconSponsorBlocker256px.png b/icons/PlayerDeleteIconSponsorBlocker256px.png new file mode 100644 index 00000000..c44f383d Binary files /dev/null and b/icons/PlayerDeleteIconSponsorBlocker256px.png differ diff --git a/manifest.json b/manifest.json index c14a16aa..74a04979 100644 --- a/manifest.json +++ b/manifest.json @@ -28,6 +28,7 @@ "icons/upvote.png", "icons/downvote.png", "icons/PlayerInfoIconSponsorBlocker256px.png", + "icons/PlayerDeleteIconSponsorBlocker256px.png", "popup.html" ], "permissions": [