• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Compliments issue

Scheduled Pinned Locked Moved Unsolved Troubleshooting
4 Posts 3 Posters 621 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    tintkovich
    last edited by Nov 17, 2019, 9:07 PM

    Hi guys!
    I edited compliments.js file in /modules/default/compliments cataloge. After that my mirror has stopped displaying this module. I restored the original version and made the modifications to the config.js file.

    It still doesn’t work :/ what can I do?

    S 1 Reply Last reply Nov 18, 2019, 2:58 AM Reply Quote 0
    • S Online
      sdetweil @tintkovich
      last edited by Nov 18, 2019, 2:58 AM

      @tintkovich what doesn’t work? Mirror or just compliments?

      Did u put the list if compliments thru a JavaScript parser online?

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      T 1 Reply Last reply Nov 19, 2019, 7:08 PM Reply Quote 0
      • T Offline
        tintkovich @sdetweil
        last edited by Nov 19, 2019, 7:08 PM

        @sdetweil Hi, Compliments doesn’t work…

        Yes, I did put it thru js parser.

        /* global Log, Module, moment */
        
        /* Magic Mirror
         * Module: Compliments
         *
         * By Michael Teeuw http://michaelteeuw.nl
         * MIT Licensed.
         */
        Module.register("compliments", {
        
        	// Module config defaults.
        	defaults: {
        			compliments: {
        		anytime: [
        			"Hey there sexy!"
        		],
        		morning: [
        			"Good morning, handsome!",
        			"Enjoy your day!",
        			"How was your sleep?"
        		],
        		afternoon: [
        			"Hello, beauty!",
        			"You look sexy!",
        			"Looking good today!"
        		],
        		evening: [
        			"Wow, you look hot!",
        			"You look nice!",
        			"Hi, sexy!"
        		]
        	}
        },
        		updateInterval: 30000,
        		remoteFile: null,
        		fadeSpeed: 4000,
        		morningStartTime: 3,
        		morningEndTime: 12,
        		afternoonStartTime: 12,
        		afternoonEndTime: 17
        	},
        
        	// Set currentweather from module
        	currentWeatherType: "",
        
        	// Define required scripts.
        	getScripts: function() {
        		return ["moment.js"];
        	},
        
        	// Define start sequence.
        	start: function() {
        		Log.info("Starting module: " + this.name);
        
        		this.lastComplimentIndex = -1;
        
        		var self = this;
        		if (this.config.remoteFile !== null) {
        			this.complimentFile(function(response) {
        				self.config.compliments = JSON.parse(response);
        				self.updateDom();
        			});
        		}
        
        		// Schedule update timer.
        		setInterval(function() {
        			self.updateDom(self.config.fadeSpeed);
        		}, this.config.updateInterval);
        	},
        
        	/* randomIndex(compliments)
        	 * Generate a random index for a list of compliments.
        	 *
        	 * argument compliments Array<String> - Array with compliments.
        	 *
        	 * return Number - Random index.
        	 */
        	randomIndex: function(compliments) {
        		if (compliments.length === 1) {
        			return 0;
        		}
        
        		var generate = function() {
        			return Math.floor(Math.random() * compliments.length);
        		};
        
        		var complimentIndex = generate();
        
        		while (complimentIndex === this.lastComplimentIndex) {
        			complimentIndex = generate();
        		}
        
        		this.lastComplimentIndex = complimentIndex;
        
        		return complimentIndex;
        	},
        
        	/* complimentArray()
        	 * Retrieve an array of compliments for the time of the day.
        	 *
        	 * return compliments Array<String> - Array with compliments for the time of the day.
        	 */
        	complimentArray: function() {
        		var hour = moment().hour();
        		var compliments;
        
        		if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
        			compliments = this.config.compliments.morning.slice(0);
        		} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime && this.config.compliments.hasOwnProperty("afternoon")) {
        			compliments = this.config.compliments.afternoon.slice(0);
        		} else if(this.config.compliments.hasOwnProperty("evening")) {
        			compliments = this.config.compliments.evening.slice(0);
        		}
        
        		if (typeof compliments === "undefined") {
        			compliments = new Array();
        		}
        
        		if (this.currentWeatherType in this.config.compliments) {
        			compliments.push.apply(compliments, this.config.compliments[this.currentWeatherType]);
        		}
        
        		compliments.push.apply(compliments, this.config.compliments.anytime);
        
        		return compliments;
        	},
        
        	/* complimentFile(callback)
        	 * Retrieve a file from the local filesystem
        	 */
        	complimentFile: function(callback) {
        		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", path, true);
        		xobj.onreadystatechange = function() {
        			if (xobj.readyState === 4 && xobj.status === 200) {
        				callback(xobj.responseText);
        			}
        		};
        		xobj.send(null);
        	},
        
        	/* complimentArray()
        	 * Retrieve a random compliment.
        	 *
        	 * return compliment string - A compliment.
        	 */
        	randomCompliment: function() {
        		var compliments = this.complimentArray();
        		var index = this.randomIndex(compliments);
        
        		return compliments[index];
        	},
        
            // Override dom generator.
            getDom: function () {
                var complimentText = this.randomCompliment();
        
                var compliment = document.createTextNode(complimentText);
                var wrapper = document.createElement("div");
                wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
                wrapper.appendChild(compliment);
        
                return wrapper;
            },
        
            // From data currentweather set weather type
            setCurrentWeatherType: function (data) {
                var weatherIconTable = {
                    "01d": "day_sunny",
                    "02d": "day_cloudy",
                    "03d": "cloudy",
                    "04d": "cloudy_windy",
                    "09d": "showers",
                    "10d": "rain",
                    "11d": "thunderstorm",
                    "13d": "snow",
                    "50d": "fog",
                    "01n": "night_clear",
                    "02n": "night_cloudy",
                    "03n": "night_cloudy",
                    "04n": "night_cloudy",
                    "09n": "night_showers",
                    "10n": "night_rain",
                    "11n": "night_thunderstorm",
                    "13n": "night_snow",
                    "50n": "night_alt_cloudy_windy"
                };
                this.currentWeatherType = weatherIconTable[data.weather[0].icon];
            },
        
            // Override notification handler.
            notificationReceived: function (notification, payload, sender) {
                if (notification === "CURRENTWEATHER_DATA") {
                    this.setCurrentWeatherType(payload.data);
                }
            },
        
        });
        
        T 1 Reply Last reply Nov 19, 2019, 8:00 PM Reply Quote 0
        • T Offline
          tanvir586 @tintkovich
          last edited by Nov 19, 2019, 8:00 PM

          @tintkovich
          Delete extra } after the evening section.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            1/4
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy