This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
/
contextMenu.js
66 lines (60 loc) · 1.69 KB
/
contextMenu.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
twocloud.context = {};
twocloud.context.map = {};
twocloud.context.callback = function(info, tab) {
if(twocloud.auth.username == null || twocloud.auth.secret == null) {
alert("Ooops. You need to log in before you can send links.");
return;
} else {
twocloud.links.send(twocloud.auth.username, twocloud.context.map[info.menuItemId].slug, info.linkUrl, null, "chrome", "chrome/context_menu", false, false, function(data, textStatus, jqXHR) {
if(textStatus == "error") {
console.log(data);
console.log(jqXHR);
}
});
}
};
twocloud.context.addDevice = function(device) {
for(id in twocloud.context.map) {
if(twocloud.context.map[id].slug == device.slug) {
return twocloud.context.updateDevice(device);
}
}
id = chrome.contextMenus.create({
"title": device.name,
"contexts": ["link"],
"parentId": twocloud.context.root,
"onclick": twocloud.context.callback
});
twocloud.context.map[id] = device;
};
twocloud.context.removeDevice = function(device) {
for(id in twocloud.context.map) {
if(twocloud.context.map[id].slug == device.slug) {
chrome.contextMenus.remove(parseInt(id));
delete twocloud.context.map[id];
break;
}
}
};
twocloud.context.clear = function() {
for(id in twocloud.context.map) {
chrome.contextMenus.remove(parseInt(id));
delete twocloud.context.map[id];
}
};
twocloud.context.updateDevice = function(device) {
for(id in twocloud.context.map) {
if(twocloud.context.map[id].slug == device.slug) {
chrome.contextMenus.update(parseInt(id), {
"title": device.name
});
break;
}
}
};
twocloud.context.init = function() {
twocloud.context.root = chrome.contextMenus.create({
"title": "Send With 2cloud",
"contexts": ["link"]
});
};