-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmetadata.ts
73 lines (69 loc) · 1.94 KB
/
metadata.ts
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
import { DEFAULT_METADATA_SCHEMA, distFileName } from 'userscripter/build'
import { Metadata, StringItem } from 'userscript-metadata'
import U from './src/userscript'
export type ViolentMonkeyMetadata = Metadata & {
name: string
run_at: string
match: string[]
version: string
author?: string
description?: string
namespace?: string
icon?: string
license?: string
noframes?: true
grant?: string
downloadURL?: string
supportURL?: string
homepageURL?: string
'exclude-match'?: string[]
include?: string[]
exclude?: string[]
}
export const MetadataSchema = {
...DEFAULT_METADATA_SCHEMA,
items: {
...DEFAULT_METADATA_SCHEMA.items,
homepageURL: new StringItem({
key: 'homepageURL',
unique: true,
required: false,
}),
supportURL: new StringItem({
key: 'supportURL',
unique: true,
required: false,
}),
downloadURL: new StringItem({
key: 'downloadURL',
unique: true,
required: false,
}),
},
}
export function generateDownloadUrlFromRepositoryUrl(repositoryUrl: string): string {
const gitRepoExtractorRegex = /^(?:https|git|git\+ssh)[:@](?:\/\/)?[^/:]+[/:]([^/:]+\/.+).git$/
const match = repositoryUrl.match(gitRepoExtractorRegex)
if (match !== null && match.length === 2) {
return `https://raw.githubusercontent.com/${match[1]}/${U.releaseBranch}/${distFileName(U.id, 'user')}`
}
return ''
}
// Will generate the metadata for the code as userscript
export default function metadataConfigFactory(): ViolentMonkeyMetadata {
return {
name: U.name,
description: U.description,
version: U.version,
author: U.author,
grant: 'none',
match: [`*://${U.hostname}/*`, `*://www.${U.hostname}/*`],
namespace: 'greasyfork-namespace-url',
downloadURL: generateDownloadUrlFromRepositoryUrl(U.repositoryURL),
noframes: true,
homepageURL: U.homepage,
supportURL: U.support,
run_at: U.run_at,
license: U.license,
}
}