-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollapse-all-gitlab-diffs.user.js
44 lines (40 loc) · 1.65 KB
/
collapse-all-gitlab-diffs.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
// ==UserScript==
// @name Collapse all gitlab diffs
// @namespace https://github.com/johanbrandhorst/collapse-gitlab-files
// @version 0.2
// @description Collapses all files on a GitLab merge request diff page
// @author Johan Brandhorst
// @grant none
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @include https://gitlab.com/*/merge_requests/*
// @include https://gitlab.com/*/commit/*
// @include https://*.githost.io/*/merge_requests/*
// @include https://*.githost.io/*/commit/*
// ==/UserScript==
//
// Script based on script suggested by Pantelis Geo
// (https://gitlab.com/pantelis.geo.90)
// in https://gitlab.com/gitlab-org/gitlab-ce/issues/24679
// and StackOverflow answer
// http://stackoverflow.com/questions/6480082/add-a-javascript-button-using-greasemonkey-or-tampermonkey
//
// Warning:
// Depends on GitLab supplying jQuery.
waitForKeyElements (".inline-parallel-buttons", function() {
'use strict';
var button = document.createElement ('a');
button.setAttribute ('id', 'collapse-button');
button.setAttribute ('class', 'btn btn-default');
button.textContent = "Collapse All";
var buttons = document.getElementsByClassName ("inline-parallel-buttons")[0];
buttons.insertBefore (button, buttons.firstChild);
//--- Activate button.
document.getElementById ("collapse-button").addEventListener(
"click", CollapseAll, false
);
function CollapseAll (zEvent) {
$(".diff-file:not(:has(div.nothing-here-block))").each(function (i){
$(this).find("div.file-title-flex-parent").trigger("click");
});
}
});