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

Use it as a bookmarklet:

javascript:!function(a){"use strict";var b=a.prompt("Gist ID ['200c7ca83f2dfcd92a09']","200c7ca83f2dfcd92a09");if(b){var e,f,g,c="https://api.github.com/gists/{id}/comments".replace("{id}",b),d=new XMLHttpRequest;d.open("GET",c,!0),d.onload=function(){if(200==d.status)for(e=JSON.parse(d.responseText),f=e.length,console.log("\n--------------------------"),console.log("%s has %s comments:",b,f),console.log("--------------------------"),g=0;f>g;g++)console.log("\n[%s] %s: ",e[g].created_at,e[g].user.login),console.log("%s",e[g].body),console.log("\n--------------------------")},d.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