aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-08-12 23:20:35 -0400
committerAjay Ramachandran <[email protected]>2019-08-12 23:20:35 -0400
commit5445146b5610f171d992e4e3acd2b92cb76f2495 (patch)
tree7bc61dbacf0c247cee8a0825ea34c86163f37cb5
parent13d0e4a33a244037e35e95f9d9a6bd8720f07261 (diff)
downloadSponsorBlock-5445146b5610f171d992e4e3acd2b92cb76f2495.tar.gz
SponsorBlock-5445146b5610f171d992e4e3acd2b92cb76f2495.zip
Added ability to set your username
-rw-r--r--popup.html27
-rw-r--r--popup.js46
2 files changed, 71 insertions, 2 deletions
diff --git a/popup.html b/popup.html
index 82c2d66c..0c829494 100644
--- a/popup.html
+++ b/popup.html
@@ -114,6 +114,31 @@
</div>
+ <div id="setUsernameContainer" class="popupElement">
+ <br/>
+ <br/>
+
+ <button id="setUsernameButton" class="warningButton popupElement">Set Username</button>
+ </div>
+
+ <div id="setUsername" class="popupElement" style="display: none">
+ <br/>
+
+ <h3>Set Username</h3>
+
+ <div id="setUsernameStatusContainer" style="display: none">
+ <h2 id="setUsernameStatus"></h2>
+ </div>
+
+
+ <input id="usernameInput" hint="Username"></input>
+
+ <br/>
+ <br/>
+
+ <button id="submitUsername" class="warningButton popupElement">Submit Username</button>
+ </div>
+
<div id="discordButtonContainer" class="popupElement" style="display: none">
<br/>
@@ -121,7 +146,7 @@
<br/>
- Come join the official discord server to give suggestions and feedback!
+ Come join the official discord server to give suggestions and feedback!
<br/>
diff --git a/popup.js b/popup.js
index 220fb769..ae9a9499 100644
--- a/popup.js
+++ b/popup.js
@@ -54,6 +54,14 @@ function runThePopup() {
// submitTimesInfoMessage
"submitTimesInfoMessageContainer",
"submitTimesInfoMessage",
+ // Username
+ "setUsernameContainer",
+ "setUsernameButton",
+ "setUsernameStatusContainer",
+ "setUsernameStatus",
+ "setUsername",
+ "usernameInput",
+ "submitUsername",
// More
"submissionSection",
"mainControls",
@@ -78,6 +86,8 @@ function runThePopup() {
SB.showDeleteButtonPlayerControls.addEventListener("click", showDeleteButtonPlayerControls);
SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking);
SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking);
+ SB.setUsernameButton.addEventListener("click", setUsernameButton);
+ SB.submitUsername.addEventListener("click", submitUsername);
SB.optionsButton.addEventListener("click", openOptions);
SB.reportAnIssue.addEventListener("click", reportAnIssue);
SB.hideDiscordButton.addEventListener("click", hideDiscordButton);
@@ -995,11 +1005,45 @@ function runThePopup() {
}
}
- //make the options div visisble
+ //make the options div visible
function openOptions() {
document.getElementById("optionsButtonContainer").style.display = "none";
document.getElementById("options").style.display = "unset";
}
+
+ //make the options username setting option visible
+ function setUsernameButton() {
+ SB.setUsernameContainer.style.display = "none";
+ SB.setUsername.style.display = "unset";
+ }
+
+ //submit the new username
+ function submitUsername() {
+ //add loading indicator
+ SB.setUsernameStatusContainer.style.display = "unset";
+ SB.setUsernameStatus.innerText = "Loading...";
+
+ //get the userID
+ chrome.storage.sync.get(["userID"], function(result) {
+ sendRequestToServer("POST", "/api/setUsername?userID=" + result.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ //submitted
+ 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.setUsernameContainer.style.display = "none";
+ SB.setUsername.style.display = "unset";
+ }
//this is not a YouTube video page
function displayNoVideo() {