-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
75 lines (64 loc) · 1.44 KB
/
preload.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
/* eslint-disable no-undef */
const version = '1.0.1';
const defaultSplitChar = ":"
const defaultConfigList = [
{
id: "vue",
hotKey: 'v',
title: 'cn.vuejs.org',
appId: "UURH1MHAF7",
indexName: 'vuejs_cn2',
apiKey: 'c23eb8e7895f42daeaf2bf6f63eb4bf6',
facetFilters: "",
disabled: false,
},
{
id: "vite",
hotKey: 'vi',
title: 'cn.vitejs.dev',
appId: "7H67QR5P0A",
indexName: 'vitejs',
apiKey: 'deaab78bcdfe96b599497d25acc6460e',
facetFilters: '["tags:cn","lang:zh-CN"]',
disabled: false,
}
];
const applyConfig = () => {
const config = utools.db.get('config');
// 需要动态添加配置的数组
let configList = defaultConfigList;
let split = defaultSplitChar;
if (!config) {
utools.db.put({
_id: 'config',
data: {
version: version,
configList: configList,
split: split,
}
});
} else {
split = config.data.split;
configList = config.data?.configList || [];
}
const cmds = configList.map((e) => {
return {
"type": "regex",
"label": `在${e.title}搜索`,
"match": `/${e.hotKey}${split}/i`,
"minLength": 1
}
});
if (cmds.length > 0) {
const features = {
"code": "utools-docsearch",
"explain": "docsearch匹配网站",
"cmds": cmds
};
utools.setFeature(features);
}
}
utools.onPluginReady(() => {
applyConfig()
})
window.applyConfig = applyConfig;