-
Notifications
You must be signed in to change notification settings - Fork 3
/
ContribsByPage.js
82 lines (75 loc) · 3.09 KB
/
ContribsByPage.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
/*** Group Contributions By Page ***/
// Groups revisions at Special:Contributions by page
// Documentation at [[en:w:User:BrandonXLF/ContribsByPage]]
// By [[en:w:User:BrandonXLF]]
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') != 'Contributions') return;
mw.loader.load(['mediawiki.special.changeslist.enhanced', 'jquery.makeCollapsible.styles', 'mediawiki.icon']);
var pages = {},
arrowClass = 'mw-collapsible-toggle mw-collapsible-arrow mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space mw-collapsible-toggle-collapsed';
$('[data-mw-revid]').each(function() {
var title = $('.mw-contributions-title', this).attr('title');
if (!pages[title]) {
pages[title] = [];
}
pages[title].push(this);
});
function merge(page) {
if (pages[page].length > 1) {
var diff = $('<span class="mw-diff-bytes">'),
toggle = $('<span class="' + arrowClass + '"></span>').click(function() {
if (toggle.hasClass('mw-collapsible-toggle-collapsed')) {
toggle.removeClass('mw-collapsible-toggle-collapsed').addClass('mw-collapsible-toggle-expanded');
sub.show();
} else {
toggle.removeClass('mw-collapsible-toggle-expanded').addClass('mw-collapsible-toggle-collapsed');
sub.hide();
}
}),
head = $('<li class="multi">').append(
toggle,
$('.mw-changeslist-date', pages[page][0]).first().text(),
' ',
$('<span class="mw-changeslist-links">').append(
'<span>' + pages[page].length + ' changes</span>',
$('.mw-changeslist-history', pages[page][0]).parent().clone().children().text('history').parent()
),
' <span class="mw-changeslist-separator"></span> ',
diff,
' <span class="mw-changeslist-separator"></span> ',
$('.newpage', pages[page]).clone(),
$('.newpage', pages[page]).length ? ' ' : '',
$('.mw-contributions-title', pages[page][0]).clone(),
$('.mw-uctop', pages[page][0]).length ? ' ' : '',
$('.mw-uctop', pages[page][0]).clone(),
$('.mw-rollback-link', pages[page][0]).length ? ' ' : '',
$('.mw-rollback-link', pages[page][0]).clone()
).insertBefore(pages[page][0]),
sub = $('<ul>').appendTo(head).hide(),
size = 0;
for (var i = 0; i < pages[page].length; i++) {
sub.append(pages[page][i]);
var idiff = $('.mw-changeslist-diff', pages[page][i]);
$('.mw-changeslist-history', pages[page][i]).parent().remove();
idiff.parent().parent().append($('<span>').append(idiff.clone().text('prev')));
idiff.attr('class', 'mw-changeslist-cur').text('cur');
idiff.attr('href') && idiff.attr('href', idiff.attr('href').replace('diff=prev', 'diff=cur'));
size += parseInt($('.mw-diff-bytes', pages[page][i]).text().replace(/,/g, '').replace(/−/g, '-'));
}
if (Math.abs(size) > 500) {
diff.css('font-weight', 'bold');
}
if (size === 0) {
diff.text(size);
diff.addClass('mw-plusminus-null');
} else if (size > 0) {
diff.text('+' + size.toLocaleString());
diff.addClass('mw-plusminus-pos');
} else {
diff.text(size.toLocaleString());
diff.addClass('mw-plusminus-neg');
}
}
}
for (var page in pages) merge(page);
});