Added capability to load compliments from the host file system.

This commit is contained in:
Brian 2016-11-30 10:30:49 -05:00
parent 5666729fcf
commit 950fa84d1c

View File

@ -29,6 +29,7 @@ Module.register("compliments",{
]
},
updateInterval: 30000,
remoteFile: null,
fadeSpeed: 4000
},
@ -46,6 +47,12 @@ Module.register("compliments",{
this.lastComplimentIndex = -1;
if (this.config.remoteFile != null) {
this.complimentFile((response) => {
this.config.compliments = JSON.parse(response);
});
}
// Schedule update timer.
var self = this;
setInterval(function() {
@ -104,6 +111,21 @@ Module.register("compliments",{
},
/* complimentFile(callback)
* Retrieve a file from the local filesystem
*/
complimentFile: function(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', this.file(this.config.remoteFile), true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
callback(xobj.responseText);
}
};
xobj.send(null);
},
/* complimentArray()
* Retrieve a random compliment.
*