Skip to content

Instantly share code, notes, and snippets.

@noromanba
Forked from saitamanodoruji/gist_logs.user.js
Created May 13, 2012 00:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save noromanba/2669793 to your computer and use it in GitHub Desktop.
Save noromanba/2669793 to your computer and use it in GitHub Desktop.
Show commit logs on Gist for Greasemonkey
// ==UserScript==
// @name gist logs
// @namsgpace https://www.hatena.ne.jp/noromanba/
// @description Show commit logs on Gist for Greasemonkey
// @include https://gist.github.com/*
// @version 2012.7.18.19
// @license WTFPL http://sam.zoy.org/wtfpl/ (Do What The Fuck You Want To Public License)
// @contributor satyr https://gist.github.com/107780
// @contributor saitamanodoruji https://gist.github.com/2653937
// @contributor syoichi https://gist.github.com/3121904
// @author noromanba (https://www.hatena.ne.jp/noromanba/)
// @homepage https://gist.github.com/2669793
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Talk_icon.svg/32px-Talk_icon.svg.png
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Talk_icon.svg/64px-Talk_icon.svg.png
// ==/UserScript==
// Icon (Public Domain by Jonathan)
// https://commons.wikimedia.org/wiki/File:Talk_icon.svg
// c.f. http://d.hatena.ne.jp/murky-satyr/20090508/gist_logs
(function () {
if (!(/^https:\/\/gist\.github\.com\/\d+/.test(location.href))) return;
var indicator = (function () {
var spinner = document.createElement('img');
spinner.src = 'https://assets.github.com/images/spinners/octocat-spinner-32.gif';
var style = spinner.style;
style.display = 'inline-block';
style.marginLeft = '5px';
style.height = '16px';
document.querySelector('#revisions h3').appendChild(spinner);
var timer, threshold = 1500;
return {
keep: function () { // debounce
clearTimeout(timer);
timer = setTimeout(function () {
style.display = 'none';
}, threshold);
}
};
})();
var appendStyle = (function () {
var style = document.createElement('style');
style.type = 'text/css';
// 'white-space' for word-wrap of inline element in Firefox
// http://www.w3.org/TR/css3-text/#white-space
style.textContent = [
'',
'.gist-message {',
' word-break: break-all;',
' white-space: pre-wrap;',
'}',
''
].join('\n');
document.head.appendChild(style);
})();
var timer, queue = [], interval = 1000;
Array.prototype.forEach.call(document.querySelectorAll('#revisions .id'), function (rev, idx) {
// XXX too much XHR requests!
// therefore Github block a response: (D)DoS filtering or API constraints => 505 error
// better to be a XHR once only. but Gist API v1 and v3 not provide log information
timer = setTimeout(function () {
indicator.keep();
queue.shift();
try {
GM_xmlhttpRequest({
method: 'GET',
url: 'https://raw.github.com/gist' + rev.pathname + '/meta',
onload: function (res) {
var msg = (/\n{2}([\s\S]*)\n$/m.exec(res.responseText) || [])[1];
if (!msg) return;
var container = document.createElement('pre');
container.textContent = msg;
container.className = 'gist-message';
rev.parentNode.appendChild(container);
}
});
} catch (e) {
queue.forEach(function (job) {
clearTimeout(job);
});
if (console && console.warn) {
console.warn('*error caught by gist logs =>', e);
}
}
}, interval * idx);
queue.push(timer);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment