-
Notifications
You must be signed in to change notification settings - Fork 2
/
userscript.js
63 lines (51 loc) · 1.46 KB
/
userscript.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
import userscriptConfig from "./userscript.config";
const ArrayKeys = [
"include",
"match",
"exclude",
"require",
"resource",
"connect",
"grant",
];
const IgnoreKeys = ["pkgName"];
export const config = userscriptConfig;
export function createBanner(isDev, buildNumber) {
const keys = Object.keys(userscriptConfig);
const filteredKeys = [];
let maxKeyLength = 0;
for (let i = 0, len = keys.length; i < len; i++) {
let key = keys[i];
if (IgnoreKeys.indexOf(key) > -1) {
continue;
}
filteredKeys.push(key);
if (key.length > maxKeyLength) {
maxKeyLength = key.length;
}
}
const headers = [];
headers.push("// ==UserScript==");
for (let i = 0, len = filteredKeys.length; i < len; i++) {
let key = filteredKeys[i];
const config = userscriptConfig[key];
if (ArrayKeys.indexOf(key) > -1) {
if (Array.isArray(config) && config.length > 0) {
config.forEach((c) => {
headers.push(`// @${key.padEnd(maxKeyLength + 1)} ${c}`);
});
} else if (typeof config === "string") {
headers.push(`// @${key.padEnd(maxKeyLength + 1)} ${config}`);
}
} else if (key === "version" && isDev) {
headers.push(
`// @${key.padEnd(maxKeyLength + 1)} ${config}-alpha.${buildNumber}`,
);
} else {
headers.push(`// @${key.padEnd(maxKeyLength + 1)} ${config}`);
}
}
headers.push("// ==/UserScript==");
headers.push("");
return headers.join("\n");
}