Created
December 18, 2013 15:43
-
-
Save tsileo/8024507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var getJSON = function(options, callback) { | |
var xhttp = new XMLHttpRequest(); | |
options.url = options.url || location.href; | |
options.data = options.data || null; | |
callback = callback || function() {}; | |
options.type = options.type || 'json'; | |
var url = options.url; | |
xhttp.open('GET', options.url, true); | |
xhttp.send(options.data); | |
xhttp.onreadystatechange = function() { | |
if (xhttp.status == 200 && xhttp.readyState == 4) { | |
callback(xhttp.responseText); | |
} | |
}; | |
}; | |
function insertAfter(referenceNode, newNode) { | |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); | |
} | |
var callback = function(data) { | |
data = eval('('+data+')'); | |
console.log(data); | |
$ref_node = document.querySelector('.article_meta'); | |
stat = document.createElement('div'); | |
stat.id = 'stat_ui'; | |
widget_content = '<h3>Analytics</h3><div id="ui_content"></div>'; | |
stat.innerHTML = widget_content; | |
insertAfter($ref_node, stat); | |
$ui_content = document.querySelector('#ui_content'); | |
$ui_content.innerHTML = '<div><h4>Today</h4><p>Pageviews: <strong>' + data.today.total + '</strong></p></div>'; | |
//$btc_system.innerHTML = content; | |
}; | |
var api = 'http://host.com/api/post' | |
getJSON({'url': api+'?url=' + location.href}, callback); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment