diff options
-rw-r--r-- | background.js | 6 | ||||
-rw-r--r-- | content.js | 126 | ||||
-rw-r--r-- | firefox_manifest.json | 4 | ||||
-rw-r--r-- | icons/PlayerDeleteIconSponsorBlocker256px.png | bin | 0 -> 11626 bytes | |||
-rw-r--r-- | manifest.json | 3 | ||||
-rw-r--r-- | popup.css | 12 | ||||
-rw-r--r-- | popup.html | 26 | ||||
-rw-r--r-- | popup.js | 130 |
8 files changed, 282 insertions, 25 deletions
diff --git a/background.js b/background.js index 446bf0bc..adb86553 100644 --- a/background.js +++ b/background.js @@ -100,12 +100,14 @@ function submitVote(type, UUID, callback) { } else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) { //duplicate vote callback({ - successType: 0 + successType: 0, + statusCode: xmlhttp.status }); } else if (error) { //error while connect callback({ - successType: -1 + successType: -1, + statusCode: xmlhttp.status }); } }) @@ -31,6 +31,8 @@ var showingStartSponsor = true; //should the video controls buttons be added var hideVideoPlayerControls = false; +var hideInfoButtonPlayerControls = false; +var hideDeleteButtonPlayerControls = false; //becomes true when isInfoFound is called //this is used to close the popup on YouTube when the other popup opens @@ -103,6 +105,14 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes hideVideoPlayerControls = request.value; updateVisibilityOfPlayerControlsButton(); + } else if (request.message == "changeInfoButtonPlayerControlsVisibility") { + hideInfoButtonPlayerControls = request.value; + + updateVisibilityOfPlayerControlsButton(); + } else if (request.message == "changeDeleteButtonPlayerControlsVisibility") { + hideDeleteButtonPlayerControls = request.value; + + updateVisibilityOfPlayerControlsButton(); } if (request.message == "trackViewCount") { @@ -160,13 +170,12 @@ 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); } } }); - //see if video control buttons should be added + //see if video controls buttons should be added chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) { if (result.hideVideoPlayerControls != undefined) { hideVideoPlayerControls = result.hideVideoPlayerControls; @@ -174,6 +183,21 @@ function videoIDChange(id) { updateVisibilityOfPlayerControlsButton(); }); + chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) { + if (result.hideInfoButtonPlayerControls != undefined) { + hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls; + } + + updateVisibilityOfPlayerControlsButton(); + }); + chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) { + if (result.hideDeleteButtonPlayerControls != undefined) { + hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls; + } + + updateVisibilityOfPlayerControlsButton(); + }); + } function sponsorsLookup(id) { @@ -297,10 +321,17 @@ function removePlayerControlsButton() { function updateVisibilityOfPlayerControlsButton() { addPlayerControlsButton(); addInfoButton(); + addDeleteButton(); addSubmitButton(); if (hideVideoPlayerControls) { removePlayerControlsButton(); } + if (hideInfoButtonPlayerControls) { + document.getElementById("infoButton").style.display = "none"; + } + if (hideDeleteButtonPlayerControls) { + document.getElementById("deleteButton").style.display = "none"; + } } function startSponsorClicked() { @@ -318,12 +349,19 @@ function startSponsorClicked() { } function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) { + //if it isn't visible, there is no data + if (uploadButtonVisible && !hideDeleteButtonPlayerControls) { + 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"); document.getElementById("startSponsorButton").setAttribute("title", "Sponsor Starts Now"); - if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible) { + if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !hideInfoButtonPlayerControls) { document.getElementById("submitButton").style.display = "unset"; } else if (!uploadButtonVisible) { //disable submit button @@ -369,6 +407,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) { @@ -427,6 +493,10 @@ function openInfoMenu() { popup.appendChild(popupFrame); let parentNode = document.getElementById("secondary"); + if (parentNode == null) { + //old youtube theme + parentNode = document.getElementById("watch7-sidebar-contents"); + } parentNode.prepend(popup); } @@ -441,6 +511,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) { @@ -646,8 +741,13 @@ function vote(type, UUID) { //failure: duplicate vote addLoadingInfo("It seems you've already voted before", UUID) } else if (response.successType == -1) { - //failure: duplicate vote - addLoadingInfo("A connection error has occured.", UUID) + if (response.statusCode == 502) { + addLoadingInfo("It seems the sever is down. Contact the dev immediately.", UUID) + } else { + //failure: unknown error + addLoadingInfo("A connection error has occured. Error code: " + response.statusCode, UUID) + } + } } }); @@ -706,7 +806,7 @@ function submitSponsorTimes() { if (sponsorTimes != undefined && sponsorTimes.length > 0) { let confirmMessage = "Are you sure you want to submit this?\n\n" + getSponsorTimesMessage(sponsorTimes); - confirmMessage += "\n\nTo see more information, open the popup by clicking the extensions icon in the top right corner." + confirmMessage += "\n\nTo edit or delete values, click the info button or open the extension popup by clicking the extension icon in the top right corner." if(!confirm(confirmMessage)) return; sendSubmitMessage(); @@ -748,6 +848,18 @@ function sendSubmitMessage(){ //show that the upload failed document.getElementById("submitButton").style.animation = "unset"; document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png"); + + if(response.statusCode == 400) { + alert("Server said this request was invalid"); + } else if(response.statusCode == 429) { + alert("You have submitted too many sponsor times for this one video, are you sure there are this many?"); + } else if(response.statusCode == 409) { + alert("This has already been submitted before"); + } else if(response.statusCode == 502) { + alert("It seems the server is down. Contact the dev to inform them. Error code " + response.statusCode); + } else { + alert("There was an error submitting your sponsor times, please try again later. Error code " + response.statusCode); + } } } }); 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 Binary files differnew file mode 100644 index 00000000..c44f383d --- /dev/null +++ b/icons/PlayerDeleteIconSponsorBlocker256px.png diff --git a/manifest.json b/manifest.json index c14a16aa..b683f4d7 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "SponsorBlock for YouTube - Skip Sponsorships", "short_name": "SponsorBlock", - "version": "1.0.15", + "version": "1.0.16", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.", "content_scripts": [ { @@ -28,6 +28,7 @@ "icons/upvote.png", "icons/downvote.png", "icons/PlayerInfoIconSponsorBlocker256px.png", + "icons/PlayerDeleteIconSponsorBlocker256px.png", "popup.html" ], "permissions": [ @@ -29,12 +29,24 @@ body { font-size: 12px; } +.sponsorTime { + font-size: 20px; +} + .smallLink { font-size: 10px; text-decoration: underline; cursor: pointer; } +.mediumLink { + font-size: 15px; + padding-left: 15px; + padding-right: 15px; + text-decoration: underline; + cursor: pointer; +} + .greenButton { background-color:#ec1c1c; -moz-border-radius:28px; @@ -126,11 +126,11 @@ <h3>Options</h3> - <button id="hideVideoPlayerControls" class="warningButton">Hide Button On YouTube Player</button> - <button id="showVideoPlayerControls" style="display: none" class="warningButton">Show Button On YouTube Player</button> + <button id="hideVideoPlayerControls" class="warningButton">Hide Buttons On YouTube Player</button> + <button id="showVideoPlayerControls" style="display: none" class="warningButton">Show Buttons On YouTube Player</button> <br/> <sub> - This hides the button that appears on the YouTube player to submit sponsors. I can see this being annoying for some + This hides the buttons that appear on the YouTube player to submit sponsors. I can see this being annoying for some people. Instead of using the button there, this popup can be used to submit sponsors. To hide the notice that appears, use the button that appears on the notice saying "Don't show this again". You can always enable these settings again later. @@ -139,6 +139,26 @@ <br/> <br/> + <button id="hideInfoButtonPlayerControls" class="warningButton">Hide Info Button On YouTube Player</button> + <button id="showInfoButtonPlayerControls" style="display: none" class="warningButton">Show Info Button On YouTube Player</button> + <br/> + <sub> + This is the button that opens up a popup in the YouTube page. + </sub> + + <br/> + <br/> + + <button id="hideDeleteButtonPlayerControls" class="warningButton">Hide Delete Button On YouTube Player</button> + <button id="showDeleteButtonPlayerControls" style="display: none" class="warningButton">Show Delete Button On YouTube Player</button> + <br/> + <sub> + This is the button that allows you to clear all sponsors on the YouTube player. + </sub> + + <br/> + <br/> + <button id="disableSponsorViewTracking" class="warningButton">Disable Sponsor View Tracking</button> <button id="enableSponsorViewTracking" style="display: none" class="warningButton">Enable Sponsor View Tracking</button> <br/> @@ -8,6 +8,10 @@ SB.submitTimes = document.getElementById("submitTimes"); SB.showNoticeAgain = document.getElementById("showNoticeAgain"); SB.hideVideoPlayerControls = document.getElementById("hideVideoPlayerControls"); SB.showVideoPlayerControls = document.getElementById("showVideoPlayerControls"); +SB.hideInfoButtonPlayerControls = document.getElementById("hideInfoButtonPlayerControls"); +SB.showInfoButtonPlayerControls = document.getElementById("showInfoButtonPlayerControls"); +SB.hideDeleteButtonPlayerControls = document.getElementById("hideDeleteButtonPlayerControls"); +SB.showDeleteButtonPlayerControls = document.getElementById("showDeleteButtonPlayerControls"); SB.disableSponsorViewTracking = document.getElementById("disableSponsorViewTracking"); SB.enableSponsorViewTracking = document.getElementById("enableSponsorViewTracking"); SB.optionsButton = document.getElementById("optionsButton"); @@ -31,6 +35,10 @@ SB.submitTimes.addEventListener("click", submitTimes); SB.showNoticeAgain.addEventListener("click", showNoticeAgain); SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls); SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls); +SB.hideInfoButtonPlayerControls.addEventListener("click", hideInfoButtonPlayerControls); +SB.showInfoButtonPlayerControls.addEventListener("click", showInfoButtonPlayerControls); +SB.hideDeleteButtonPlayerControls.addEventListener("click", hideDeleteButtonPlayerControls); +SB.showDeleteButtonPlayerControls.addEventListener("click", showDeleteButtonPlayerControls); SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking); SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking); SB.optionsButton.addEventListener("click", openOptions); @@ -79,7 +87,7 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) { } }); -//show proper video player controls option +//show proper video player controls options chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) { let hideVideoPlayerControls = result.hideVideoPlayerControls; if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) { @@ -87,6 +95,20 @@ chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) { SB.showVideoPlayerControls.style.display = "unset"; } }); +chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) { + let hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls; + if (hideInfoButtonPlayerControls != undefined && hideInfoButtonPlayerControls) { + SB.hideInfoButtonPlayerControls.style.display = "none"; + SB.showInfoButtonPlayerControls.style.display = "unset"; + } +}); +chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) { + let hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls; + if (hideDeleteButtonPlayerControls != undefined && hideDeleteButtonPlayerControls) { + SB.hideDeleteButtonPlayerControls.style.display = "none"; + SB.showDeleteButtonPlayerControls.style.display = "unset"; + } +}); //show proper tracking option chrome.storage.sync.get(["trackViewCount"], function(result) { @@ -353,12 +375,13 @@ function getSponsorTimesMessageDiv(sponsorTimes) { for (let i = 0; i < sponsorTimes.length; i++) { let currentSponsorTimeContainer = document.createElement("div"); currentSponsorTimeContainer.id = "sponsorTimeContainer" + i; + currentSponsorTimeContainer.className = "sponsorTime"; let currentSponsorTimeMessage = ""; let deleteButton = document.createElement("span"); deleteButton.id = "sponsorTimeDeleteButton" + i; deleteButton.innerText = "Delete"; - deleteButton.className = "smallLink"; + deleteButton.className = "mediumLink"; let index = i; deleteButton.addEventListener("click", () => deleteSponsorTime(index)); @@ -368,7 +391,7 @@ function getSponsorTimesMessageDiv(sponsorTimes) { let editButton = document.createElement("span"); editButton.id = "sponsorTimeEditButton" + i; editButton.innerText = "Edit"; - editButton.className = "smallLink"; + editButton.className = "mediumLink"; editButton.addEventListener("click", () => editSponsorTime(index)); for (let s = 0; s < sponsorTimes[i].length; s++) { @@ -385,12 +408,13 @@ function getSponsorTimesMessageDiv(sponsorTimes) { } currentSponsorTimeContainer.innerText = currentSponsorTimeMessage; + currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index)); + sponsorTimesContainer.appendChild(currentSponsorTimeContainer); sponsorTimesContainer.appendChild(deleteButton); //only if it is a complete sponsor time if (sponsorTimes[i].length > 1) { - sponsorTimesContainer.appendChild(spacer); sponsorTimesContainer.appendChild(editButton); } } @@ -399,32 +423,41 @@ function getSponsorTimesMessageDiv(sponsorTimes) { } function editSponsorTime(index) { + if (document.getElementById("startTimeMinutes" + index) != null) { + //already open + return; + } + let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index); //get sponsor time minutes and seconds boxes let startTimeMinutes = document.createElement("input"); startTimeMinutes.id = "startTimeMinutes" + index; + startTimeMinutes.className = "sponsorTime"; startTimeMinutes.type = "text"; startTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][0]); - startTimeMinutes.style.width = "35"; + startTimeMinutes.style.width = "45"; let startTimeSeconds = document.createElement("input"); startTimeSeconds.id = "startTimeSeconds" + index; + startTimeSeconds.className = "sponsorTime"; startTimeSeconds.type = "text"; startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]); - startTimeSeconds.style.width = "42"; + startTimeSeconds.style.width = "60"; let endTimeMinutes = document.createElement("input"); endTimeMinutes.id = "endTimeMinutes" + index; + endTimeMinutes.className = "sponsorTime"; endTimeMinutes.type = "text"; endTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][1]); - endTimeMinutes.style.width = "35"; + endTimeMinutes.style.width = "45"; let endTimeSeconds = document.createElement("input"); endTimeSeconds.id = "endTimeSeconds" + index; + endTimeSeconds.className = "sponsorTime"; endTimeSeconds.type = "text"; endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]); - endTimeSeconds.style.width = "42"; + endTimeSeconds.style.width = "60"; let colonText = document.createElement("span"); colonText.innerText = ":"; @@ -449,7 +482,7 @@ function editSponsorTime(index) { let saveButton = document.createElement("span"); saveButton.id = "sponsorTimeSaveButton" + index; saveButton.innerText = "Save"; - saveButton.className = "smallLink"; + saveButton.className = "mediumLink"; saveButton.addEventListener("click", () => saveSponsorTimeEdit(index)); let editButton = document.getElementById("sponsorTimeEditButton" + index); @@ -576,6 +609,9 @@ function submitTimes() { } else if(response.statusCode == 409) { document.getElementById("submitTimesInfoMessage").innerText = "This has already been submitted before"; document.getElementById("submitTimesInfoMessageContainer").style.display = "unset"; + } else if(response.statusCode == 502) { + document.getElementById("submitTimesInfoMessage").innerText = "It seems the server is down. Contact the dev to inform them. Error code " + response.statusCode; + document.getElementById("submitTimesInfoMessageContainer").style.display = "unset"; } else { document.getElementById("submitTimesInfoMessage").innerText = "There was an error submitting your sponsor times, please try again later. Error code " + response.statusCode; document.getElementById("submitTimesInfoMessageContainer").style.display = "unset"; @@ -634,6 +670,74 @@ function showVideoPlayerControls() { SB.showVideoPlayerControls.style.display = "none"; } +function hideInfoButtonPlayerControls() { + chrome.storage.sync.set({"hideInfoButtonPlayerControls": true}); + + chrome.tabs.query({ + active: true, + currentWindow: true + }, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, { + message: "changeInfoButtonPlayerControlsVisibility", + value: true + }); + }); + + SB.hideInfoButtonPlayerControls.style.display = "none"; + SB.showInfoButtonPlayerControls.style.display = "unset"; +} + +function showInfoButtonPlayerControls() { + chrome.storage.sync.set({"hideInfoButtonPlayerControls": false}); + + chrome.tabs.query({ + active: true, + currentWindow: true + }, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, { + message: "changeVideoPlayerCochangeInfoButtonPlayerControlsVisibilityntrolsVisibility", + value: false + }); + }); + + SB.hideInfoButtonPlayerControls.style.display = "unset"; + SB.showInfoButtonPlayerControls.style.display = "none"; +} + +function hideDeleteButtonPlayerControls() { + chrome.storage.sync.set({"hideDeleteButtonPlayerControls": true}); + + chrome.tabs.query({ + active: true, + currentWindow: true + }, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, { + message: "changeDeleteButtonPlayerControlsVisibility", + value: true + }); + }); + + SB.hideDeleteButtonPlayerControls.style.display = "none"; + SB.showDeleteButtonPlayerControls.style.display = "unset"; +} + +function showDeleteButtonPlayerControls() { + chrome.storage.sync.set({"hideDeleteButtonPlayerControls": false}); + + chrome.tabs.query({ + active: true, + currentWindow: true + }, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, { + message: "changeVideoPlayerCochangeDeleteButtonPlayerControlsVisibilityntrolsVisibility", + value: false + }); + }); + + SB.hideDeleteButtonPlayerControls.style.display = "unset"; + SB.showDeleteButtonPlayerControls.style.display = "none"; +} + function disableSponsorViewTracking() { chrome.storage.sync.set({"trackViewCount": false}); @@ -747,8 +851,12 @@ function vote(type, UUID) { //failure: duplicate vote addVoteMessage("You have already voted this way before.", UUID) } else if (response.successType == -1) { - //failure: duplicate vote - addVoteMessage("A connection error has occured.", UUID) + if (response.statusCode == 502) { + addVoteMessage("It seems the sever is down. Contact the dev immediately.", UUID) + } else { + //failure: unknown error + addVoteMessage("A connection error has occured. Error code: " + response.statusCode, UUID) + } } } }); |