-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
104 lines (74 loc) · 2.56 KB
/
worker.js
File metadata and controls
104 lines (74 loc) · 2.56 KB
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
const archKeywords = {
"Arch:": false,
"amd64": ["amd64", "x86_64"],
"arm64": ["arm64"],
"OS:": false,
"Android": ["android",".apk"],
"Windows": ["windows",".exe",".msi"],
"Linux": ["linux", ".tar.gz",".deb",".rpm",".pacman"],
"----": false,
"Custom (No Preset)": [],
}
async function getPresets() {
const presetsRaw = await fetch('/data/presets.json')
const presets = await presetsRaw.json();
presets["None"] = [];
return presets;
}
console.log("Ready")
// Send tip to content script via messaging
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'getKeywords') {
const fetchKeywords = async () => {
const data = await chrome.storage.local.get('presetName')
const data2 = await chrome.storage.local.get('customKeys')
const presets = await getPresets();
var presetName = data.presetName || "None";
var ckeys = data2.customKeys || "";
console.log(ckeys);
var keywords= [...presets[presetName]];
ckeys.split(",").forEach(key => {
const k = key.trim();
if (k != "") {
keywords.push(k);
}
})
console.log(keywords)
sendResponse({keywords});
}
fetchKeywords();
return true;
}
if (message.type === 'getSettings') {
const fetchSettings = async () => {
const preset = await chrome.storage.local.get('presetName');
const keys = await chrome.storage.local.get('customKeys');
const presets = await getPresets();
var settings= {
preset: preset.presetName || "None",
keys: keys.customKeys || "",
possibePresets: presets,
}
sendResponse({settings});
}
fetchSettings();
return true;
}
if (message.type === 'setSettings') {
console.log("Saving")
const fetchSettings = async () => {
await chrome.storage.local.set({
presetName:message.data.preset,
customKeys: message.data.keys
});
chrome.tabs.query({}, (tabs) => {
tabs.forEach((tab) => {
chrome.tabs.sendMessage(tab.id, {type:"updateKeywords"});
});
});
sendResponse({done:true});
}
fetchSettings();
return true;
}
});