generated from userscripters/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
279 additions
and
238 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CommonHeaders, HeaderEntry } from ".."; | ||
|
||
export type MonkeyHeader = `// @${string} ${string}` | `// @${string}`; | ||
|
||
export const makeMonkeyTags = ( | ||
name = "UserScript" | ||
): readonly [openTag: string, closeTag: string] => [ | ||
`// ==${name}==`, | ||
`// ==/${name}==`, | ||
]; | ||
|
||
export const makeMonkeyHeader = <T extends CommonHeaders>([ | ||
name, | ||
value, | ||
]: HeaderEntry<T>) => | ||
<MonkeyHeader>(value ? `// @${name} ${value}` : `// @${name}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { HeaderEntries, HeaderGenerator } from ".."; | ||
import { | ||
makeMonkeyHeader, | ||
makeMonkeyTags, | ||
MonkeyHeader, | ||
} from "../common/monkey"; | ||
import { GreasemonkeyHeaders } from "./types"; | ||
|
||
//TODO: finish creating the processor | ||
export const generateGreasemonkeyHeaders: HeaderGenerator = () => { | ||
const [openTag, closeTag] = makeMonkeyTags(); | ||
|
||
const headers: HeaderEntries<GreasemonkeyHeaders> = []; | ||
|
||
const parsedHeaders: MonkeyHeader[] = headers.map(makeMonkeyHeader); | ||
|
||
return ` | ||
${openTag} | ||
${parsedHeaders.join("\n")} | ||
${closeTag} | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { | ||
CommonHeaders, | ||
CommonRunAt, | ||
CustomHeaders, | ||
GreasemonkeyGrants, | ||
} from ".."; | ||
|
||
export type GreasemonkeyHeaders = CustomHeaders & | ||
CommonHeaders<{ | ||
"grant": GreasemonkeyGrants; | ||
"run-at": CommonRunAt; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { GeneratorOptions } from ".."; | ||
import { PackageInfo, RequiredProps } from "../utils"; | ||
|
||
declare global { | ||
interface String { | ||
padEnd<T extends string>(maxLength: number, fillString?: string): T; | ||
} | ||
} | ||
|
||
export type UserScriptManagerName = | ||
| "tampermonkey" | ||
| "violentmonkey" | ||
| "greasemonkey"; | ||
|
||
export type GrantOptions = | ||
| "get" | ||
| "set" | ||
| "list" | ||
| "delete" | ||
| "unsafe" | ||
| "close" | ||
| "focus" | ||
| "change"; | ||
|
||
export type CommonGrants = "none"; | ||
|
||
export type CommonRunAt = "document-start" | "document-end" | "document-idle"; | ||
|
||
/** {@link https://wiki.greasespot.net/@grant} */ | ||
export type GreasemonkeyGrants = | ||
| CommonGrants | ||
| "GM.setValue" | ||
| "GM.getValue" | ||
| "GM.listValues" | ||
| "GM.deleteValue"; | ||
|
||
export type HeaderGenerator = ( | ||
info: PackageInfo, | ||
options: RequiredProps<GeneratorOptions, "spaces"> | ||
) => string; | ||
|
||
export type GeneratorMap = { [P in UserScriptManagerName]: HeaderGenerator }; | ||
|
||
export type CommonHeaders<T extends object = {}> = T & { | ||
description: string; | ||
exclude: string[]; | ||
icon: string; | ||
include: string[]; | ||
match: string[]; | ||
name: string; | ||
namespace: string; | ||
noframes: ""; | ||
resource: string[]; | ||
require: string[]; | ||
version: `${number}.${number}.${number}`; | ||
grant: string; | ||
}; | ||
|
||
export type CustomHeaders = { contributors: string }; | ||
|
||
export type HeaderEntry<T> = [keyof T, T[keyof T]]; | ||
|
||
export type HeaderEntries<T> = HeaderEntry<T>[]; | ||
|
||
/** | ||
* @summary abstract header generator | ||
*/ | ||
export const generateGrantHeaders = <T extends CommonHeaders>( | ||
grantMap: Record<GrantOptions, T["grant"]>, | ||
grants: GrantOptions[] | ||
) => { | ||
const grantHeaders: HeaderEntries<T> = grants.map((grant) => [ | ||
"grant", | ||
grantMap[grant], | ||
]); | ||
|
||
return grantHeaders.length | ||
? grantHeaders | ||
: ([["grant", "none"]] as HeaderEntries<Pick<T, "grant">>); | ||
}; |
Oops, something went wrong.