/
background.js
70 lines (60 loc) · 1.44 KB
/
background.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
var copiedText = null;
var allClips=[];
// 사이드바 열려있는지 체크
var is_open = false;
whale.sidebarAction.onClicked.addListener(function(result) {
if(result.opened) {
is_open = true;
} else {
is_open = false;
}
});
// 단축키
whale.commands.onCommand.addListener(function (command) {
// 사이드바 on/off 단축키
if(command === "sidebar_action") {
if(is_open) {
whale.sidebarAction.hide();
is_open = false;
} else {
whale.sidebarAction.show();
is_open = true;
}
}
});
chrome.runtime.onMessage.addListener(function(a, c, b) {
if(a.event=="copy"){
copiedText = a.text;
allClips.push(copiedText);
d = allClips.length;
if (d>25) {
e = d-25;
allClips.splice(0,e);
}
// alert(copiedText);
// alert(allClips);
assignBadge()
}
b({copiedText:copiedText})
}
);
function assignBadge(){
var a = allClips.length;
// alert("new badge:"+ a);
whale.sidebarAction.setBadgeText({text:""+a});
// chrome.browserAction.setTitle({title:a+" clips"})
}
function getAllClips(){
return allClips
}
function removeClip(a){
allClips.splice(a,1);
assignBadge();
}
function removeAllClip(){
allClips = [];
assignBadge();
}
function returnClip(a){
return allClips[a];
};