diff options
author | Ajay Ramachandran <[email protected]> | 2019-08-19 20:17:32 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2019-08-19 20:17:32 -0400 |
commit | b1393a563f57422bb8029a9171fe24088da02e63 (patch) | |
tree | c9bcfd6dae22b7541926f9b1fc8d2b657df9a4f8 | |
parent | 279e49a143e1eef46b2229e98356d0a67522ad20 (diff) | |
download | SponsorBlock-b1393a563f57422bb8029a9171fe24088da02e63.tar.gz SponsorBlock-b1393a563f57422bb8029a9171fe24088da02e63.zip |
Added language support to setUsername. Fixed error messages not appearing. Reset error messages properly.
Resolves https://github.com/ajayyy/SponsorBlock/issues/111
-rw-r--r-- | _locales/en/messages.json | 5 | ||||
-rw-r--r-- | content.js | 1 | ||||
-rw-r--r-- | popup.js | 31 | ||||
-rw-r--r-- | utils/skipNotice.js | 2 |
4 files changed, 28 insertions, 11 deletions
diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 4d0fea81..00d65946 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -103,7 +103,10 @@ "noVideoID": { "message": "This probably isn't a YouTube tab, or you clicked too early. \n If you know this is a YouTube tab,\n close this popup and open it again." }, - "Voted": { + "success": { + "message": "Success!" + }, + "voted": { "message": "Voted!" }, "voteFail": { @@ -978,7 +978,6 @@ function sendSubmitMessage(){ //request the sponsors from the server again sponsorsLookup(currentVideoID); } else { - //for a more detailed error message, they should check the popup //show that the upload failed document.getElementById("submitButton").style.animation = "unset"; document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png"); @@ -799,7 +799,13 @@ function runThePopup() { clearTimes(); } else { - let errorMessage = getErrorMessage(response.statusCode); + let errorMessage = ""; + + if([400,429,409,502].includes(response.statusCode)) { + errorMessage = chrome.i18n.getMessage(response.statusCode); + } else { + errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode; + } document.getElementById("submitTimesInfoMessage").innerText = errorMessage; document.getElementById("submitTimesInfoMessageContainer").style.display = "unset"; @@ -1010,11 +1016,14 @@ function runThePopup() { SB.setUsernameContainer.style.display = "none"; SB.setUsername.style.display = "unset"; - } else { + + SB.setUsernameStatusContainer.style.display = "none"; + } else if (xmlhttp.readyState == 4) { SB.setUsername.style.display = "unset"; SB.submitUsername.style.display = "none"; SB.usernameInput.style.display = "none"; + SB.setUsernameStatusContainer.style.display = "unset"; SB.setUsernameStatus.innerText = "Couldn't connect to server. Error code: " + xmlhttp.status; } }); @@ -1035,11 +1044,17 @@ function runThePopup() { SB.submitUsername.style.display = "none"; SB.usernameInput.style.display = "none"; - SB.setUsernameStatus.innerText = "Success!"; - } else if (xmlhttp.readyState == 4 && xmlhttp.status == 400) { - SB.setUsernameStatus.innerText = "Bad Request"; - } else { - SB.setUsernameStatus.innerText = getErrorMessage(EN_US, xmlhttp.status); + SB.setUsernameStatus.innerText = chrome.i18n.getMessage("success"); + } else if (xmlhttp.readyState == 4) { + let errorMessage = ""; + + if([400, 429, 409, 502].includes(xmlhttp.status)) { + errorMessage = chrome.i18n.getMessage(xmlhttp.status); + } else { + errorMessage = chrome.i18n.getMessage("connectionError") + xmlhttp.status; + } + + SB.setUsernameStatus.innerText = errorMessage; } }); }); @@ -1088,7 +1103,7 @@ function runThePopup() { //see if it was a success or failure if (response.successType == 1) { //success - addVoteMessage(chrome.i18n.getMessage("Voted"), UUID) + addVoteMessage(chrome.i18n.getMessage("voted"), UUID) } else if (response.successType == 0) { //failure: duplicate vote addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID) diff --git a/utils/skipNotice.js b/utils/skipNotice.js index 094f52ce..e57a56e2 100644 --- a/utils/skipNotice.js +++ b/utils/skipNotice.js @@ -268,7 +268,7 @@ class SkipNotice { } afterDownvote() { - this.addVoteButtonInfo(chrome.i18n.getMessage("Voted")); + this.addVoteButtonInfo(chrome.i18n.getMessage("voted")); this.addNoticeInfoMessage(chrome.i18n.getMessage("hitGoBack")); //remove this sponsor from the sponsors looked up |