-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_script.js
44 lines (40 loc) · 1.2 KB
/
event_script.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
let copyCommand = "copy text";
let message = "Copy";
let message2 = "Get Text";
let message3 = "Text";
let message4 = "Save";
let currentText = "I-I_I-I SUCK";
let keys = ["number", "deviation", "overlay", "double", "space", "english", "chaotic", "upper", "text"];
let defaults = [10, 0, 0.5, 0.5, false, true, true, 0.5, "I-I_I-I SUCK"];
for (let i = 0; i < keys.length; i++) {
chrome.storage.sync.get(keys[i], items => {
if (items[keys[i]] === undefined) {
let items = {};
items[keys[i]] = defaults[i];
chrome.storage.sync.set(items, () => {});
}
});
}
chrome.storage.sync.get(keys[8], items => {
if (items[keys[8]] !== undefined) {
currentText = items[keys[8]];
}
});
chrome.commands.onCommand.addListener(command => {
if (command == copyCommand) {
chrome.runtime.sendMessage(message, () => {});
}
});
chrome.runtime.onMessage.addListener((msg, _, response) => {
if (msg == message2) {
response();
chrome.runtime.sendMessage({message: message3, text: currentText}, () => {});
}
else if (msg.message == message4) {
response();
currentText = msg.text;
let items = {};
items[keys[8]] = currentText;
chrome.storage.sync.set(items, () => {});
}
});