Added time the user saved others from plus better time formatting.

This commit is contained in:
Ajay Ramachandran
2019-12-04 23:51:20 -05:00
parent b18f2ae60d
commit 3a29fcc3d8
3 changed files with 50 additions and 1 deletions

View File

@@ -308,5 +308,11 @@
}, },
"hoursLower": { "hoursLower": {
"message": "hours" "message": "hours"
},
"youHaveSavedTime": {
"message": "You have saved people"
},
"youHaveSavedTimeEnd": {
"message": " of their lives."
} }
} }

View File

@@ -130,6 +130,16 @@
<span id="sponsorTimesViewsDisplayEndWord" class="popupElement">__MSG_Segments__</span>. <span id="sponsorTimesViewsDisplayEndWord" class="popupElement">__MSG_Segments__</span>.
</span> </span>
<span id="sponsorTimesOthersTimeSavedContainer" class="popupElement" style="display: none">
__MSG_youHaveSavedTime__
<span id="sponsorTimesOthersTimeSavedDisplay" class="popupElement">
0
</span>
<span id="sponsorTimesOthersTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span>
<span class="popupElement">__MSG_youHaveSavedTimeEnd__</span>
</span>
<br/> <br/>
<br/> <br/>

View File

@@ -56,6 +56,10 @@ function runThePopup() {
"sponsorTimesViewsContainer", "sponsorTimesViewsContainer",
"sponsorTimesViewsDisplay", "sponsorTimesViewsDisplay",
"sponsorTimesViewsDisplayEndWord", "sponsorTimesViewsDisplayEndWord",
// sponsorTimesOthersTimeSaved
"sponsorTimesOthersTimeSavedContainer",
"sponsorTimesOthersTimeSavedDisplay",
"sponsorTimesOthersTimeSavedEndWord",
// sponsorTimesSkipsDone // sponsorTimesSkipsDone
"sponsorTimesSkipsDoneContainer", "sponsorTimesSkipsDoneContainer",
"sponsorTimesSkipsDoneDisplay", "sponsorTimesSkipsDoneDisplay",
@@ -244,6 +248,23 @@ function runThePopup() {
} }
} }
}); });
//get this time in minutes
sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(xmlhttp) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
let minutesSaved = JSON.parse(xmlhttp.responseText).timeSaved;
if (minutesSaved != 0) {
if (minutesSaved != 1) {
SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
} else {
SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}
SB.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
SB.sponsorTimesOthersTimeSavedContainer.style.display = "unset";
}
}
});
} }
}); });
} }
@@ -272,7 +293,7 @@ function runThePopup() {
SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
} }
SB.sponsorTimeSavedDisplay.innerText = result.minutesSaved.toFixed(2); SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(result.minutesSaved);
SB.sponsorTimeSavedContainer.style.display = "unset"; SB.sponsorTimeSavedContainer.style.display = "unset";
} }
}); });
@@ -1413,6 +1434,18 @@ function runThePopup() {
//submit this request //submit this request
xmlhttp.send(); xmlhttp.send();
} }
/**
* Converts time in hours to 5h 25.1
* If less than 1 hour, just returns minutes
*
* @param {float} seconds
* @returns {string}
*/
function getFormattedHours(minues) {
let hours = Math.floor(minues / 60);
return (hours > 0 ? hours + "h " : "") + (minues % 60).toFixed(1);
}
//end of function //end of function
} }