aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2022-03-10 10:24:11 -0500
committerGitHub <[email protected]>2022-03-10 10:24:11 -0500
commit405fb342f0a288bc4c33a247719b9d467a1f38d7 (patch)
tree569ebaef2547459c28c56de11504bcab1d47610b
parent8e94a05fa96b756b5b7847b3929ed170c4a7ddb8 (diff)
parentc76f241b636e894a66d926fa582ca52f9c225aea (diff)
downloadSponsorBlock-405fb342f0a288bc4c33a247719b9d467a1f38d7.tar.gz
SponsorBlock-405fb342f0a288bc4c33a247719b9d467a1f38d7.zip
Merge pull request #1218 from MRuy/userinfo
Get user infos from userInfo api for popup
-rw-r--r--src/popup.ts70
1 files changed, 27 insertions, 43 deletions
diff --git a/src/popup.ts b/src/popup.ts
index d02bf36f..a6b1ff44 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -167,56 +167,40 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.showNoticeAgain.style.display = "unset";
}
- utils.sendRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID, (res) => {
+ utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&userID=" + Config.config.userID, (res) => {
if (res.status === 200) {
- PageElements.usernameValue.innerText = JSON.parse(res.responseText).userName
- }
- })
-
- //get the amount of times this user has contributed and display it to thank them
- if (Config.config.sponsorTimesContributed != undefined) {
- PageElements.sponsorTimesContributionsDisplay.innerText = Config.config.sponsorTimesContributed.toLocaleString();
- PageElements.sponsorTimesContributionsContainer.classList.remove("hidden");
+ const userInfo = JSON.parse(res.responseText);
+ PageElements.usernameValue.innerText = userInfo.userName;
- //get the userID
- const userID = Config.config.userID;
- if (userID != undefined) {
- //there are probably some views on these submissions then
- //get the amount of views from the sponsors submitted
- utils.sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function (response) {
- if (response.status == 200) {
- const viewCount = JSON.parse(response.responseText).viewCount;
- if (viewCount != 0) {
- if (viewCount > 1) {
- PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
- } else {
- PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
- }
-
- PageElements.sponsorTimesViewsDisplay.innerText = viewCount.toLocaleString();
- PageElements.sponsorTimesViewsContainer.style.display = "unset";
- }
-
- showDonateWidget(viewCount);
+ const viewCount = userInfo.viewCount;
+ if (viewCount != 0) {
+ if (viewCount > 1) {
+ PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
+ } else {
+ PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
}
- });
+ PageElements.sponsorTimesViewsDisplay.innerText = viewCount.toLocaleString();
+ PageElements.sponsorTimesViewsContainer.style.display = "unset";
+ }
- //get this time in minutes
- utils.sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function (response) {
- if (response.status == 200) {
- const minutesSaved = JSON.parse(response.responseText).timeSaved;
- if (minutesSaved != 0) {
- if (minutesSaved != 1) {
- PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
- } else {
- PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
- }
+ showDonateWidget(viewCount);
- PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
- }
+ const minutesSaved = userInfo.minutesSaved;
+ if (minutesSaved != 0) {
+ if (minutesSaved != 1) {
+ PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
+ } else {
+ PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}
- });
+ PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
+ }
}
+ });
+
+ //get the amount of times this user has contributed and display it to thank them
+ if (Config.config.sponsorTimesContributed != undefined) {
+ PageElements.sponsorTimesContributionsDisplay.innerText = Config.config.sponsorTimesContributed.toLocaleString();
+ PageElements.sponsorTimesContributionsContainer.classList.remove("hidden");
}
//get the amount of times this user has skipped a sponsor