-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopy code block.js
51 lines (42 loc) · 1.63 KB
/
Copy code block.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
const i18n = key => translations.trans[config.lang][key];
class countDownWidget extends api.NoteContextAwareWidget {
get position() {
return 100;
}
get parentWidget() {
return 'center-pane';
}
isEnabled() {
return super.isEnabled();
}
doRender() {
this.$widget = $(``);
return this.$widget;
}
async refreshWithNote(note) {
// only execute in text note
if (note.type !== 'text') {
return;
}
$(document).ready(function () {
var container = $("div.note-split:not(.hidden-ext) > div.scrolling-container > div.note-detail");
function performOperationWhenReady(container) {
// pinpoint code blocks
container.find("pre:not(.CodeMirror-line, .CodeMirror-line-like)").each(function() {
var _this = $(this)[0];
// copy on double click
// unbind first, prevent duplicated event binding
$(this).off('dblclick').on('dblclick', function() {
// extract code block data
var codeContent = _this.innerText;
navigator.clipboard.writeText(codeContent);
api.showMessage(i18n('copied'));
});
});
}
// wait for editor load the content, prevent unexpected things
setTimeout(performOperationWhenReady, config.executeDelay, container);
});
}
}
module.exports = new countDownWidget();