Skip to content

Commit

Permalink
Merge pull request #176 from ajayyy/experimental-ajay
Browse files Browse the repository at this point in the history
Better error messages and manual skipping
  • Loading branch information
ajayyy authored Dec 3, 2019
2 parents 62d4b36 + cd5207f commit d6aeec9
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 33 deletions.
24 changes: 21 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"409": {
"message": "This has already been submitted before"
},
"502": {
"message": "It seems the server is down. Contact the dev to inform them."
},
"channelWhitelisted": {
"message": "Channel Whitelisted!"
},
Expand Down Expand Up @@ -272,5 +269,26 @@
"yourWork": {
"message": "Your Work",
"description": "Used to describe the section that will show you the statistics from your submissions."
},
"502": {
"message": "The server seems to be overloaded. Try again in a few seconds."
},
"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."
}
}
3 changes: 0 additions & 3 deletions _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"409": {
"message": "Déja soumis"
},
"502": {
"message": "Le serveur ne fonctionne pas. Contactez le développeur."
},
"channelWhitelisted": {
"message": "Cette chaîne est sur la liste blanche !"
},
Expand Down
3 changes: 0 additions & 3 deletions _locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"409": {
"message": "Questo spezzone è già stato inviato"
},
"502": {
"message": "Sembra che il server non funzioni. Contatta lo sviluppatore."
},
"channelWhitelisted": {
"message": "Canale aggiunto alla whitelist!"
},
Expand Down
3 changes: 0 additions & 3 deletions _locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"409": {
"message": "Isso já foi enviado antes"
},
"502": {
"message": "Parece que o servidor caiu. Contate o desenvolvedor para informá-los."
},
"channelWhitelisted": {
"message": "Canal adicionado à lista branca!"
},
Expand Down
3 changes: 0 additions & 3 deletions _locales/pt_pt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"409": {
"message": "Isso já foi enviado antes"
},
"502": {
"message": "Parece que o servidor caiu. Contacte o desenvolvedor para o informar."
},
"channelWhitelisted": {
"message": "Canal adicionado à whitelist!"
},
Expand Down
3 changes: 0 additions & 3 deletions _locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"409": {
"message": "Этот запрос был отправлен ранее."
},
"502": {
"message": "Сервер недоступен. Свяжитесь с разработчиком и сообщите ему об этом."
},
"channelWhitelisted": {
"message": "Канал добавлен в белый список!"
},
Expand Down
17 changes: 14 additions & 3 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 Expand Up @@ -1048,7 +1059,7 @@ function sendSubmitMessage(){
//treat them the same
if (response.statusCode == 503) response.statusCode = 502;

alert(chrome.i18n.getMessage(response.statusCode + ""));
alert(chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode);
} else {
alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
}
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
31 changes: 30 additions & 1 deletion 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 @@ -830,7 +844,7 @@ function runThePopup() {
//treat them the same
if (response.statusCode == 503) response.statusCode = 502;

errorMessage = chrome.i18n.getMessage(response.statusCode + "");
errorMessage = chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode;
} else {
errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode;
}
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 d6aeec9

Please sign in to comment.