Skip to content

Commit 27322a5

Browse files
committed
v1.5
1 parent b87a0d8 commit 27322a5

File tree

8 files changed

+670
-4611
lines changed

8 files changed

+670
-4611
lines changed

background.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,152 @@
11
/*--------------------------------------------------------------
22
>>> BACKGROUND
3+
----------------------------------------------------------------
4+
# Update listener
5+
# Message listener
6+
--------------------------------------------------------------*/
7+
8+
/*--------------------------------------------------------------
9+
# UPDATE LISTENER
10+
--------------------------------------------------------------*/
11+
12+
chrome.runtime.onInstalled.addListener(function (details) {
13+
chrome.storage.local.get(function (items) {
14+
if (items.global) {
15+
var global_items = {},
16+
founded = false;
17+
18+
for (var key in items.global) {
19+
var item = items.global[key];
20+
21+
if (typeof item === 'string') {
22+
try {
23+
item = JSON.parse(item);
24+
25+
if (item) {
26+
var value = {
27+
alt: item.altKey,
28+
ctrl: item.ctrlKey,
29+
shift: item.shiftKey
30+
};
31+
32+
if (item.hasOwnProperty('key') && item.hasOwnProperty('keyCode')) {
33+
value.keys = {};
34+
35+
value.keys[item.keyCode] = {
36+
key: item.key
37+
};
38+
}
39+
40+
if (item.click) {
41+
value.click = item.click;
42+
}
43+
44+
if (item.context) {
45+
value.context = item.context;
46+
}
47+
48+
if (item.wheel) {
49+
value.wheel = item.wheel < 0 ? -1 : 1;
50+
}
51+
52+
global_items[key] = value;
53+
54+
founded = true;
55+
}
56+
} catch (error) {
57+
console.log(error);
58+
}
59+
}
60+
}
61+
62+
if (founded === true) {
63+
if (items.global.cut) {
64+
global_items.cut = true;
65+
}
66+
67+
if (items.global.copy) {
68+
global_items.copy = true;
69+
}
70+
71+
if (items.global.paste) {
72+
global_items.paste = true;
73+
}
74+
75+
if (items.global.select) {
76+
global_items.select = true;
77+
}
78+
79+
if (items.global.drag_and_drop) {
80+
global_items.drag_and_drop = true;
81+
}
82+
83+
items.global = global_items;
84+
}
85+
}
86+
87+
if (items.websites) {
88+
for (var hostname in items.websites) {
89+
var website = items.websites[hostname],
90+
website_items = {},
91+
founded = false;
92+
93+
for (var key in website.items) {
94+
var item = website.items[key];
95+
96+
if (typeof item === 'string') {
97+
try {
98+
item = JSON.parse(item);
99+
100+
if (item) {
101+
var value = {
102+
alt: item.altKey,
103+
ctrl: item.ctrlKey,
104+
shift: item.shiftKey
105+
};
106+
107+
if (item.hasOwnProperty('key') && item.hasOwnProperty('keyCode')) {
108+
value.keys = {};
109+
110+
value.keys[item.keyCode] = {
111+
key: item.key
112+
};
113+
}
114+
115+
if (item.click) {
116+
value.click = item.click;
117+
}
118+
119+
if (item.context) {
120+
value.context = item.context;
121+
}
122+
123+
if (item.wheel) {
124+
value.wheel = item.wheel < 0 ? -1 : 1;
125+
}
126+
127+
website_items[key] = value;
128+
129+
founded = true;
130+
}
131+
} catch (error) {
132+
console.log(error);
133+
}
134+
}
135+
}
136+
137+
if (founded === true) {
138+
website.items = website_items;
139+
}
140+
}
141+
}
142+
143+
chrome.storage.local.set(items);
144+
});
145+
});
146+
147+
148+
/*--------------------------------------------------------------
149+
# MESSAGE LISTENER
3150
--------------------------------------------------------------*/
4151

5152
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {

0 commit comments

Comments
 (0)