Skip to content

Commit

Permalink
Added clear button.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jul 30, 2019
1 parent e0d2436 commit 1119adf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
64 changes: 62 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down Expand Up @@ -297,6 +296,7 @@ function removePlayerControlsButton() {
function updateVisibilityOfPlayerControlsButton() {
addPlayerControlsButton();
addInfoButton();
addDeleteButton();
addSubmitButton();
if (hideVideoPlayerControls) {
removePlayerControlsButton();
Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion firefox_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file added icons/PlayerDeleteIconSponsorBlocker256px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"icons/upvote.png",
"icons/downvote.png",
"icons/PlayerInfoIconSponsorBlocker256px.png",
"icons/PlayerDeleteIconSponsorBlocker256px.png",
"popup.html"
],
"permissions": [
Expand Down

0 comments on commit 1119adf

Please sign in to comment.