From effac2449a0e605078e39fa039583e9f4047eae5 Mon Sep 17 00:00:00 2001 From: Nanobyte Date: Sat, 5 Mar 2022 23:52:44 +0100 Subject: [PATCH 1/3] Get user infos from userInfo api for popup --- src/popup.ts | 65 +++++++++++++++++++--------------------------------- 1 file 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 { 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 { 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 From 54013681ef5365669fcabc8c95ff0de76419c441 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 10 Mar 2022 10:22:53 -0500 Subject: [PATCH 2/3] Ask for specific values --- src/popup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup.ts b/src/popup.ts index 6f05583f..bd743605 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -167,7 +167,7 @@ async function runThePopup(messageListener?: MessageListener): Promise { PageElements.showNoticeAgain.style.display = "unset"; } - utils.sendRequestToServer("GET", "/api/userInfo?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) { const userInfo = JSON.parse(res.responseText) PageElements.usernameValue.innerText = userInfo.userName From c76f241b636e894a66d926fa582ca52f9c225aea Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 10 Mar 2022 10:23:35 -0500 Subject: [PATCH 3/3] Formatting --- src/popup.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/popup.ts b/src/popup.ts index bd743605..a6b1ff44 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -169,30 +169,33 @@ async function runThePopup(messageListener?: MessageListener): Promise { utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&userID=" + Config.config.userID, (res) => { if (res.status === 200) { - const userInfo = JSON.parse(res.responseText) - PageElements.usernameValue.innerText = userInfo.userName - const viewCount = userInfo.viewCount + 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") + PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments"); } else { - PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment") + PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment"); } - PageElements.sponsorTimesViewsDisplay.innerText = viewCount.toLocaleString() - PageElements.sponsorTimesViewsContainer.style.display = "unset" + PageElements.sponsorTimesViewsDisplay.innerText = viewCount.toLocaleString(); + PageElements.sponsorTimesViewsContainer.style.display = "unset"; } - showDonateWidget(viewCount) - const minutesSaved = userInfo.minutesSaved + + showDonateWidget(viewCount); + + const minutesSaved = userInfo.minutesSaved; if (minutesSaved != 0) { if (minutesSaved != 1) { - PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower") + PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); } else { - PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower") + PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); } - PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved) + 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) {