diff options
author | Nanobyte <[email protected]> | 2022-03-05 23:52:44 +0100 |
---|---|---|
committer | Nanobyte <[email protected]> | 2022-03-05 23:52:44 +0100 |
commit | effac2449a0e605078e39fa039583e9f4047eae5 (patch) | |
tree | 40e5ae749cb5c5401baf440e6ccd5a585de711b3 | |
parent | d02aab4ba35d224d10a83644e487880da2a7a8dd (diff) | |
download | SponsorBlock-effac2449a0e605078e39fa039583e9f4047eae5.tar.gz SponsorBlock-effac2449a0e605078e39fa039583e9f4047eae5.zip |
Get user infos from userInfo api for popup
-rw-r--r-- | src/popup.ts | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/src/popup.ts b/src/popup.ts index d02bf36f..6f05583f 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -167,9 +167,30 @@ 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?userID=" + Config.config.userID, (res) => { if (res.status === 200) { - PageElements.usernameValue.innerText = JSON.parse(res.responseText).userName + const userInfo = JSON.parse(res.responseText) + PageElements.usernameValue.innerText = userInfo.userName + 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" + } + showDonateWidget(viewCount) + 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) + } } }) @@ -177,46 +198,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { if (Config.config.sponsorTimesContributed != undefined) { PageElements.sponsorTimesContributionsDisplay.innerText = Config.config.sponsorTimesContributed.toLocaleString(); PageElements.sponsorTimesContributionsContainer.classList.remove("hidden"); - - //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); - } - }); - - //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"); - } - - PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved); - } - } - }); - } } //get the amount of times this user has skipped a sponsor |