JSFiddle - React, Tailwind, and code Playground

by Santiago J

HTML

<img src="http://www.ragemaker.net/images/Determined%20-%20Focused/fumanchu.jpg">
<pre id="log"></pre>

CSS

body {
    background-color: #333;
    color: #eee;
}

img {
    width: 128px;
}

JavaScript

//window.console = window.console || {log:function(){}};

var myJSONP = {scriptTag: null};
var head, log;

myJSONP.onload = function(obj) {
    var date = new Date();
    var h = date.getHours();
    var m = date.getMinutes();

    var newScore = obj.data.children[0].data.score;
    if (newScore !== myJSONP.score)
        log.innerHTML += h + "h" + m + "m: score " + myJSONP.score + " -> " + newScore + "\n";
    myJSONP.score = newScore;

    var newComm = obj.data.children[0].data.num_comments;
    if (newComm !== myJSONP.comm)
        log.innerHTML += h + "h" + m + "m: comments " + myJSONP.comm + " -> " + newComm + "\n";
    myJSONP.comm = newComm;

    setTimeout(myJSONP.get, 60*1000);
};

myJSONP.get = function() {
    if (myJSONP.scriptTag && myJSONP.scriptTag.parentNode) {
        myJSONP.scriptTag.parentNode.removeChild(myJSONP.scriptTag);
    }
    var script = document.createElement("script");
    script.src = "http://www.reddit.com/by_id/t3_pbfdt.json?jsonp=myJSONP.onload&c=" + Date.now();

    if (head) head.appendChild(script);
    myJSONP.scriptTag = script;
};

window.onload = function() {
    head = document.head || document.getElementsByTagName("head")[0];
    log = document.getElementById("log");
    myJSONP.get();
};