var ghe = { apiBase: 'https://api.github.com' ,callbacks: {} ,library: {} ,rLeadSlash: /^\/+|\/+$/g } ghe.keygen = function(){ return 'ghe_' + ~~(Math.random() * 100000); } ghe.jsonpCallback = function(key){ return ghe.callbacks[key] = function(resp){ var lib = ghe.library[key]; console.log( 'retrieved library data', lib ); console.log( 'response', resp ); } } ghe.jsonp = function(fileUrl, cbName){ var script = document.createElement('script'); script.async = true; script.src = fileUrl + '?callback=' + cbName; } ghe.parseNode = function(el){ var lines = el.getAttribute('data-ghlines') ,start ,end; if(lines && lines.indexOf('-') > -1){ lines = lines.split('-'); start = parseInt( lines[0], 10 ); end = parseInt( lines[1], 10 ); } else if( lines ){ start = end = parseInt( lines, 10 ); } else { start = end = -1; } return { path: el.getAttribute('data-ghpath') ,userrepo: el.getAttribute('data-ghuserrepo') ,lineBegin: start ,lineEnd: end ,el: el } } ghe.load = function(cfg){ var key = ghe.keygen(); if( cfg.nodeName ){ cfg = ghe.parseNode(cfg); } ghe.jsonpCallback(key); ghe.library[key] = cfg; ghe.jsonp( ghe.apiBase + '/repos/' + cfg.userrepo.replace(ghe.rLeadSlash, '') + '/contents/' + cfg.path.replace(ghe.rLeadSlash, '') ,key ); } ghe.autorun = function(){ var nodes; if( window.jQuery ){ nodes = $('[data-ghpath]') } else { nodes = document.querySelectorAll('[data-ghpath]'); } for(var i = 0; i < nodes.length; i++){ console.log(nodes[i]); ghe.load(nodes[i]); } } ghe.autorun(); console.log(ghe); /*var css = document.createElement('link'); css.type = 'text/css'; css.ref = 'stylesheet'; css.href = 'https://gist.github.com/stylesheets/gist/embed.css'; css.media = 'screen'; document.getElementsByTagName('head')[0].appendChild(css); var container = document.createElement('div') ,url = 'https://api.github.com/repos/kirbysayshi/broad-phase-bng/contents/examples/bruteforce/orbit-01.js' ,req = new XMLHttpRequest(); container.className = 'gist'; document.getElementsByTagName('body')[0].appendChild(container); req.open( 'GET', url, true ); req.onreadystatechange = function(){ var parsed, lines, filename, gist, pre; if(req.readyState === 4){ parsed = JSON.parse( req.responseText ); console.log(parsed); filename = url.split('/').pop(); content = atob( parsed.content.replace(/\s/g, '') ); lines = content.split('\n'); lines = lines.map(function(l, i){ return '<a id="#' + filename + '-' + i + '"></a>' + l.replace(/\t/g, ' ') .replace(/^ +/g, ' '); }); console.log( lines.join('\n') ); gist = document.createElement('div'); gist.className = 'gist-file'; gist.innerHTML = lines.join('<br />'); container.appendChild(gist); } else { console.log(arguments); } } req.send();*/
<div data-ghpath="examples/bruteforce/orbit-01.js" data-ghuserrepo="kirbysayshi/broad-phase-bng" data-ghlines="4-10" class="gist"></div>