Compare commits

..

3 Commits

Author SHA1 Message Date
c51ca65751 Merge branch 'main' of git.zomo.dev:zomo/browser-scripts-builder into main 2022-06-10 21:59:10 -05:00
a10a35d662 built previous commit 2022-06-10 21:55:42 -05:00
85ff5851b5 added multilanguage support 2022-06-10 21:49:13 -05:00
6 changed files with 99 additions and 41 deletions

View File

@@ -71,15 +71,28 @@ ${Object.keys(meta)
: key;
key_str = key_str.padEnd(12, ' ');
if (typeof val === 'boolean') {
//bool
if (val)
return `// @${key_str}`;
}
else if (typeof val === 'string') {
//string
return `// @${key_str} ${val}`;
}
else if (Array.isArray(val)) {
//multiple
return val.map(v => `// @${key_str} ${v}`).join('\n');
}
else if (typeof val === 'object') {
//multilingual
let langs = val;
return Object.keys(langs)
.map(lang => {
let langStr = lang === 'default' ? '' : `:${lang}`;
return `// @${key_str}${langStr} ${langs[lang]}`;
})
.join('\n');
}
return '';
})
.filter(l => l.length)

View File

@@ -1 +1 @@
{"version":3,"file":"readmeta.js","sourceRoot":"","sources":["../src/readmeta.ts"],"names":[],"mappings":";;AAAA,2BAAwD;AACxD,mCAAkE;AAOlE,mBAAyB,IAAY;IACjC,IAAI,IAAI,GAAuB;QAC3B,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,UAAU;QACrB,KAAK,EAAE,EAAE;QACT,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,EAAE;QACf,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,EAAE;QACT,UAAU,EAAE,EAAE;QACd,WAAW,EAAE,IAAA,eAAO,EAAC,IAAI,CAAC;QAC1B,UAAU,EAAE,kBAAU;QACtB,WAAW,EAAE,eAAO;QACpB,MAAM,EAAE,KAAK;KAChB,CAAA;IAED,IAAI,QAAQ,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAC,IA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AAI,CAAC,EAAE,CAAA;gBACpD,CAAC,CAAC;qBACD,IAAI,CAAC,IAAI,CAAC,CAAA;aAClB;YAED,OAAO,EAAE,CAAA;QACb,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;aACrB,IAAI,CAAC,IAAI,CAAC;;CAEd;KACI,CAAA;AACL,CAAC;AApGD,4BAoGC"}

View File

@@ -1,18 +1,33 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema",
"$id": "https://git.zomo.dev/zomo/browser-scripts-builder/raw/branch/main/meta.schema.json",
"title": "UserScriptMeta",
"description": "UserScript metadata fields, from https://violentmonkey.github.io/api/metadata-block/",
"type": "object",
"properties": {
"$schema": {
"type": "string",
"description": "Read https://violentmonkey.github.io/api/metadata-block/ for more examples and information about metadata"
},
"name": {
"description": "Script Name",
"type": "string"
"description": "The name of the script, shown in script list and menus",
"type": ["string", "object"],
"properties": {
"default": {
"type": "string"
}
},
"additionalProperties": {
"type": "string"
},
"required": ["default"]
},
"namespace": {
"description": "Author namespace",
"description": "The combination of namespace and name is the unique identifier for a userscript",
"type": "string"
},
"match": {
"description": "",
"description": "Define rules to decide whether a script should be executed",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true,
@@ -21,7 +36,7 @@
}
},
"excludematch": {
"description": "",
"description": "Define rules to decide whether a script should be executed",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true,
@@ -30,19 +45,28 @@
}
},
"version": {
"description": "",
"description": "Version of the script, it can be used to check if a script has new versions",
"type": "string"
},
"description": {
"description": "",
"type": "string"
"description": "A brief summary to describe the script",
"type": ["string", "object"],
"properties": {
"default": {
"type": "string"
}
},
"additionalProperties": {
"type": "string"
},
"required": ["default"]
},
"icon": {
"description": "",
"description": "Specify an icon for the script",
"type": "string"
},
"require": {
"description": "",
"description": "Require another script to execute before the current one\n\nThe value is the URL to the required script, which may be relative to the URL the script is being installed from",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true,
@@ -51,7 +75,7 @@
}
},
"resource": {
"description": "",
"description": "Static resources that can be accessed in the script by GM_getResourceText and GM_getResourceURL\n\nThe value is composed of two parts, joined with one or more white spaces\n\nThe first part is the name of the resource, no white space is allowed in it\n\nThe second part is the URL to the resource, which may be relative to the URL the script is being installed from",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true,
@@ -60,16 +84,16 @@
}
},
"runat": {
"description": "",
"description": "Decide when the script will execute\n\ndocument-end: (default) The script executes when DOMContentLoaded is fired\n\ndocument-start: The script executes as soon as possible\n\ndocument-idle: The script executes after DOMContentLoaded is fired, ensuring other resources like images are loaded",
"type": "string",
"enum": ["document-start", "document-end", "document-idle"]
"enum": ["document-end", "document-idle", "document-start"]
},
"noframes": {
"description": "",
"description": "When present, the script will execute only in top level document, but not in nested frames",
"type": "boolean"
},
"grant": {
"description": "",
"description": "Specify which special APIs should be granted and can be used when the script executes\n\nIf nothing is present, \"none\" is assumed\n\nAny GM_ or GM. function used, including window.close and window.focus",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true,
@@ -78,26 +102,27 @@
}
},
"injectinto": {
"description": "",
"description": "Decide which context the script will be injected into\n\npage: Inject into context of the web page\nIn this mode, unsafeWindow refers to the window object, allowing the script to access JavaScript objects of the web page, just like normal page scripts can\n\ncontent: Inject into context of content scripts.\nIn this mode, unsafeWindow refers to the global object in content script. As a result, the script can access and modify the page's DOM, but cannot access JavaScript objects of the web page.\n\nauto: Try to inject into context of the web page. If blocked by CSP rules, inject as a content script.",
"type": "string",
"enum": ["page", "content", "auto"]
},
"downloadURL": {
"description": "",
"description": "The URL the script can be downloaded from",
"type": "string"
},
"supportURL": {
"description": "",
"description": "If supplied, the question mark icon in the user scripts list will link to this.",
"type": "string"
},
"homepageURL": {
"description": "",
"description": "If supplied, the home icon in the user scripts list will link to this.",
"type": "string"
},
"unwrap": {
"description": "",
"description": "If supplied, the script will be injected as is into the global scope of the page, i.e. without our standard wrapper like window.VMxxx=function(){...}.\n\nThe @grant key is ignored so the script won't have access to GM.* or GM_* API. ",
"type": "boolean"
}
},
"additionalProperties": false,
"required": ["name", "namespace", "version"]
}

