forked from Atrasoftware/chrome-virtual-keyboard-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
121 lines (119 loc) · 4.02 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getLocalStorage")
{
sendResponse({data: localStorage[request.key]});
}
else if (request.method == "getSmallKeyboardCoords")
{
sendResponse({smallKeyboard: localStorage["smallKeyboard"], smallKeyboardTop: localStorage["smallKeyboardTop"], smallKeyboardBottom: localStorage["smallKeyboardBottom"], smallKeyboardRight: localStorage["smallKeyboardRight"], smallKeyboardLeft: localStorage["smallKeyboardLeft"]});
}
else if (request.method == "loadKeyboardSettings")
{
sendResponse({openedFirstTime: localStorage["openedFirstTime"],
capsLock: localStorage["capsLock"],
smallKeyboard: localStorage["smallKeyboard"],
touchEvents: localStorage["touchEvents"],
keyboardLayout1: localStorage["keyboardLayout1"],
urlButton: localStorage["urlButton"],
keyboardEnabled: localStorage["keyboardEnabled"]});
}
else if (request.method == "initLoadKeyboardSettings")
{
sendResponse({hardwareAcceleration: localStorage["hardwareAcceleration"],
zoomLevel: localStorage["zoomLevel"],
autoTrigger: localStorage["autoTrigger"],
repeatLetters: localStorage["repeatLetters"],
intelligentScroll: localStorage["intelligentScroll"],
autoTriggerLinks: localStorage["autoTriggerLinks"],
autoTriggerAfter: localStorage["autoTriggerAfter"]});
}
else if (request.method == "setLocalStorage")
{
localStorage[request.key] = request.value;
sendResponse({data: "ok"});
}
else if (request.method == "openFromIframe")
{
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, request);
});
}
else if (request.method == "clickFromIframe")
{
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, request);
});
}
else if (request.method == "toogleKeyboard")
{
if (localStorage["keyboardEnabled"] != "false") {
localStorage["keyboardEnabled"] = "false";
} else {
localStorage["keyboardEnabled"] = "true";
}
chrome.tabs.getSelected(null, function(tab) {
vkeyboard_loadPageIcon(tab.id);
if (localStorage["keyboardEnabled"] == "false") {
chrome.tabs.sendRequest(tab.id, "closeKeyboard");
} else {
chrome.tabs.sendRequest(tab.id, "openKeyboard");
}
})
sendResponse({data: "ok"});
}
else if (request.method == "toogleKeyboardOn")
{
localStorage["keyboardEnabled"] = "true";
chrome.tabs.getSelected(null, function(tab) {
vkeyboard_loadPageIcon(tab.id);
chrome.tabs.sendRequest(tab.id, "openKeyboard");
})
sendResponse({data: "ok"});
}
else if (request.method == "toogleKeyboardDemand")
{
localStorage["keyboardEnabled"] = "demand";
chrome.tabs.getSelected(null, function(tab) {
vkeyboard_loadPageIcon(tab.id);
chrome.tabs.sendRequest(tab.id, "openKeyboard");
})
sendResponse({data: "ok"});
}
else if (request.method == "toogleKeyboardOff")
{
localStorage["keyboardEnabled"] = "false";
chrome.tabs.getSelected(null, function(tab) {
vkeyboard_loadPageIcon(tab.id);
chrome.tabs.sendRequest(tab.id, "closeKeyboard");
})
sendResponse({data: "ok"});
}
else if (request.method == "openUrlBar")
{
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, "openUrlBar");
sendResponse({data: "ok" });
});
}
else {
sendResponse({});
}
});
function vkeyboard_loadPageIcon(tabId) {
if (localStorage["keyboardEnabled"] == "demand") {
chrome.pageAction.setIcon({ tabId: tabId, path: "buttons/keyboard_2.png" }, function() { })
} else if (localStorage["keyboardEnabled"] != "false") {
chrome.pageAction.setIcon({ tabId: tabId, path: "buttons/keyboard_1.png" }, function() { })
} else {
chrome.pageAction.setIcon({ tabId: tabId, path: "buttons/keyboard_3.png" }, function() { })
}
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (localStorage["toogleKeyboard"] != "false") {
chrome.pageAction.show(tabId);
vkeyboard_loadPageIcon(tabId);
} else {
localStorage["keyboardEnabled"] = "true";
chrome.pageAction.hide(tabId);
}
});