Last active
August 29, 2015 14:16
-
-
Save MichalPaszkiewicz/fc4435b8eb0a9271d9c8 to your computer and use it in GitHub Desktop.
PR for dashboard extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var localStorageFunctions = function(){ | |
| this.GetRecognitions = function(){ | |
| var result = {}; | |
| try{ | |
| var recognitionsString = localStorage.getItem("recognitions") | |
| result = JSON.parse(recognitionsString) || {}; | |
| } | |
| catch(err){ | |
| console.error("The format of localStorage's recognitions is bad. SO bad."); | |
| console.error(err.message); | |
| } | |
| return result; | |
| }; | |
| this.SaveRecognitions = function(recognitions){ | |
| if(recognitions == null){ | |
| recognitions = {}; | |
| } | |
| localStorage.setItem("recognitions", JSON.stringify(recognitions) ); | |
| return recognitions; | |
| }; | |
| } | |
| var Database = new localStorageFunctions(); | |
| var addRecognition = function(name){ | |
| var recognitions = Database.GetRecognitions(); | |
| if(recognitions[name] === undefined){ | |
| recognitions[name] = 0; | |
| } | |
| recognitions[name]++; | |
| var date = new Date(); | |
| recognitions["latest-day"] = {day: date.getDate(), hours: date.getHours(), minutes: date.getMinutes()}; | |
| Database.SaveRecognitions(recognitions); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you dont even needd the save function just do all in add recognition and move that to the object
i mean combining save and add recognition