-
Notifications
You must be signed in to change notification settings - Fork 7
/
stashmods.user.js
executable file
·90 lines (75 loc) · 2.73 KB
/
stashmods.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function main() {
var apibase = location.pathname.replace(/^\/projects\/(\w+)\/repos\/([\w\-]+)(\/.*)?$/, '/rest/api/1.0/projects/$1/repos/$2');
var $ = jQuery;
/* Keep me logged in! */
// Load the account page once every 2 minutes
setInterval(function() {
$.get('/account');
}, 120000);
function addTags() {
var tbl = $('table.commits-table');
if (!tbl.length) return;
$.get(apibase+'/tags', function(tagdata) {
var lookup = {};
for (var i=0,s=tagdata.values.length; i<s; i++) {
var sha = tagdata.values[i].latestChangeset;
lookup[sha] = lookup[sha] || [];
lookup[sha].push(tagdata.values[i].displayId);
}
var observer = new MutationObserver(modTable);
modTable();
function modTable() {
console.log('Stashmods Chrome extension: Modifying commit table');
observer.disconnect();
$('.ft-tag').remove();
tbl.find('.commit-row').each(function() {
var sha = $(this).find('.changesetid').attr('href').replace(/^.*\/(\w+)\/?$/, '$1');
if (lookup[sha]) {
var span = $(this).find('.message span');
if (lookup[sha].length === 1) {
span.prepend('<div style="float:right;" class="ft-tag aui-lozenge">'+lookup[sha][0]+'</div>');
} else {
lookup[sha].forEach(function _add(tag) {
span.after('<div style="float:right; margin: 2px;" class="ft-tag aui-lozenge">'+tag+'</div>');
});
}
}
});
observer.observe(tbl.get(0), {subtree: true, childList: true});
}
});
}
function addRedmineLinks() {
var commitMsgs = document.querySelectorAll('.commit-message, .commit-row .message, h2.title, .branch .name');
for (var i = 0, l = commitMsgs.length; i < l; i++) {
var msg = commitMsgs[i];
msg.innerHTML = msg.innerHTML.replace(/(redmine\s*#?(\d+))/ig, '<a href="https://redmine.labs.ft.com/issues/$2">$1</a>')
}
}
function removeAuthorNames() {
var observer = new MutationObserver(avatarOnly);
avatarOnly();
function avatarOnly() {
observer.disconnect();
$('th.author').empty();
$('.avatar-with-name > .aui-avatar').each(function() {
$(this).parent().find('.secondary-link').empty().append(this);
});
observer.observe(document.body, {subtree: true, childList: true});
}
}
$(function() {
// Add tags to commit view
addTags();
// Convert Redmine references to links
addRedmineLinks();
// Remove author names - avatars are sufficient
removeAuthorNames();
});
}
// Run the script in the main document context, not in the extension sandbox
var scriptNode = document.createElement('script');
var target = document.getElementsByTagName('head')[0] || document.body || document.documentElement;
scriptNode.type = "text/javascript";
scriptNode.textContent = '(' + main.toString() + ')()';
target.appendChild(scriptNode);