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.

    custom JS file (JQUERY)

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    8 Posts 4 Posters 1.4k 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.
    • P Offline
      panos
      last edited by

      Hello.
      Is there a way to run my own javascript on magicmirror?
      I want to run some functions using jquery.
      I was thinking to include my code on config.js (but I’m sure that will break the config file)
      Any suggestions?

      1 Reply Last reply Reply Quote 0
      • cowboysdudeC Offline
        cowboysdude Module Developer
        last edited by

        Running how? In a module? If in a module the you can just include it in your getScripts function…

        P 1 Reply Last reply Reply Quote 0
        • P Offline
          panos @cowboysdude
          last edited by

          @cowboysdude
          Hi.
          I’m using the MMM-MQTT module and I want to change the color of the represented text by MQTT in real-time using JQuery.

          I wrote the code, but I can’t make it run on MagicMirror web UI

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @panos
            last edited by

            @panos in a module, u need to tell M to make those functions available

            in a normal js file you would use require(‘js+filename’)

            in the module u have to return the names (and paths) of these routine files from the
            getScripts() function, which returns an array of names

            then u can use the functions in those files from the modulename.js file functions.

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            cowboysdudeC 1 Reply Last reply Reply Quote 0
            • cowboysdudeC Offline
              cowboysdude Module Developer @sdetweil
              last edited by cowboysdude

              For example:

              In your main.js file we’ll call it MMM-Whatever.js

                // Define required scripts.
                   getScripts: function() {
                  return ["jquery.min.js", "moment.js", "run.js"];
                  },
              

              That’s one way to to do it.

              1 Reply Last reply Reply Quote 0
              • P Offline
                panos
                last edited by

                Thanks guys. I did it by modifying MMM-MQTT original code.
                The only issue is that everytime that the module will be updated, I must modify it again.
                Thanks for your help!

                cowboysdudeC 1 Reply Last reply Reply Quote 0
                • cowboysdudeC Offline
                  cowboysdude Module Developer @panos
                  last edited by

                  @panos Hopefully you find another way to do it because that would be frustrating after a while LOL

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    doubleT Module Developer
                    last edited by

                    If you have a git hub account you can fork the module’s repo to your own github account and then install/clone it to your modules folder from your own git. Make the change, push it to your remote repo. When there’s an update, you can merge the update with your changed code on github and update the module afterwards. Or not even bother with updates anymore at all, if you want that.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      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