Skip to content

Commit

Permalink
Added ability to disable auto skip.
Browse files Browse the repository at this point in the history
Resolves #131 and #162
  • Loading branch information
ajayyy committed Dec 3, 2019
1 parent 381c11e commit cd5207f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 13 deletions.
15 changes: 15 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,20 @@
},
"errorCode": {
"message": "Error Code: "
},
"noticeTitleNotSkipped": {
"message": "Skip Sponsor?"
},
"skip": {
"message": "Skip"
},
"disableAutoSkip": {
"message": "Disable Auto Skip"
},
"enableAutoSkip": {
"message": "Enable Auto Skip"
},
"autoSkipDescription": {
"message": "Auto skip will skip sponsors for you. If disabled, a notice will appear asking if you'd like to skip."
}
}
15 changes: 13 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ chrome.storage.sync.get(["disableSkipping"], function(result) {
}
});

//should skips be manual
var disableAutoSkip = false;
chrome.storage.sync.get(["disableAutoSkip"], function(result) {
let disableAutoSkipStorage = result.disableAutoSkip;
if (disableAutoSkipStorage != undefined) {
disableAutoSkip = disableAutoSkipStorage;
}
});

//should view counts be tracked
var trackViewCount = false;
chrome.storage.sync.get(["trackViewCount"], function(result) {
Expand Down Expand Up @@ -606,7 +615,9 @@ function checkIfTimeToSkip(currentVideoTime, startTime, endTime) {

//skip fromt he start time to the end time for a certain index sponsor time
function skipToTime(v, index, sponsorTimes, openNotice) {
v.currentTime = sponsorTimes[index][1];
if (!disableAutoSkip) {
v.currentTime = sponsorTimes[index][1];
}

lastSponsorTimeSkipped = sponsorTimes[index][0];

Expand All @@ -616,7 +627,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
if (openNotice) {
//send out the message saying that a sponsor message was skipped
if (!dontShowNotice) {
let skipNotice = new SkipNotice(this, currentUUID);
let skipNotice = new SkipNotice(this, currentUUID, disableAutoSkip);

if (dontShowNoticeOld) {
//show why this notice is showing
Expand Down
10 changes: 10 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ <h2 id="setUsernameStatus"></h2>

<h3>__MSG_Options__</h3>

<button id="disableAutoSkip" class="warningButton popupElement">__MSG_disableAutoSkip__</button>
<button id="enableAutoSkip" style="display: none" class="warningButton popupElement">__MSG_enableAutoSkip__</button>
<br/>
<sub class="popupElement">
__MSG_autoSkipDescription__
</sub>

<br/>
<br/>

<span id="keybindButtons">
<button id="setStartSponsorKeybind" class="warningButton popupElement">__MSG_setStartSponsorShortcut__</button>
<br/>
Expand Down
29 changes: 29 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function runThePopup() {
// More controls
"clearTimes",
"submitTimes",
// options
"showNoticeAgain",
"disableAutoSkip",
"enableAutoSkip",
"hideVideoPlayerControls",
"showVideoPlayerControls",
"hideInfoButtonPlayerControls",
Expand Down Expand Up @@ -89,6 +92,8 @@ function runThePopup() {
SB.clearTimes.addEventListener("click", clearTimes);
SB.submitTimes.addEventListener("click", submitTimes);
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
SB.disableAutoSkip.addEventListener("click", () => setAutoSkip(true));
SB.enableAutoSkip.addEventListener("click", () => setAutoSkip(false));
SB.setStartSponsorKeybind.addEventListener("click", () => setKeybind(true));
SB.setSubmitKeybind.addEventListener("click", () => setKeybind(false));
SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
Expand Down Expand Up @@ -157,6 +162,15 @@ function runThePopup() {
SB.showNoticeAgain.style.display = "unset";
}
});

//show proper auto skip option
chrome.storage.sync.get(["disableAutoSkip"], function(result) {
let disableAutoSkip = result.disableAutoSkip;
if (disableAutoSkip != undefined && disableAutoSkip) {
SB.disableAutoSkip.style.display = "none";
SB.enableAutoSkip.style.display = "unset";
}
});

//show proper video player controls options
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
Expand Down Expand Up @@ -859,6 +873,21 @@ function runThePopup() {

SB.showNoticeAgain.style.display = "none";
}

function setAutoSkip(value) {
chrome.storage.sync.set({"disableAutoSkip": value});

if (value) {
// If it isn't shown, they can't manually skip
showNoticeAgain();

SB.disableAutoSkip.style.display = "none";
SB.enableAutoSkip.style.display = "unset";
} else {
SB.enableAutoSkip.style.display = "none";
SB.disableAutoSkip.style.display = "unset";
}
}

function hideVideoPlayerControls() {
chrome.storage.sync.set({"hideVideoPlayerControls": true});
Expand Down
70 changes: 59 additions & 11 deletions utils/skipNotice.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
'use strict';

//The notice that tells the user that a sponsor was just skipped
/**
* The notice that tells the user that a sponsor was just skipped
*/
class SkipNotice {
constructor(parent, UUID) {
/**
* @param {HTMLElement} parent
* @param {String} UUID
* @param {String} noticeTitle
* @param {boolean} manualSkip
*/
constructor(parent, UUID, manualSkip = false) {
this.parent = parent;
this.UUID = UUID;
this.manualSkip = manualSkip;

let noticeTitle = chrome.i18n.getMessage("noticeTitle");

if (manualSkip) {
noticeTitle = chrome.i18n.getMessage("noticeTitleNotSkipped");
}

this.maxCountdownTime = () => 4;
//the countdown until this notice closes
Expand Down Expand Up @@ -54,7 +69,7 @@ class SkipNotice {
noticeMessage.id = "sponsorSkipMessage" + this.idSuffix;
noticeMessage.classList.add("sponsorSkipMessage");
noticeMessage.classList.add("sponsorSkipObject");
noticeMessage.innerText = chrome.i18n.getMessage("noticeTitle");
noticeMessage.innerText = noticeTitle;

//create the first column
logoColumn.appendChild(logoElement);
Expand Down Expand Up @@ -136,7 +151,10 @@ class SkipNotice {
dontShowAgainButton.className = "sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton";
dontShowAgainButton.addEventListener("click", dontShowNoticeAgain);

dontshowContainer.appendChild(dontShowAgainButton);
// Don't let them hide it if manually skipping
if (!this.manualSkip) {
dontshowContainer.appendChild(dontShowAgainButton);
}

//add to row
secondRow.appendChild(voteButtonsContainer);
Expand Down Expand Up @@ -165,6 +183,10 @@ class SkipNotice {

referenceNode.prepend(noticeElement);

if (manualSkip) {
this.unskippedMode(chrome.i18n.getMessage("skip"));
}

this.startCountdown();
}

Expand Down Expand Up @@ -228,10 +250,13 @@ class SkipNotice {
unskip() {
unskipSponsorTime(this.UUID);

this.unskippedMode(chrome.i18n.getMessage("reskip"));
}

/** Sets up notice to be not skipped yet */
unskippedMode(buttonText) {
//change unskip button to a reskip button
let unskipButton = document.getElementById("sponsorSkipUnskipButton" + this.idSuffix);
unskipButton.innerText = chrome.i18n.getMessage("reskip");
unskipButton.removeEventListener("click", this.unskipCallback);
let unskipButton = this.changeUnskipButton(buttonText);

//setup new callback
this.unskipCallback = this.reskip.bind(this);
Expand All @@ -252,10 +277,8 @@ class SkipNotice {
reskip() {
reskipSponsorTime(this.UUID);

//change unskip button to a reskip button
let unskipButton = document.getElementById("sponsorSkipUnskipButton" + this.idSuffix);
unskipButton.innerText = chrome.i18n.getMessage("unskip");
unskipButton.removeEventListener("click", this.unskipCallback);
//change reskip button to a unskip button
let unskipButton = this.changeUnskipButton(chrome.i18n.getMessage("unskip"));

//setup new callback
this.unskipCallback = this.unskip.bind(this);
Expand All @@ -265,6 +288,25 @@ class SkipNotice {
this.maxCountdownTime = () => 4;
this.countdownTime = this.maxCountdownTime();
this.updateTimerDisplay();

// See if the title should be changed
if (this.manualSkip) {
this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle"));
}
}

/**
* Changes the text on the reskip button
*
* @param {string} text
* @returns {HTMLElement} unskipButton
*/
changeUnskipButton(text) {
let unskipButton = document.getElementById("sponsorSkipUnskipButton" + this.idSuffix);
unskipButton.innerText = text;
unskipButton.removeEventListener("click", this.unskipCallback);

return unskipButton;
}

afterDownvote() {
Expand Down Expand Up @@ -293,6 +335,12 @@ class SkipNotice {
}
}
}

changeNoticeTitle(title) {
let noticeElement = document.getElementById("sponsorSkipMessage" + this.idSuffix);

noticeElement.innerText = title;
}

addNoticeInfoMessage(message, message2) {
let previousInfoMessage = document.getElementById("sponsorTimesInfoMessage" + this.idSuffix);
Expand Down

0 comments on commit cd5207f

Please sign in to comment.