add: advice api to compliments module

This commit is contained in:
ndo@ndo3 2020-05-14 14:56:38 +02:00
parent 8a1f9b7de6
commit 205de7233e
2 changed files with 16 additions and 2 deletions

View File

@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
*This release is scheduled to be released on 2020-07-01.*
### Added
- Compliments Module - Add Advice API (https://api.adviceslip.com/) Option
### Updated
- Cleaned up alert module code

View File

@ -39,7 +39,8 @@ Module.register("compliments", {
afternoonStartTime: 12,
afternoonEndTime: 17,
random: true,
mockDate: null
mockDate: null,
advice: false
},
lastIndexUsed:-1,
// Set currentweather from module
@ -62,7 +63,19 @@ Module.register("compliments", {
self.config.compliments = JSON.parse(response);
self.updateDom();
});
}
} else if (this.config.advice) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open("GET", "https://api.adviceslip.com/advice", true);
xobj.onreadystatechange = function() {
if (xobj.readyState === 4 && xobj.status === 200) {
const adviceResp = JSON.parse(xobj.responseText);
self.config.compliments = adviceResp.slip.advice
self.updateDom();
}
};
xobj.send(null);
}
// Schedule update timer.
setInterval(function() {