-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_images.js
48 lines (41 loc) · 1.24 KB
/
custom_images.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
function save_custom_image(info, tab){
var custom_URLs = JSON.parse(localStorage["custom_URLs"]);
custom_URLs.push(info.srcUrl);
localStorage["custom_URLs"] = JSON.stringify(custom_URLs);
}
function delete_custom_image(info, tab){
var custom_URLs = JSON.parse(localStorage["custom_URLs"]);
var index_to_kill = custom_URLs.indexOf(info.srcUrl);
custom_URLs.splice(index_to_kill, 1);
localStorage["custom_URLs"] = JSON.stringify(custom_URLs);
}
function menu_on_click(info, tab){
if (info.menuItemId == "save_image_menu")
save_custom_image(info, tab);
else if (info.menuItemId == "delete_image_menu")
delete_custom_image(info, tab);
}
function make_buttons(){
var parent_menu = chrome.contextMenus.create({
"type": "normal",
"id": "parent_menu",
"title": "Sponsored Corgis",
"contexts": ["image"],
});
var save_image_menu = chrome.contextMenus.create({
"type": "normal",
"title": "Save image",
"id": "save_image_menu",
"parentId": parent_menu,
"contexts": ["image"],
});
var delete_image_menu = chrome.contextMenus.create({
"type": "normal",
"title": "Delete image",
"id": "delete_image_menu",
"parentId": parent_menu,
"contexts": ["image"],
});
chrome.contextMenus.onClicked.addListener(menu_on_click);
}
make_buttons();