-
Notifications
You must be signed in to change notification settings - Fork 1
/
gh.js
112 lines (82 loc) · 2.83 KB
/
gh.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(function($, g) {
var gh = g.g = {};
/**
* Получить список изменённых в pull request файлов.
*
* @alias gf
* @alias g.files
* @param {Boolean} isVisible - Если true, то вывести только отображённые файлы.
*/
g.gf = gh.files = function(isVisible) {
var selector = '.file' + (isVisible ? ':visible' : ''),
files = [];
console.clear();
$(selector).each(function() {
var $file = $(this),
path = $file.find('.js-selectable-text').attr('title'),
diffstat = parseInt($file.find('.diffstat').text());
console.log(path + ' (' + diffstat + ')');
});
return '';
};
/**
* Отобразить только соответствующие шаблону файлы.
* Если вызвать без параметра откроет все скрытые файлы.
*
* @alias go
* @alias g.only
* @param {String|String[]|RegExp|RegExp[]} files - Набор шаблонов путей файлов.
*/
g.go = gh.only = function(files) {
!files && (files = '');
!$.isArray(files) && (files = [files]);
var strategies = {
string: function(pattern) {
return function(str) {
return ~str.indexOf(pattern);
}
},
regexp: function(pattern) {
return function(str) {
return pattern.test(str);
}
}
},
patterns = [], i;
for (i=0; i<files.length; i++) {
patterns.push(strategies[files[i].test ? 'regexp' : 'string'](files[i]));
}
$('.file').each(function() {
var $file = $(this),
path = $file.find('.js-selectable-text').attr('title'),
hide = true, i;
for (i=0; i<patterns.length; i++) {
if (patterns[i](path)) {
hide = false;
break;
}
}
hide
? $file.hide()
: $file.show();
});
return gh.files(true);
};
/**
* Показать / скрыть комментарии.
* Если комментарии были скрыты, они откроются и наоборот.
*
* @alias gc
* @alias g.comments
*/
g.gc = gh.comments = function() {
console.clear();
return $('.inline-comments')
.toggle()
.is(':visible')
? 'comments visible'
: 'comments not visible';
};
console.clear();
return 'Github helpers inited';
})(jQuery, window);