Skip to content

Instantly share code, notes, and snippets.

@davidhund
Last active January 7, 2020 00:15
Show Gist options
  • Save davidhund/200c7ca83f2dfcd92a09 to your computer and use it in GitHub Desktop.
Save davidhund/200c7ca83f2dfcd92a09 to your computer and use it in GitHub Desktop.
Log Gist Comments
/**
* Log comments on a particular gist. Verrrry simple/naive/stupid.
* @param {Global} win Window
*/
(function logGistComments(win){
'use strict';
var gid = win.prompt('Gist ID [\'200c7ca83f2dfcd92a09\']', '200c7ca83f2dfcd92a09');
if (gid) {
var url = 'https://api.github.com/gists/{id}/comments'.replace('{id}',gid),
req = new XMLHttpRequest(),
res, l, i;
req.open('GET', url, true);
req.onload = function() {
if (req.status == 200) {
res = JSON.parse(req.responseText);
l = res.length;
console.log('\n--------------------------');
console.log("Gist %s has %s comments:", gid, l);
console.log('--------------------------');
for (i=0;i<l;i++) {
console.log('\n[%s] %s: ', res[i].created_at, res[i].user.login);
console.log('%s', res[i].body);
console.log('\n--------------------------');
}
}
};
req.send();
} else {
console.log('Supply a (valid) Gist ID');
}
})(window);
@davidhund
Copy link
Author

.. and don't forget to open Console to check 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment