Repository navigation
Expand file tree
/
Copy pathgithub-pr-tools.user.js
More file actions
71 lines (56 loc) · 2.05 KB
/
Copy pathgithub-pr-tools.user.js
File metadata and controls
71 lines (56 loc) · 2.05 KB
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
// ==UserScript==
// @name GitHub PR Tools
// @namespace https://github.com/
// @version 0.1
// @description Adds PR helper tools
// @author Matthew Batchelder
// @include /https?:\/\/github\.com.*\/pull\/.*/
// @require https://code.jquery.com/jquery-3.2.1.min.js
// @grant none
// ==/UserScript==
( function( $ ) {
'use strict';
var obj = {
specFiles: []
};
/**
* Initialize
*/
obj.init = function() {
var $reviewTools = $( '.pr-review-tools' );
var specFiles = obj.getSpecFiles();
$reviewTools.prepend( '<div class="diffbar-item"><button class="btn btn-sm" id="tribe-suppress-spec"><span id="tribe-suppress-spec-showhide">Hide</span> spec.js<span id="tribe-suppress-spec-count"></span></button></div>' );
$reviewTools.on( 'click', '#tribe-suppress-spec', function( e ) {
var specFiles = obj.getSpecFiles();
var $el = $( this );
var isActive = $el.hasClass( 'active' );
$( '#tribe-suppress-spec-count' ).text( ' (' + specFiles.length + ')' );
var $showhide = $( '#tribe-suppress-spec-showhide' );
specFiles.forEach( function( el ) {
$( '.js-details-target', el ).click();
} );
if ( isActive ) {
$el.removeClass( 'active' );
$showhide.html( 'Hide' );
} else {
$el.addClass( 'active' );
$showhide.html( 'Show' );
}
} );
};
obj.getSpecFiles = function() {
// Reset spec files array
obj.specFiles = [];
var jsFiles = document.getElementsByClassName( 'js-file' );
Array.prototype.forEach.call( jsFiles, function( el, index, array ) {
var fileloc = el.querySelector( '.file-info a' );
if ( fileloc.innerText.match( /\.spec\.js/ ) ) {
obj.specFiles.push( el );
}
} );
return obj.specFiles;
};
$( function() {
obj.init();
} );
})( jQuery );