Skip to content

Instantly share code, notes, and snippets.

@syoichi
Forked from noromanba/gist-logs.user.js
Created July 16, 2012 10:04
Show Gist options
  • Save syoichi/3121904 to your computer and use it in GitHub Desktop.
Save syoichi/3121904 to your computer and use it in GitHub Desktop.
show commit messages on Gist
// ==UserScript==
// @name gist logs
// @namsgpace https://www.hatena.ne.jp/noromanba/
// @description show commit messages on Gist
// @include https://gist.github.com/*
// @version 0.0.3
// @update 2012-07-18T21:18:13.437Z(GMT+09:00)
// @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
// @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
// @run-at document-end
// @priority 0
// @compatibility Firefox 14.0.1(Scriptish 0.1.7), Chrome 20.0.1132.57, Safari 5.1.7(NinjaKit 0.9.1) on Windows 7 Home Premium SP1 64bit
// @charset UTF-8
// ==/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
/*jslint browser: true, maxlen: 80*/
/*global GM_xmlhttpRequest*/
// Edition 2012-07-13
(function executeShowCommitMessages(doc) {
'use strict';
var GIST_META_URL, GITHUB_LOADING_ICON, revisions, gmXHR, button,
revisionHeadline, revisionList, ids, idsLen, messages, noMessageIdExp,
$X, addMessage, req, removeButtonAndEventListener, addAllMessage,
cancelDblclickSelect, selectRevisions, details, noMessageIds, idx, id,
loading;
revisions = doc.getElementById('revisions');
if (!revisions) {
return;
}
doc.head.appendChild(doc.createElement('style')).textContent = [
'#revisions > h3 > .classy {',
' top: -2px !important;',
' height: auto !important;',
'}',
'#revisions > h3 > .classy > span {',
' height: auto !important;',
' line-height: normal !important;',
'}',
'.loading {',
' margin-left: 10px !important;',
' margin-bottom: -3px !important;',
' height: 19px !important;',
'}',
'.message {',
' border: 1px solid silver !important;',
' border-radius: 10px !important;',
' padding: 0 3px !important;',
' word-break: break-all !important;',
' white-space: pre-wrap !important;',
'}',
'.error {',
' color: red !important;',
'}'
].join('\n');
GIST_META_URL = 'https://raw.github.com/gist';
GITHUB_LOADING_ICON =
'https://assets.github.com/images/spinners/octocat-spinner-32.gif';
gmXHR = GM_xmlhttpRequest;
button = doc.createElement('button');
revisionHeadline = revisions.firstElementChild;
revisionList = revisionHeadline.nextElementSibling;
ids = revisionList.getElementsByClassName('id');
idsLen = ids.length;
messages = revisionList.getElementsByClassName('message');
noMessageIdExp = 'a[' + (
'contains(concat(" ", @class, " "), " id ") and ' +
'not(' + (
'following-sibling::pre[' + (
'contains(concat(" ", @class, " "), " message ")'
) + ']'
) + ')'
) + ']';
$X = function $X(exp, context) {
var root, result, len, idx, nodes;
root = context ? context.ownerDocument : (context = doc);
result = root.evaluate(exp, context, null, 7, null);
len = result.snapshotLength;
for (idx = 0, nodes = []; idx < len; idx += 1) {
nodes.push(result.snapshotItem(idx));
}
return nodes;
};
addMessage = function addMessage(res) {
var message, matchMessage;
message = doc.createElement('pre');
message.className = 'message';
if (/^(?:200|304)$/.test(res.status)) {
matchMessage = /\n{2}([\s\S]+)\n$/m.exec(res.responseText);
if (matchMessage) {
message.textContent = matchMessage[1];
} else {
message.classList.add('error');
message.textContent = 'commit message not found';
}
} else {
message.classList.add('error');
message.textContent = 'loading error';
}
id.parentNode.appendChild(message);
if (messages.length < idsLen) {
if (noMessageIds) {
req(noMessageIds[idx += 1]);
} else {
loading.hidden = true;
}
} else {
revisionHeadline.removeChild(loading);
}
};
req = function req(rev) {
if (!rev) {
return;
}
id = rev;
if (loading) {
loading.hidden = false;
} else {
loading = doc.createElement('img');
loading.className = 'loading';
loading.src = GITHUB_LOADING_ICON;
revisionHeadline.appendChild(loading);
}
details.url = GIST_META_URL + id.pathname;
gmXHR(details);
};
removeButtonAndEventListener = function removeButtonAndEventListener() {
button.removeEventListener('click', addAllMessage);
button.parentNode.removeChild(button);
revisionList.removeEventListener('selectstart', cancelDblclickSelect);
revisionList.removeEventListener('dblclick', selectRevisions);
};
addAllMessage = function addAllMessage() {
removeButtonAndEventListener();
noMessageIds = $X('.//' + noMessageIdExp, revisions);
idx = 0;
req(noMessageIds[idx]);
};
cancelDblclickSelect = function cancelDblclickSelect(evt) {
var target;
target = evt.target;
if (!(target.tagName === 'LI' && target.parentNode === revisionList)) {
return;
}
evt.preventDefault();
};
selectRevisions = function selectRevisions(evt) {
var target;
target = evt.target;
if (target.tagName === 'A') {
return;
}
if (messages.length === (idsLen - 1)) {
removeButtonAndEventListener();
}
req($X('./ancestor-or-self::li[@class]/' + noMessageIdExp, target)[0]);
};
details = {method: 'GET', onload: addMessage, onerror: addMessage};
button.className = 'classy';
button.insertAdjacentHTML('BeforeEnd', '<span>message</span>');
revisionHeadline.appendChild(button);
button.addEventListener('click', addAllMessage);
revisionList.addEventListener('selectstart', cancelDblclickSelect);
revisionList.addEventListener('dblclick', selectRevisions);
}(document));
@noromanba
Copy link

@syoichi
thank you for fork and many fixes!! 👏

@noromanba
Copy link

@syoichi
FYI
I fixed word-wrap problem on Firefox. see this rev. and commit log.

thanks ;-)

@syoichi
Copy link
Author

syoichi commented Jul 18, 2012

@noromanba
Thank you! I also fixed the bug.

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