Last active
August 29, 2015 14:23
-
-
Save tkrkt/11a7bc241d498c0d7bfc to your computer and use it in GitHub Desktop.
BitBucketのコミットページでコミット全体の行数プラマイ出すグリモン
This file contains 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
// ==UserScript== | |
// @name SumCommitLines | |
// @namespace jp.tkrkt | |
// @include https://bitbucket.org/**/commits/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var container = document.getElementById('commit-files-summary'); | |
if(container){ | |
function getNum(className){ | |
var elems = document.querySelectorAll(className); | |
return Array.prototype.reduce.call(elems, function(sum, elem){ | |
return sum + parseInt(elem.textContent.match(/\d+/)[0]); | |
}, 0); | |
} | |
var tmpl = ''; | |
tmpl += '<li class="iterable-item file file-modified">'; | |
tmpl += '<div class="commit-file-diff-stats">'; | |
tmpl += '<span class="lines-added">%add%</span>'; | |
tmpl += '<span class="lines-removed">%remove%</span>'; | |
tmpl += '</div>'; | |
tmpl += '<a class="execute">合計(%change%)</a>'; | |
tmpl += '</li>'; | |
var add = getNum('.lines-added'); | |
var remove = getNum('.lines-removed'); | |
var change = add - remove; | |
if(change >= 0){ | |
change = '+' + change; | |
} | |
tmpl = tmpl.replace('%add%', '+' + add); | |
tmpl = tmpl.replace('%remove%', '-' + remove); | |
tmpl = tmpl.replace('%change%', change); | |
container.innerHTML = tmpl + container.innerHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment