This repository has been archived by the owner on Dec 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprune.js
162 lines (126 loc) · 3.99 KB
/
prune.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var _mounted = false;
var _parents = {};
//console.log(ev.currentTarget.getAttribute('data-container-id'));
//var containerId = ev.currentTarget.getAttribute('data-container-id');
/*
background:#dcdcdc;
box-shadow:inset 0 3px 5px rgba(0,0,0,0.15);
color: #6a6
background:#8c8;
box-shadow:inset 0 3px 5px rgba(0,0,0,0.15);
<a href="#" class="minibutton" style="background:#9c9;box-shadow:inset 0 3px 5px rgba(0,0,0,0.15);">Done</a>
document.querySelectorAll('div.js-details-container.file .meta .actions .button-group')
document.querySelectorAll('.data')[5].getBoundingClientRect().top
.meta style = position:fixed;top:0;width:918px
*/
function prId(pathname) {
var re = /\/([^\/]+)\/([^\/]+)\/pull\/(\d+)\/.*/;
var matches = re.exec(pathname);
return matches.splice(1).join('$');
}
function storageKey() {
return 'supr:' + prId(location.pathname);
}
function md5(str) {
return CryptoJS.MD5(str).toString(CryptoJS.enc.Base64);
}
function set(file, hash) {
var store = window.localStorage;
var data = JSON.parse(store.getItem(storageKey()));
data[file] = hash;
store.setItem(storageKey(), JSON.stringify(data));
}
function unset(file) {
var store = window.localStorage;
var data = JSON.parse(store.getItem(storageKey()));
if (data[file]) {
delete data[file];
store.setItem(storageKey(), JSON.stringify(data));
}
}
function list() {
var store = window.localStorage;
return JSON.parse(store.getItem(storageKey()));
}
function reset() {
console.log('resetting', storageKey());
window.localStorage.setItem(storageKey(), JSON.stringify({}));
}
function getParent(file) {
if (_.isUndefined(_parents[file])) {
_parents[file] = Zepto(
Zepto('div.meta[data-path="' + file + '"]')
.closest('div.file.js-details-container'));
}
return _parents[file];
}
function toggle(file) {
var $parent = getParent(file);
var $data = Zepto($parent.find('.data')[0]);
var $meta = Zepto($parent.find('.meta')[0]);
if ($data.css('display') == 'block' || $data.css('display') == '') {
hide(file);
}
else {
show(file);
}
}
function show(file) {
var $parent = getParent(file);
var $data = Zepto($parent.find('.data')[0]);
var $meta = Zepto($parent.find('.meta')[0]);
console.log('showing', $parent);
unset($meta.attr('data-path'));
$data.css('display', 'block');
Zepto('.supr-done', $meta).removeClass('supr-done-active');
}
function hide(file) {
var $parent = getParent(file);
var $data = Zepto($parent.find('.data')[0]);
var $meta = Zepto($parent.find('.meta')[0]);
console.log('hiding', $parent);
$data.css('display', 'none');
set($meta.attr('data-path'), md5($data.html()));
Zepto('.supr-done', $meta).addClass('supr-done-active');
}
function boot() {
console.log(list());
_.forIn(list(), function(v, k) {
hide(k);
});
}
function mount() {
if (_mounted) return true;
var files = Zepto('#files > div.file.js-details-container');
Zepto('.meta > .actions > .button-group', files)
.append('<a href="#" class="minibutton supr-done" style="">Done</a>')
.on('click', function(ev) {
ev.preventDefault();
var $parent = Zepto(
Zepto(ev.currentTarget)
.closest('div.file.js-details-container'));
var $meta = Zepto($parent.find('.meta')[0]);
toggle($meta.attr('data-path'));
});
$menu = Zepto('<div><a href="" class="minibutton supr-menu">Menu</a><a href="" class="minibutton supr-set">Set</a></div>')
.css('position', 'fixed')
.css('top', '10px')
.css('right', '10px');
Zepto('.supr-menu', $menu).on('click', function(ev) {
ev.preventDefault();
});
Zepto('.supr-set', $menu).on('click', function(ev) {
ev.preventDefault();
reset();
});
Zepto('body').append($menu);
boot();
_mounted = true;
}
window.addEventListener('load', function() {
//var tabs = document.getElementsByClassName('js-pull-request-tab');
//_.forEach(tabs, function(tab) {
// tab.addEventListener('click', handleTabClick);
//});
mount();
});