From b140ef3b7a7ef02852a12826a77f480d083e7610 Mon Sep 17 00:00:00 2001 From: idoodler Date: Sun, 3 Jun 2018 15:47:56 +0200 Subject: [PATCH] Ability to fetch compliments from a remote server --- CHANGELOG.md | 1 + modules/default/compliments/README.md | 2 +- modules/default/compliments/compliments.js | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5735875..aa8c9dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Changed fullscreen newsfeed width from 100% to 100vw (better results) - Added option to calendar module that colors only the symbol instead of the whole line - Added option for new display format in the calendar module with date headers with times/events below. +- Ability to fetch compliments from a remote server ### Changed - Upgrade to Electron 2.0.0. diff --git a/modules/default/compliments/README.md b/modules/default/compliments/README.md index 2b381b39..8f796888 100644 --- a/modules/default/compliments/README.md +++ b/modules/default/compliments/README.md @@ -30,7 +30,7 @@ The following properties can be configured: | `updateInterval` | How often does the compliment have to change? (Milliseconds)

**Possible values:** `1000` - `86400000`
**Default value:** `30000` (30 seconds) | `fadeSpeed` | Speed of the update animation. (Milliseconds)

**Possible values:**`0` - `5000`
**Default value:** `4000` (4 seconds) | `compliments` | The list of compliments.

**Possible values:** An object with four arrays: `morning`, `afternoon`, `evening` and `anytime`. See _compliment configuration_ below.
**Default value:** See _compliment configuration_ below. -| `remoteFile` | External file from which to load the compliments

**Possible values:** Path to a JSON file containing compliments, configured as per the value of the _compliments configuration_ (see below). An object with four arrays: `morning`, `afternoon`, `evening` and `anytime`. - `compliments.json`
**Default value:** `null` (Do not load from file) +| `remoteFile` | External file from which to load the compliments

**Possible values:** Path or URL (starting with `http://` or `https://`) to a JSON file containing compliments, configured as per the value of the _compliments configuration_ (see below). An object with four arrays: `morning`, `afternoon`, `evening` and `anytime`. - `compliments.json`
**Default value:** `null` (Do not load from file) | `classes` | Override the CSS classes of the div showing the compliments

**Default value:** `thin xlarge bright` | `morningStartTime` | Time in hours (in 24 format), after which the mode of "morning" will begin
**Possible values:** `0` - `24`

**Default value:** `3` | `morningEndTime` | Time in hours (in 24 format), after which the mode of "morning" will end
**Possible values:** `0` - `24`

**Default value:** `12` diff --git a/modules/default/compliments/compliments.js b/modules/default/compliments/compliments.js index b4207bfc..74aef034 100644 --- a/modules/default/compliments/compliments.js +++ b/modules/default/compliments/compliments.js @@ -128,9 +128,11 @@ Module.register("compliments", { * Retrieve a file from the local filesystem */ complimentFile: function(callback) { - var xobj = new XMLHttpRequest(); + var xobj = new XMLHttpRequest(), + isRemote = this.config.remoteFile.indexOf("http://") === 0 || this.config.remoteFile.indexOf("https://") === 0, + path = isRemote ? this.config.remoteFile : this.file(this.config.remoteFile); xobj.overrideMimeType("application/json"); - xobj.open("GET", this.file(this.config.remoteFile), true); + xobj.open("GET", path, true); xobj.onreadystatechange = function() { if (xobj.readyState == 4 && xobj.status == "200") { callback(xobj.responseText);