Skip to content

Commit 9fb4d9f

Browse files
committed
feat: create CreateBanner func
1 parent b1c9c84 commit 9fb4d9f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

builder/source/banner/index.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
export interface BannerOptions {
2+
Version: string
3+
BuildType: 'production' | 'development'
4+
Domains: Set<string>
5+
Author: string
6+
Name: string
7+
Namespace: string
8+
HomepageURL: URL
9+
SupportURL: URL
10+
UpdateURL: URL
11+
DownloadURL: URL
12+
License: string
13+
Description: Record<'en' | 'ko' | 'ja' | string, string>
14+
}
15+
16+
export function CreateBanner(Options: BannerOptions): string {
17+
let BannerString: string = '// ==UserScript==\n'
18+
BannerString += `// @name ${Options.BuildType === 'production' ? Options.Name : Options.Name + ' (Development)'}\n`
19+
BannerString += '//\n'
20+
BannerString += `// @namespace ${Options.Namespace}\n`
21+
BannerString += `// @homepageURL ${Options.HomepageURL.href}\n`
22+
BannerString += `// @supportURL ${Options.SupportURL.href}\n`
23+
BannerString += `// @updateURL ${Options.UpdateURL.href}\n`
24+
BannerString += `// @downloadURL ${Options.DownloadURL.href}\n`
25+
BannerString += `// @license ${Options.License}\n`
26+
BannerString += '//\n'
27+
BannerString += `// @version ${Options.Version}\n`
28+
BannerString += `// @author ${Options.Author}\n`
29+
BannerString += '//\n'
30+
BannerString += '// @grant unsafeWindow\n'
31+
BannerString += '// @run-at document-start\n'
32+
BannerString += '//\n'
33+
BannerString += `// @description ${Options.Description['en']}\n`
34+
35+
for (const Key of Object.keys(Options.Description)) {
36+
if (Key === 'en') continue
37+
BannerString += `// @description:${Key} ${Options.Description[Key]}\n`
38+
}
39+
BannerString += '//\n'
40+
41+
for (const Domain of Options.Domains) {
42+
BannerString += `// @match *://${Domain}/*\n`
43+
BannerString += `// @match *://*.${Domain}/*\n`
44+
}
45+
BannerString += '// ==/UserScript==\n\n'
46+
return BannerString
47+
}

0 commit comments

Comments
 (0)