10
pnpm-lock.yaml generated
View File

@@ -1,4 +1,4 @@
lockfileVersion: 5.3
lockfileVersion: 5.4
specifiers:
'@types/command-line-args': ^5.2.0
@@ -11,16 +11,16 @@ specifiers:
typescript: ^4.7.3
dependencies:
'@types/command-line-args': 5.2.0
command-line-args: 5.2.1
esbuild: 0.14.42
prettier: 2.6.2
typescript: 4.7.3
devDependencies:
'@types/command-line-args': 5.2.0
'@types/node': 17.0.40
'@types/prettier': 2.6.3
eslint: 8.17.0
prettier: 2.6.2
packages:
@@ -58,7 +58,7 @@ packages:
/@types/command-line-args/5.2.0:
resolution: {integrity: sha512-UuKzKpJJ/Ief6ufIaIzr3A/0XnluX7RvFgwkV89Yzvm77wCh1kFaFmqN8XEnGcN62EuHdedQjEMb8mYxFLGPyA==}
dev: false
dev: true
/@types/node/17.0.40:
resolution: {integrity: sha512-UXdBxNGqTMtm7hCwh9HtncFVLrXoqA3oJW30j6XWp5BH/wu3mVeaxo7cq5benFdBw34HB3XDT2TRPI7rXZ+mDg==}
@@ -721,7 +721,7 @@ packages:
resolution: {integrity: sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==}
engines: {node: '>=10.13.0'}
hasBin: true
dev: true
dev: false
/punycode/2.1.1:
resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==}

View File

@@ -80,11 +80,23 @@ ${(Object.keys(meta) as Array<keyof UserScriptMetaFull>)
key_str = key_str.padEnd(12, ' ')
if (typeof val === 'boolean') {
//bool
if (val) return `// @${key_str}`
} else if (typeof val === 'string') {
//string
return `// @${key_str} ${val}`
} else if (Array.isArray(val)) {
//multiple
return val.map(v => `// @${key_str} ${v}`).join('\n')
} else if (typeof val === 'object') {
//multilingual
let langs = val
return Object.keys(langs)
.map(lang => {
let langStr = lang === 'default' ? '' : `:${lang}`
return `// @${key_str}${langStr} ${langs[lang]}`
})
.join('\n')
}
return ''

View File

@@ -1,16 +1,24 @@
export type UserScriptMetaMultilingual =
| string
| {
default: string
[lang: string]: string
}
export type UserScriptMetaMultiple = string | string[]
export interface UserScriptMetaPartial {
name?: string
name?: UserScriptMetaMultilingual
namespace?: string
match?: string | string[]
excludematch?: string | string[]
match?: UserScriptMetaMultiple
excludematch?: UserScriptMetaMultiple
version?: string
description?: string
description?: UserScriptMetaMultilingual
icon?: string
require?: string | string[]
resource?: string | string[]
require?: UserScriptMetaMultiple
resource?: UserScriptMetaMultiple
runat?: 'document-start' | 'document-end' | 'document-idle' | ''
noframes?: boolean
grant?: string | string[]
grant?: UserScriptMetaMultiple
injectinto?: 'page' | 'content' | 'auto' | ''
downloadURL?: string
supportURL?: string
@@ -19,7 +27,7 @@ export interface UserScriptMetaPartial {
}
export interface UserScriptMeta extends UserScriptMetaPartial {
name: string
name: UserScriptMetaMultilingual
namespace: string
version: string
downloadURL: string
@@ -28,15 +36,15 @@ export interface UserScriptMeta extends UserScriptMetaPartial {
}
export interface UserScriptMetaFull extends UserScriptMeta {
match: string | string[]
excludematch: string | string[]
description: string
match: UserScriptMetaMultiple
excludematch: UserScriptMetaMultiple
description: UserScriptMetaMultilingual
icon: string
require: string | string[]
resource: string | string[]
require: UserScriptMetaMultiple
resource: UserScriptMetaMultiple
runat: 'document-start' | 'document-end' | 'document-idle' | ''
noframes: boolean
grant: string | string[]
grant: UserScriptMetaMultiple
injectinto: 'page' | 'content' | 'auto' | ''
unwrap: boolean
}