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
33 changed files
with
421 additions
and
183 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
import { HeaderEntries, HeaderEntry } from ".."; | ||
export declare type MonkeyHeader = `// @${string} ${string}` | `// @${string}`; | ||
export declare const makeMonkeyTags: (name?: string) => readonly [openTag: string, closeTag: string]; | ||
export declare const makeMonkeyHeader: <T extends { | ||
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; | ||
}>([name, value,]: HeaderEntry<T>) => MonkeyHeader; | ||
export declare const finalizeMonkeyHeaders: <T extends { | ||
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; | ||
}>(headers: HeaderEntries<T>, spaces: number) => string; |
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,24 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.finalizeMonkeyHeaders = exports.makeMonkeyHeader = exports.makeMonkeyTags = void 0; | ||
const common_1 = require("../../utils/common"); | ||
const makeMonkeyTags = (name = "UserScript") => [ | ||
`// ==${name}==`, | ||
`// ==/${name}==`, | ||
]; | ||
exports.makeMonkeyTags = makeMonkeyTags; | ||
const makeMonkeyHeader = ([name, value,]) => (value ? `// @${name} ${value}` : `// @${name}`); | ||
exports.makeMonkeyHeader = makeMonkeyHeader; | ||
const finalizeMonkeyHeaders = (headers, spaces) => { | ||
const [openTag, closeTag] = exports.makeMonkeyTags(); | ||
const longest = common_1.getLongest(headers.map(([key]) => key)) + spaces; | ||
const indentedHeaders = headers.map(([key, val]) => [ | ||
key.padEnd(longest), | ||
val, | ||
]); | ||
const parsedHeaders = indentedHeaders | ||
.map(exports.makeMonkeyHeader) | ||
.sort(); | ||
return [openTag, ...parsedHeaders, closeTag].join("\n"); | ||
}; | ||
exports.finalizeMonkeyHeaders = finalizeMonkeyHeaders; |
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,3 @@ | ||
import { HeaderGenerator } from ".."; | ||
import { GreasemonkeyGrantOptions } from "./types"; | ||
export declare const generateGreasemonkeyHeaders: HeaderGenerator<GreasemonkeyGrantOptions>; |
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,25 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateGreasemonkeyHeaders = void 0; | ||
const __1 = require(".."); | ||
const monkey_1 = require("../common/monkey"); | ||
const generateGreasemonkeyHeaders = (_packageInfo, { matches = [], grants = [] }) => { | ||
const grantMap = { | ||
set: "GM.setValue", | ||
get: "GM.getValue", | ||
delete: "GM.deleteValue", | ||
list: "GM.listValues", | ||
notify: "GM.notification", | ||
clip: "GM.setClipboard", | ||
fetch: "GM.xmlHttpRequest", | ||
unsafe: "unsafeWindow", | ||
}; | ||
const matchHeaders = __1.generateMatchHeaders(matches); | ||
const grantHeaders = __1.generateGrantHeaders(grantMap, grants); | ||
const headers = [ | ||
...grantHeaders, | ||
...matchHeaders, | ||
]; | ||
return monkey_1.finalizeMonkeyHeaders(headers, 4); | ||
}; | ||
exports.generateGreasemonkeyHeaders = generateGreasemonkeyHeaders; |
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,7 @@ | ||
import { CommonGrantOptions, CommonGrants, CommonHeaders, CommonRunAt, CustomHeaders } from ".."; | ||
export declare type GreasemonkeyGrantOptions = CommonGrantOptions | "notify" | "clip" | "fetch"; | ||
export declare type GreasemonkeyGrants = CommonGrants | "GM.setValue" | "GM.getValue" | "GM.listValues" | "GM.deleteValue" | "GM.notification" | "GM.setClipboard" | "GM.xmlHttpRequest"; | ||
export declare 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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,63 @@ | ||
import { GeneratorOptions } from ".."; | ||
import { RequiredProps } from "../utils/common"; | ||
import { PackageInfo } from "../utils/package"; | ||
import { GreasemonkeyGrantOptions } from "./greasemonkey/types"; | ||
import { TampermonkeyGrantOptions } from "./tampermonkey/types"; | ||
declare global { | ||
interface String { | ||
padEnd<T extends string>(maxLength: number, fillString?: string): T; | ||
} | ||
} | ||
export declare type CommonGrantOptions = "get" | "set" | "list" | "delete" | "unsafe"; | ||
export declare type GrantOptions = GreasemonkeyGrantOptions | TampermonkeyGrantOptions | CommonGrantOptions; | ||
export declare type UserScriptManagerName = "tampermonkey" | "violentmonkey" | "greasemonkey"; | ||
export declare type CommonGrants = "none" | "unsafeWindow"; | ||
export declare type CommonRunAt = "document-start" | "document-end" | "document-idle"; | ||
export declare type HeaderGenerator<T extends GrantOptions> = (info: PackageInfo, options: RequiredProps<GeneratorOptions<T>, "spaces">) => string; | ||
export declare 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 declare type CustomHeaders = { | ||
contributors: string; | ||
}; | ||
export declare type HeaderEntry<T> = [keyof T & string, string]; | ||
export declare type HeaderEntries<T> = HeaderEntry<T>[]; | ||
export declare const generateGrantHeaders: <T extends { | ||
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; | ||
}, U extends GrantOptions>(grantMap: Record<U, T["grant"]>, grants: U[]) => HeaderEntries<T>; | ||
export declare const generateMatchHeaders: <T extends { | ||
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; | ||
}>(matches: string[]) => HeaderEntries<T>; |
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,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateMatchHeaders = exports.generateGrantHeaders = void 0; | ||
const generateGrantHeaders = (grantMap, grants) => { | ||
const grantHeaders = grants.map((grant) => [ | ||
"grant", | ||
grantMap[grant], | ||
]); | ||
return grantHeaders.length | ||
? grantHeaders | ||
: [["grant", "none"]]; | ||
}; | ||
exports.generateGrantHeaders = generateGrantHeaders; | ||
const generateMatchHeaders = (matches) => { | ||
return matches.map((uri) => ["match", uri]); | ||
}; | ||
exports.generateMatchHeaders = generateMatchHeaders; |
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,3 @@ | ||
import { HeaderGenerator } from ".."; | ||
import { TampermonkeyGrantOptions } from "./types"; | ||
export declare const generateTampermonkeyHeaders: HeaderGenerator<TampermonkeyGrantOptions>; |
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,44 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateTampermonkeyHeaders = void 0; | ||
const __1 = require(".."); | ||
const author_1 = require("../../utils/author"); | ||
const common_1 = require("../../utils/common"); | ||
const monkey_1 = require("../common/monkey"); | ||
const generateTampermonkeyHeaders = ({ author, contributors = [], icon, name, description, homepage, bugs: { url: supportURL }, repository: { url: source }, version, }, { spaces, matches = [], grants = [] }) => { | ||
const parsedAuthor = author_1.parseAuthor(author); | ||
const { packageName, scope } = common_1.parseName(name); | ||
const matchHeaders = __1.generateMatchHeaders(matches); | ||
const grantMap = { | ||
set: "GM_setValue", | ||
get: "GM_getValue", | ||
delete: "GM_deleteValue", | ||
list: "GM_listValues", | ||
unsafe: "unsafeWindow", | ||
change: "window.onurlchange", | ||
close: "window.close", | ||
focus: "window.focus", | ||
}; | ||
const grantHeaders = __1.generateGrantHeaders(grantMap, grants); | ||
const headers = [ | ||
["author", author_1.formatAuthor(parsedAuthor)], | ||
["description", description], | ||
["homepage", homepage], | ||
...matchHeaders, | ||
...grantHeaders, | ||
["name", packageName], | ||
["source", source], | ||
["supportURL", supportURL], | ||
["version", version], | ||
]; | ||
if (scope) | ||
headers.push(["namespace", scope]); | ||
if (icon) | ||
headers.push(["icon", icon]); | ||
if (contributors.length) { | ||
const formatted = contributors.map((contributor) => author_1.formatAuthor(author_1.parseAuthor(contributor))); | ||
headers.push(["contributors", formatted.join(", ")]); | ||
} | ||
return monkey_1.finalizeMonkeyHeaders(headers, spaces); | ||
}; | ||
exports.generateTampermonkeyHeaders = generateTampermonkeyHeaders; |
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,23 @@ | ||
import { CommonGrantOptions, CommonGrants, CommonHeaders, CommonRunAt, CustomHeaders } from ".."; | ||
export declare type TampermonkeyGrantOptions = CommonGrantOptions | "close" | "focus" | "change"; | ||
export declare type TampermonkeyGrants = CommonGrants | "GM_setValue" | "GM_getValue" | "GM_listValues" | "GM_deleteValue" | "window.close" | "window.focus" | "window.onurlchange"; | ||
export declare type TampermonkeyHeaders = CustomHeaders & CommonHeaders<{ | ||
"author": string; | ||
"homepage": string; | ||
"homepageURL": string; | ||
"website": string; | ||
"source": string; | ||
"iconURL": string; | ||
"defaulticon": string; | ||
"icon64": string; | ||
"icon64URL": string; | ||
"updateURL": string; | ||
"downloadURL": string; | ||
"supportURL": string; | ||
"connect": string[]; | ||
"run-at": CommonRunAt | "context-menu" | "document-body"; | ||
"grant": TampermonkeyGrants; | ||
"antifeature": `${"ads" | "tracking" | "miner"} ${string}`[]; | ||
"unwrap": ""; | ||
"nocompat": "Chrome" | "Opera" | "FireFox"; | ||
}>; |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
import { CommonGrantOptions, HeaderGenerator } from ".."; | ||
export declare const generateViolentMonkeyHeaders: HeaderGenerator<CommonGrantOptions>; |
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,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateViolentMonkeyHeaders = void 0; | ||
const monkey_1 = require("../common/monkey"); | ||
const generateViolentMonkeyHeaders = ({}) => { | ||
const headers = []; | ||
return monkey_1.finalizeMonkeyHeaders(headers, 4); | ||
}; | ||
exports.generateViolentMonkeyHeaders = generateViolentMonkeyHeaders; |
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,2 @@ | ||
import { CommonHeaders, CustomHeaders } from ".."; | ||
export declare type ViolentMonkeyHeaders = CustomHeaders & CommonHeaders<{}>; |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { GrantOptions, UserScriptManagerName } from "./generators"; | ||
export declare type GeneratorOptions = { | ||
export declare type GeneratorOptions<T extends GrantOptions> = { | ||
packagePath: string; | ||
output: string; | ||
spaces?: number; | ||
matches?: string[]; | ||
grants?: GrantOptions[]; | ||
grants?: T[]; | ||
direct?: boolean; | ||
}; | ||
export declare const generate: (type: UserScriptManagerName, { packagePath, output, spaces, direct, ...rest }: GeneratorOptions) => Promise<string>; | ||
export declare const generate: <T extends GrantOptions>(type: UserScriptManagerName, { packagePath, output, spaces, direct, matches, ...rest }: GeneratorOptions<T>) => Promise<string>; |
Oops, something went wrong.