Last active
January 7, 2020 00:15
-
-
Save davidhund/200c7ca83f2dfcd92a09 to your computer and use it in GitHub Desktop.
Log Gist Comments
This file contains hidden or 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
/** | |
* 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); |
.. 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
Use it as a bookmarklet: