forked from bgcho98/DoorayClipboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
427 lines (393 loc) · 13.8 KB
/
contentScript.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
!(function(t) {
function n(i) {
if (e[i]) return e[i].exports
var o = (e[i] = { i: i, l: !1, exports: {} })
return t[i].call(o.exports, o, o.exports, n), (o.l = !0), o.exports
}
var e = {}
;(n.m = t),
(n.c = e),
(n.d = function(t, e, i) {
n.o(t, e) || Object.defineProperty(t, e, { configurable: !1, enumerable: !0, get: i })
}),
(n.n = function(t) {
var e =
t && t.__esModule
? function() {
return t.default
}
: function() {
return t
}
return n.d(e, 'a', e), e
}),
(n.o = function(t, n) {
return Object.prototype.hasOwnProperty.call(t, n)
}),
(n.p = ''),
n((n.s = 0))
})([
function(t, n, e) {
e(1), (t.exports = e(4))
},
function(t, n, e) {
'use strict'
var i =
Object.assign ||
function(t) {
for (var n = 1; n < arguments.length; n++) {
var e = arguments[n]
for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i])
}
return t
}
e(2)
var o = e(3)
!(function(t) {
function n(t) {
return (
(t = i({}, c, t)),
(function(t) {
return ['nfc-top-left', 'nfc-top-right', 'nfc-bottom-left', 'nfc-bottom-right'].indexOf(t) > -1
})(t.positionClass) ||
(console.warn('An invalid notification position class has been specified.'), (t.positionClass = c.positionClass)),
t.onclick &&
'function' != typeof t.onclick &&
(console.warn('Notification on click must be a function.'), (t.onclick = c.onclick)),
'number' != typeof t.showDuration && (t.showDuration = c.showDuration),
((0, o.isString)(t.theme) && 0 !== t.theme.length) ||
(console.warn('Notification theme must be a string with length'), (t.theme = c.theme)),
t
)
}
function e(t) {
return (
(t = n(t)),
function() {
var n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
e = n.title,
i = n.message,
c = r(t.positionClass)
if (!e && !i) return console.warn('Notification must contain a title or a message!')
var a = (0, o.createElement)('div', 'ncf', t.theme)
if (
(!0 === t.closeOnClick &&
a.addEventListener('click', function() {
return c.removeChild(a)
}),
t.onclick &&
a.addEventListener('click', function(n) {
return t.onclick(n)
}),
t.displayCloseButton)
) {
var s = (0, o.createElement)('button')
;(s.innerText = 'X'),
!1 === t.closeOnClick &&
s.addEventListener('click', function() {
return c.removeChild(a)
}),
(0, o.append)(a, s)
}
if (
((0, o.isString)(e) && e.length && (0, o.append)(a, (0, o.createParagraph)('ncf-title')(e)),
(0, o.isString)(i) && i.length && (0, o.append)(a, (0, o.createParagraph)('nfc-message')(i)),
(0, o.append)(c, a),
t.showDuration && t.showDuration > 0)
) {
var l = setTimeout(function() {
c.removeChild(a), 0 === c.querySelectorAll('.ncf').length && document.body.removeChild(c)
}, t.showDuration)
;(t.closeOnClick || t.displayCloseButton) &&
a.addEventListener('click', function() {
return clearTimeout(l)
})
}
}
)
}
function r(t) {
var n = document.querySelector('.' + t)
return n || ((n = (0, o.createElement)('div', 'ncf-container', t)), (0, o.append)(document.body, n)), n
}
var c = {
closeOnClick: !0,
displayCloseButton: !1,
positionClass: 'nfc-top-right',
onclick: !1,
showDuration: 3500,
theme: 'success'
}
t.createNotification
? console.warn('Window already contains a create notification function. Have you included the script twice?')
: (t.createNotification = e)
})(window)
},
function(t, n, e) {
'use strict'
!(function() {
function t(t) {
this.el = t
for (var n = t.className.replace(/^\s+|\s+$/g, '').split(/\s+/), i = 0; i < n.length; i++) e.call(this, n[i])
}
if (!(void 0 === window.Element || 'classList' in document.documentElement)) {
var n = Array.prototype,
e = n.push,
i = n.splice,
o = n.join
;(t.prototype = {
add: function(t) {
this.contains(t) || (e.call(this, t), (this.el.className = this.toString()))
},
contains: function(t) {
return -1 != this.el.className.indexOf(t)
},
item: function(t) {
return this[t] || null
},
remove: function(t) {
if (this.contains(t)) {
for (var n = 0; n < this.length && this[n] != t; n++);
i.call(this, n, 1), (this.el.className = this.toString())
}
},
toString: function() {
return o.call(this, ' ')
},
toggle: function(t) {
return this.contains(t) ? this.remove(t) : this.add(t), this.contains(t)
}
}),
(window.DOMTokenList = t),
(function(t, n, e) {
Object.defineProperty ? Object.defineProperty(t, n, { get: e }) : t.__defineGetter__(n, e)
})(Element.prototype, 'classList', function() {
return new t(this)
})
}
})()
},
function(t, n, e) {
'use strict'
Object.defineProperty(n, '__esModule', { value: !0 })
var i = (n.partial = function(t) {
for (var n = arguments.length, e = Array(n > 1 ? n - 1 : 0), i = 1; i < n; i++) e[i - 1] = arguments[i]
return function() {
for (var n = arguments.length, i = Array(n), o = 0; o < n; o++) i[o] = arguments[o]
return t.apply(void 0, e.concat(i))
}
}),
o = ((n.append = function(t) {
for (var n = arguments.length, e = Array(n > 1 ? n - 1 : 0), i = 1; i < n; i++) e[i - 1] = arguments[i]
return e.forEach(function(n) {
return t.appendChild(n)
})
}),
(n.isString = function(t) {
return 'string' == typeof t
}),
(n.createElement = function(t) {
for (var n = arguments.length, e = Array(n > 1 ? n - 1 : 0), i = 1; i < n; i++) e[i - 1] = arguments[i]
var o = document.createElement(t)
return (
e.length &&
e.forEach(function(t) {
return o.classList.add(t)
}),
o
)
})),
r = function(t, n) {
return (t.innerText = n), t
},
c = function(t) {
for (var n = arguments.length, e = Array(n > 1 ? n - 1 : 0), c = 1; c < n; c++) e[c - 1] = arguments[c]
return i(r, o.apply(void 0, [t].concat(e)))
}
n.createParagraph = function() {
for (var t = arguments.length, n = Array(t), e = 0; e < t; e++) n[e] = arguments[e]
return c.apply(void 0, ['p'].concat(n))
}
},
function(t, n) {}
])
function copyToClipboard(text, elementId) {
if( elementId === undefined) {
var t = document.createElement('textarea')
document.body.appendChild(t)
t.value = text
t.select()
document.execCommand('copy')
document.body.removeChild(t)
}
else {
var range = document.createRange();
var selection = window.getSelection();
range.selectNodeContents(document.getElementById(elementId));
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
selection.removeAllRanges();
}
}
function initButton(id, buttonTitle, copyText, elementId) {
let button = document.createElement('button')
button.id = id
button.textContent = buttonTitle
button.className = 'link-btn d-toolbar-white-icon-btn url-button ng-isolate-scope'
button.addEventListener(
'click',
function() {
copyToClipboard(copyText, elementId)
window.createNotification({
closeOnClick: true,
displayCloseButton: true,
positionClass: 'nfc-top-right',
showDuration: 3000,
theme: 'info'
})({
title: '클립보드 COPY',
message: copyText
})
},
false
)
return button
}
function initPullMsgButton(id, buttonTitle, copyText, saveObj) {
let button = document.createElement('button')
button.id = id
button.textContent = buttonTitle
button.className = 'link-btn d-toolbar-white-icon-btn url-button ng-isolate-scope'
button.addEventListener(
'click',
function() {
saveStorage(saveObj)
copyToClipboard(copyText)
window.createNotification({
closeOnClick: true,
displayCloseButton: true,
positionClass: 'nfc-top-right',
showDuration: 3000,
theme: 'info'
})({
title: '클립보드 COPY',
message: copyText
})
},
false
)
return button
}
function saveStorage (saveObj) {
if(!isProjectPath()) {
return;
}
var doorayProjectIdMap = {}
chrome.storage.local.get("doorayProjectIdMap", result => {
doorayProjectIdMap = result['doorayProjectIdMap'] || {}
doorayProjectIdMap[saveObj.id] = saveObj
chrome.storage.local.set({"doorayProjectIdMap": doorayProjectIdMap}, () => {})
})
}
function isProjectPath() {
try {
parseInt(getProjectId())
if(window.location.pathname.split('/')[1] != 'project') {
return false;
}
} catch (e) {
return false;
}
return true;
}
function getProjectId() {
return window.location.pathname.split('/')[2];
}
function createButtonStorageDelete(id, buttonTitle, saveId, saveText, buttonBar) {
if(!isProjectPath()) {
return;
}
let doorayProjectIdMapToValid = {}
chrome.storage.local.get("doorayProjectIdMap", result => {
doorayProjectIdMapToValid = result['doorayProjectIdMap'] || {}
if (doorayProjectIdMapToValid[saveId] == null || doorayProjectIdMapToValid[saveId] === undefined) {
return;
}
let button = document.createElement('button')
button.id = id
button.textContent = buttonTitle
button.className = 'link-btn d-toolbar-white-icon-btn url-button ng-isolate-scope'
button.addEventListener(
'click',
function() {
let doorayProjectIdMapToDelete = {}
chrome.storage.local.get("doorayProjectIdMap", resultStorage => {
doorayProjectIdMapToDelete = resultStorage['doorayProjectIdMap'] || {}
delete doorayProjectIdMapToDelete[saveId]
chrome.storage.local.set({"doorayProjectIdMap": doorayProjectIdMapToDelete}, () => {})
})
window.createNotification({
closeOnClick: true,
displayCloseButton: true,
positionClass: 'nfc-top-right',
showDuration: 3000,
theme: 'info'
})({
title: 'Chrome Storage 삭제',
message: saveId
})
buttonBar.removeChild(button)
},
false
)
buttonBar.appendChild(button)
})
}
function appendButton(target) {
let buttonIds = ['QFD1boxRNX0', 'QFD1boxRNX1', 'QFD1boxRNX2', 'QFD1boxRNX3', 'QFD1boxRNX10']
var titleElement = target.querySelector('span.subject.ng-binding');
if( titleElement === null) {
return
}
let title = titleElement.textContent
let projectName = target.querySelector('span[ng-bind=\\:\\:\\$ctrl\\.post\\.projectCode]').textContent
let postNumber = target.querySelector('span[ng-bind=\\:\\:\\$ctrl\\.post\\.number]').textContent
let previousNumberButton = target.querySelector('button[id=' + buttonIds[0] + ']')
if (previousNumberButton && previousNumberButton.textContent === postNumber) {
return
}
let buttonBar = target.querySelector('div.header-right-toolbar.pull-right.layout-align-start-center.layout-row')
if (previousNumberButton) {
for (let i = 0; i < buttonIds.length; i++) {
let button = target.querySelector('button[id=' + buttonIds[i] + ']')
buttonBar.removeChild(button)
}
}
let headerLinkLine = target.querySelector('div.header-link-line.layout-align-start-center.layout-row')
let link = buttonBar.childNodes[1].getAttribute('data-clipboard-text')
var numberButton = initButton(buttonIds[0], postNumber, postNumber)
var commitButton = initButton(buttonIds[1], '커밋메시지', postNumber + ' ' + title)
var pullRequestButton = initPullMsgButton(buttonIds[2], 'Pull메시지', '#' + projectName + '/' + postNumber + ': ' + title, {"id": getProjectId(), "text": projectName})
let onelineText = postNumber + '/' + title
var aTag = document.createElement('a');
aTag.setAttribute('id', 'clipboard');
aTag.value = onelineText
aTag.innerHTML = onelineText.link(link)
headerLinkLine.appendChild(aTag);
var messageWithLinkButton = initButton(buttonIds[3], '메시지+링크', onelineText, aTag.getAttribute('id'))
buttonBar.appendChild(numberButton)
buttonBar.appendChild(commitButton)
buttonBar.appendChild(pullRequestButton)
buttonBar.appendChild(messageWithLinkButton)
createButtonStorageDelete(buttonIds[4], 'D프로젝트ID삭제', getProjectId(), projectName, buttonBar)
}
function checkAndAppendButton() {
let targets = document.getElementsByClassName('task-view ng-scope layout-column')
for (let i = 0; i < targets.length; i++) {
appendButton(targets[i])
}
}
setInterval(() => {
checkAndAppendButton()
}, 1000)