diff --git a/README.md b/README.md index 15b8470..1b1db0e 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,56 @@ # Module planetrise -Calculates and display the rise and set times of the planets for Magic Mirror 2 -This module is powered with Don Cross's javascript library [astronomy.js](http://cosinekitty.com). -## Using the module +Calculates and display the rise and set times of the planets for [MagicMirror²](https://magicmirror.builders/). + +This module is powered with Don Cross's javascript library [astronomy.js](https://github.com/cosinekitty/astronomy). + +## Screenshot + +![Screenshot](screenshot.png) + +## Installation + +Just clone the module into your modules folder of your MagicMirror²: + +```bash +cd ~/MagicMirror/modules +git clone https://github.com/croxis/planetrise +``` + +## Configuration To use this module, add it to the modules array in the `config/config.js` file: -````javascript -modules: [ - { - module: 'planetrise', - position: 'top_right', // This can be any of the regions. - header: 'PLanet Rise', + +```javascript + { + module: "planetrise", + position: "top_right", // This can be any of the regions. + header: "Planet Rise", config: { // Place the latitude and longitude of your mirror latitude: 45.5, longitude: -122.38, // A dictiory of the bodies and unicode character for the symbol // This is the default and does not need to be listed. // A full list of bodies can be seen on line 1359 in astronomy.js - // Note: Trying to find the rise time of Earth will crash the Module - bodies: {'Sun': '☉', - 'Moon': '☽', - 'Mercury': '☿', - 'Venus': '♀', - 'Mars': '♂', - 'Jupiter': '♃', - 'Saturn': '♄', + // Note: Trying to find the rise time of Earth will crash the module + bodies: { + Sun: "☉", + Moon: "☽", + Mercury: "☿", + Venus: "♀", + Mars: "♂", + Jupiter: "♃", + Saturn: "♄" } } - } -] -```` + }, +``` + +## Update + +Go to the module’s folder inside MagicMirror modules folder and pull the latest version from GitHub: + +```bash +cd ~/MagicMirror/modules/planetrise +git pull +``` diff --git a/package.json b/package.json new file mode 100644 index 0000000..7fab340 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "planetrise", + "version": "1.0.0", + "description": "A MagicMirror² module to display the rise and set times of the planets.", + "main": "planetrise.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/croxis/planetrise.git" + }, + "keywords": [ + "astronomy" + ], + "author": "croxis", + "license": "MIT", + "bugs": { + "url": "https://github.com/croxis/planetrise/issues" + }, + "homepage": "https://github.com/croxis/planetrise#readme" +} diff --git a/planetrise.js b/planetrise.js index e193b56..008dd1d 100644 --- a/planetrise.js +++ b/planetrise.js @@ -1,99 +1,99 @@ // Helper functions from http://cosinekitty.com/solar_system.html -var BriefDayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - function BriefTimeString (date) - { - if (date == null) { - return ""; - } else { - var h = date.getHours(); - h = ((h < 10) ? "0" : "") + h.toString(); - var m = date.getMinutes(); - m = ((m < 10) ? "0" : "") + m.toString(); - var s = date.getSeconds(); - s = ((s < 10) ? "0" : "") + s.toString(); - return BriefDayOfWeek[date.getDay()] + " " + h + ":" + m + ":" + s; - } +const BriefDayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + +function BriefTimeString (date) { + if (date == null) { + return ""; } + let h = date.getHours(); + h = (h < 10 ? "0" : "") + h.toString(); + let m = date.getMinutes(); + m = (m < 10 ? "0" : "") + m.toString(); + let s = date.getSeconds(); + s = (s < 10 ? "0" : "") + s.toString(); + return `${BriefDayOfWeek[date.getDay()]} ${h}:${m}:${s}`; +} -function BriefDayValueString (day) - { - if (day == null) { - return ""; - } else { - return BriefTimeString (Astronomy.DayValueToDate (day)); - } +function BriefDayValueString (day) { + if (day == null) { + return ""; } + return BriefTimeString(Astronomy.DayValueToDate(day)); +} Module.register("planetrise", { defaults: { latitude: 34.2, longitude: -118.1, - //bodies: ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn'] - bodies: {'Sun': '☉', - 'Moon': '☽', - 'Mercury': '☿', - 'Venus': '♀', - 'Mars': '♂', - 'Jupiter': '♃', - 'Saturn': '♄', + // bodies: ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn'] + bodies: { + Sun: "☉", + Moon: "☽", + Mercury: "☿", + Venus: "♀", + Mars: "♂", + Jupiter: "♃", + Saturn: "♄" } }, // Define start sequence. - start: function() { - Log.info("Starting module: " + this.name); + start () { + Log.info(`Starting module: ${this.name}`); - // Schedule update interval. - var self = this; - setInterval(function() { - self.updateDom(); - }, 1000*60); + // Schedule update interval. + const self = this; + setInterval(() => { + self.updateDom(); + }, 1000 * 60); }, // Override dom generator. - getDom: function() { + getDom () { latitude = this.config.latitude; longitude = this.config.longitude; - var wrapper = document.createElement("table"); + const wrapper = document.createElement("table"); wrapper.className = "small"; - var AstroDateTime = new Date(); - var day = Astronomy.DayValue (AstroDateTime); - var location = new GeographicCoordinates(longitude, latitude, 0); + const AstroDateTime = new Date(); + const day = Astronomy.DayValue(AstroDateTime); + const location = new GeographicCoordinates(longitude, latitude, 0); - for (var i in Astronomy.Body) { - //AddRowForCelestialBody (Astronomy.Body[i], day); - if (Object.keys(this.config.bodies).indexOf(Astronomy.Body[i].Name) >= 0){ - var planetWrapper = document.createElement("tr"); + for (const i in Astronomy.Body) { + // AddRowForCelestialBody (Astronomy.Body[i], day); + if (Object.keys(this.config.bodies).indexOf(Astronomy.Body[i].Name) >= 0) { + const planetWrapper = document.createElement("tr"); planetWrapper.className = "normal"; - var symbolWrapper = document.createElement("td"); + const symbolWrapper = document.createElement("td"); symbolWrapper.className = "symbol"; - //If fontio ever supports the full set - //var symbol = document.createElement("span"); - //symbol.className = "fa fa-" + this.config.bodies[Astronomy.Body[i].Name]; - //symbolWrapper.appendChild(symbol); - symbolWrapper.innerHTML = '
' + this.config.bodies[Astronomy.Body[i].Name] + '
'; + + // If fontio ever supports the full set + // let symbol = document.createElement("span"); + // symbol.className = "fa fa-" + this.config.bodies[Astronomy.Body[i].Name]; + // symbolWrapper.appendChild(symbol); + + symbolWrapper.innerHTML = `
${this.config.bodies[Astronomy.Body[i].Name]}
`; planetWrapper.appendChild(symbolWrapper); - var titleWrapper = document.createElement("td"); + const titleWrapper = document.createElement("td"); titleWrapper.innerHTML = Astronomy.Body[i].Name; titleWrapper.className = "title bright"; planetWrapper.appendChild(titleWrapper); - var riseWrapper = document.createElement("td"); + const riseWrapper = document.createElement("td"); riseWrapper.className = "time light"; riseWrapper.innerHTML = BriefDayValueString(Astronomy.NextRiseTime(Astronomy.Body[i], day, location)); planetWrapper.appendChild(riseWrapper); - var setWrapper = document.createElement("td"); + const setWrapper = document.createElement("td"); setWrapper.className = "time light"; setWrapper.innerHTML = BriefDayValueString(Astronomy.NextSetTime(Astronomy.Body[i], day, location)); planetWrapper.appendChild(setWrapper); - //planetWrapper.innerHTML = Object.keys(Astronomy.Body[i]).toString(); + // planetWrapper.innerHTML = Object.keys(Astronomy.Body[i]).toString(); wrapper.appendChild(planetWrapper); } } - //wrapper.innerHTML = make_text(sun_elevation, next, julian_date); + // wrapper.innerHTML = make_text(sun_elevation, next, julian_date); return wrapper; }, - getScripts: function() { - return['astronomy.js'] + getScripts () { + return ["astronomy.js"]; } -}); \ No newline at end of file +}); diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..c7430bc Binary files /dev/null and b/screenshot.png differ