From 13d0e4a33a244037e35e95f9d9a6bd8720f07261 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 20:22:00 -0400 Subject: [PATCH] Made it still possible to vote on downvoted sponsors. Added "(hidden)" to the button. Resolves https://github.com/ajayyy/SponsorBlock/issues/28 --- content.js | 30 ++++++++++++++++++------------ popup.js | 9 ++++++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/content.js b/content.js index e7db1359..0a181560 100644 --- a/content.js +++ b/content.js @@ -7,6 +7,9 @@ var UUIDs = null; //what video id are these sponsors for var sponsorVideoID = null; +//these are sponsors that have been downvoted +var hiddenSponsorTimes = []; + //the time this video is starting at when first played, if not zero var youtubeVideoStartTime = null; @@ -106,6 +109,7 @@ function messageListener(request, sender, sendResponse) { sendResponse({ found: sponsorDataFound, sponsorTimes: sponsorTimes, + hiddenSponsorTimes: hiddenSponsorTimes, UUIDs: UUIDs }); @@ -431,7 +435,7 @@ function checkSponsorTime(sponsorTimes, index, openNotice) { lastTime = v.currentTime - 0.0001; } - if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0])) { + if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0]) && !hiddenSponsorTimes.includes(index)) { //skip it skipToTime(v, index, sponsorTimes, openNotice); @@ -945,21 +949,23 @@ function afterDownvote(UUID) { //remove this sponsor from the sponsors looked up //find which one it is - let removeIndex = -1; for (let i = 0; i < sponsorTimes.length; i++) { if (UUIDs[i] == UUID) { - //this one is the one to remove - removeIndex = i; + //this one is the one to hide + + //add this as a hidden sponsorTime + hiddenSponsorTimes.push(i); + + let sponsorTimesLeft = sponsorTimes.slice(); + for (let j = 0; j < hiddenSponsorTimes.length; j++) { + //remove this sponsor time + sponsorTimesLeft.splice(hiddenSponsorTimes[j], 1); + } + + //update the preview + previewBar.set(sponsorTimesLeft, [], v.duration); } } - - if (removeIndex != -1) { - //remove this sponsor time - sponsorTimes.splice(removeIndex, 1); - - //update the preview - previewBar.set(sponsorTimes, [], v.duration); - } } function addLoadingInfo(message, UUID) { diff --git a/popup.js b/popup.js index 71587889..220fb769 100644 --- a/popup.js +++ b/popup.js @@ -384,7 +384,14 @@ function runThePopup() { for (let i = 0; i < request.sponsorTimes.length; i++) { let sponsorTimeButton = document.createElement("button"); sponsorTimeButton.className = "warningButton popupElement"; - sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i][0]) + " to " + getFormattedTime(request.sponsorTimes[i][1]); + + let extraInfo = ""; + if (request.hiddenSponsorTimes.includes(i)) { + //this one is hidden + extraInfo = " (hidden)"; + } + + sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i][0]) + " to " + getFormattedTime(request.sponsorTimes[i][1]) + extraInfo; let votingButtons = document.createElement("div");