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
5 changed files
with
124 additions
and
117 deletions.
There are no files selected for viewing
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
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
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,87 +1,88 @@ | ||
import { | ||
generateGrantHeaders, | ||
HeaderEntries, | ||
HeaderGenerator, | ||
} from ".."; | ||
import { parseName } from "../../utils/common"; | ||
import { generateGrantHeaders, HeaderEntries, HeaderGenerator } from ".."; | ||
import { formatAuthor, parseAuthor } from "../../utils/author"; | ||
import { parseName } from "../../utils/common"; | ||
import { finalizeMonkeyHeaders } from "../common/monkey"; | ||
import { TampermonkeyGrantOptions, TampermonkeyGrants, TampermonkeyHeaders } from "./types"; | ||
import { | ||
TampermonkeyGrantOptions, | ||
TampermonkeyGrants, | ||
TampermonkeyHeaders, | ||
} from "./types"; | ||
|
||
export const generateTampermonkeyHeaders: HeaderGenerator = ( | ||
{ | ||
author, | ||
contributors = [], | ||
icon, | ||
name, | ||
description, | ||
homepage, | ||
bugs: { url: supportURL }, | ||
repository: { url: source }, | ||
version, | ||
}, | ||
{ spaces, matches = [], grants = [] } | ||
) => { | ||
const parsedAuthor = parseAuthor(author); | ||
const { packageName, scope } = parseName(name); | ||
export const generateTampermonkeyHeaders: HeaderGenerator<TampermonkeyGrantOptions> = | ||
( | ||
{ | ||
author, | ||
contributors = [], | ||
icon, | ||
name, | ||
description, | ||
homepage, | ||
bugs: { url: supportURL }, | ||
repository: { url: source }, | ||
version, | ||
}, | ||
{ spaces, matches = [], grants = [] } | ||
) => { | ||
const parsedAuthor = parseAuthor(author); | ||
const { packageName, scope } = parseName(name); | ||
|
||
const matchHeaders: HeaderEntries<TampermonkeyHeaders> = matches.map( | ||
(uri) => ["match", uri] | ||
); | ||
const matchHeaders: HeaderEntries<TampermonkeyHeaders> = matches.map( | ||
(uri) => ["match", uri] | ||
); | ||
|
||
const grantMap: Record<TampermonkeyGrantOptions, TampermonkeyGrants> = { | ||
set: "GM_setValue", | ||
get: "GM_getValue", | ||
delete: "GM_deleteValue", | ||
list: "GM_listValues", | ||
unsafe: "unsafeWindow", | ||
change: "window.onurlchange", | ||
close: "window.close", | ||
focus: "window.focus", | ||
}; | ||
const grantMap: Record<TampermonkeyGrantOptions, TampermonkeyGrants> = { | ||
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 = generateGrantHeaders<TampermonkeyHeaders, TampermonkeyGrantOptions>( | ||
grantMap, | ||
grants | ||
); | ||
const grantHeaders = generateGrantHeaders< | ||
TampermonkeyHeaders, | ||
TampermonkeyGrantOptions | ||
>(grantMap, grants); | ||
|
||
const headers: HeaderEntries<TampermonkeyHeaders> = [ | ||
["author", formatAuthor(parsedAuthor)], | ||
["description", description], | ||
["homepage", homepage], | ||
...matchHeaders, | ||
...grantHeaders, | ||
["name", packageName], | ||
["source", source], | ||
["supportURL", supportURL], | ||
["version", version], | ||
]; | ||
const headers: HeaderEntries<TampermonkeyHeaders> = [ | ||
["author", formatAuthor(parsedAuthor)], | ||
["description", description], | ||
["homepage", homepage], | ||
...matchHeaders, | ||
...grantHeaders, | ||
["name", packageName], | ||
["source", source], | ||
["supportURL", supportURL], | ||
["version", version], | ||
]; | ||
|
||
if (scope) headers.push(["namespace", scope]); | ||
if (scope) headers.push(["namespace", scope]); | ||
|
||
if (icon) headers.push(["icon", icon]); | ||
if (icon) headers.push(["icon", icon]); | ||
|
||
if (contributors.length) { | ||
const formatted = contributors.map((contributor) => | ||
formatAuthor(parseAuthor(contributor)) | ||
); | ||
headers.push(["contributors", formatted.join(", ")]); | ||
} | ||
if (contributors.length) { | ||
const formatted = contributors.map((contributor) => | ||
formatAuthor(parseAuthor(contributor)) | ||
); | ||
headers.push(["contributors", formatted.join(", ")]); | ||
} | ||
|
||
//Unused headers: | ||
// @icon64 and @icon64URL | ||
// @updateURL | ||
// @downloadURL | ||
// @include | ||
// @exclude | ||
// @require | ||
// @resource | ||
// @connect | ||
// @run-at | ||
// @antifeature | ||
// @noframes | ||
// @unwrap | ||
// @nocompat | ||
//Unused headers: | ||
// @icon64 and @icon64URL | ||
// @updateURL | ||
// @downloadURL | ||
// @include | ||
// @exclude | ||
// @require | ||
// @resource | ||
// @connect | ||
// @run-at | ||
// @antifeature | ||
// @noframes | ||
// @unwrap | ||
// @nocompat | ||
|
||
return finalizeMonkeyHeaders(headers, spaces); | ||
}; | ||
return finalizeMonkeyHeaders(headers, spaces); | ||
}; |
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,9 +1,10 @@ | ||
import { HeaderEntries, HeaderGenerator } from ".."; | ||
import { CommonGrantOptions, HeaderEntries, HeaderGenerator } from ".."; | ||
import { finalizeMonkeyHeaders } from "../common/monkey"; | ||
import { ViolentMonkeyHeaders } from "./types"; | ||
|
||
//TODO: finish creating the processor | ||
export const generateViolentMonkeyHeaders: HeaderGenerator = ({}) => { | ||
const headers: HeaderEntries<ViolentMonkeyHeaders> = []; | ||
return finalizeMonkeyHeaders(headers, 4); | ||
}; | ||
export const generateViolentMonkeyHeaders: HeaderGenerator<CommonGrantOptions> = | ||
({}) => { | ||
const headers: HeaderEntries<ViolentMonkeyHeaders> = []; | ||
return finalizeMonkeyHeaders(headers, 4); | ||
}; |
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