• 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.

Random text fetch from Reddit

Scheduled Pinned Locked Moved Troubleshooting
1 Posts 1 Posters 944 Views 1 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.
  • S Offline
    stech
    last edited by Jun 18, 2017, 3:18 PM

    Hello everyone.
    I’m trying to display random text from random subreddits on my mirror. I have found a code that uses jQuery to fetch 10 titles from a page and that can be used successfully inside a html page.
    Link to the function -> https://gist.github.com/sente/947491

    The problem comes when I try to integrate that inside my module. So I try to fetch that data inside my function but using $ I don’t think it does the job. I have no idea how to call a jQuery function inside my script since the example uses a html page. I tried with the getScripts function but the result is the same.
    My code right now looks like this

    	randomQuote: function() {
    		
    		var script = document.createElement('script');
    		script.src = 'http://j.mp/jqymin';
    		script.type = 'text/javascript';
    		document.getElementsByTagName('head')[0].appendChild(script);
    	  
    		var a=[];
    		script.getJSON(
            "http://www.reddit.com/r/showerthoughts.json?jsonp=?",
            function foo(data)
            {
              script.each(
                data.data.children.slice(0, 10),
                function (i, post) {
                  a.push(post.data.title);
                }
              )
            }
            
          )      
          return a;
    	},
    

    Any help would be much appreciated since I’m a noob with JavaScript, I’m just starting out.

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