Compare commits
	
		
			10 Commits
		
	
	
		
			b7615d8bf4
			...
			38a1e6718c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					38a1e6718c | ||
| 
						 | 
					6c7090422c | ||
| 
						 | 
					e91121ff1b | ||
| 
						 | 
					803cfa3b6b | ||
| 
						 | 
					7e0d13f105 | ||
| 
						 | 
					f32b7deb01 | ||
| 
						 | 
					05f0a9d5ec | ||
| 
						 | 
					c154923886 | ||
| 
						 | 
					742e9ca799 | ||
| 
						 | 
					c9ce1d9ea6 | 
							
								
								
									
										60
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								README.md
									
									
									
									
									
								
							@ -55,14 +55,13 @@ If you are using this repo, I recommended that you put the following badge on yo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- Event-driven, functional programming, under extensive skeleton;
 | 
					- Event-driven, functional programming, under extensive skeleton;
 | 
				
			||||||
- Simple and user-friendly, works out-of-the-box.
 | 
					- Simple and user-friendly, works out-of-the-box.
 | 
				
			||||||
- ⭐ [New!] Auto hot reload! Whenever the source code is modified, automatically compile and reload. [See here→](#auto-hot-reload)
 | 
					 | 
				
			||||||
- Abundant examples in `src/modules/examples.ts`, covering most of the commonly used APIs in plugins (using [zotero-plugin-toolkit](https://github.com/windingwind/zotero-plugin-toolkit));
 | 
					- Abundant examples in `src/modules/examples.ts`, covering most of the commonly used APIs in plugins (using [zotero-plugin-toolkit](https://github.com/windingwind/zotero-plugin-toolkit));
 | 
				
			||||||
- TypeScript support:
 | 
					- TypeScript support:
 | 
				
			||||||
  - Full type definition support for the whole Zotero project, which is written in JavaScript (using [zotero-types](https://github.com/windingwind/zotero-types));
 | 
					  - Full type definition support for the whole Zotero project, which is written in JavaScript (using [zotero-types](https://github.com/windingwind/zotero-types));
 | 
				
			||||||
  - Global variables and environment setup;
 | 
					  - Global variables and environment setup;
 | 
				
			||||||
- Plugin develop/build/release workflow:
 | 
					- Plugin develop/build/release workflow:
 | 
				
			||||||
 | 
					  - ⭐ [New!] Auto hot reload! Whenever the source code is modified, automatically compile and reload. [See here→](#auto-hot-reload)
 | 
				
			||||||
  - Automatically generate/update plugin id/version, update configrations, and set environment variables (`development` / `production`);
 | 
					  - Automatically generate/update plugin id/version, update configrations, and set environment variables (`development` / `production`);
 | 
				
			||||||
  - Automatically build and reload code in Zotero;
 | 
					 | 
				
			||||||
  - Automatically release to GitHub;
 | 
					  - Automatically release to GitHub;
 | 
				
			||||||
- Prettier and ES Lint integration.
 | 
					- Prettier and ES Lint integration.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -134,7 +133,7 @@ Activate with `Shift+P`.
 | 
				
			|||||||
### 0 Requirement
 | 
					### 0 Requirement
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. Install a beta version of Zotero: <https://www.zotero.org/support/beta_builds>
 | 
					1. Install a beta version of Zotero: <https://www.zotero.org/support/beta_builds>
 | 
				
			||||||
2. Install [Node.js](https://nodejs.org/en/) and [Git](https://git-scm.com/)
 | 
					2. Install [Node.js latest LTS version](https://nodejs.org/en/) and [Git](https://git-scm.com/)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!note]
 | 
					> [!note]
 | 
				
			||||||
> This guide assumes that you have an initial understanding of the basic structure and workings of the Zotero plugin. If you don't, please refer to the [documentation](https://www.zotero.org/support/dev/zotero_7_for_developers) and official plugin examples [Make It Red](https://github.com/zotero/make-it-red) first.
 | 
					> This guide assumes that you have an initial understanding of the basic structure and workings of the Zotero plugin. If you don't, please refer to the [documentation](https://www.zotero.org/support/dev/zotero_7_for_developers) and official plugin examples [Make It Red](https://github.com/zotero/make-it-red) first.
 | 
				
			||||||
@ -161,19 +160,26 @@ Activate with `Shift+P`.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
1. Modify the settings in `./package.json`, including:
 | 
					1. Modify the settings in `./package.json`, including:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ```json5
 | 
					   ```jsonc
 | 
				
			||||||
   {
 | 
					   {
 | 
				
			||||||
     version: "", // to 0.0.0
 | 
					     "version": "0.0.0",
 | 
				
			||||||
     author: "",
 | 
					     "description": "",
 | 
				
			||||||
     description: "",
 | 
					     "config": {
 | 
				
			||||||
     homepage: "",
 | 
					       "addonName": "", // name to be displayed in the plugin manager
 | 
				
			||||||
     config: {
 | 
					       "addonID": "", // ID to avoid conflict. IMPORTANT!
 | 
				
			||||||
       addonName: "", // name to be displayed in the plugin manager
 | 
					       "addonRef": "", // e.g. Element ID prefix
 | 
				
			||||||
       addonID: "", // ID to avoid conflict. IMPORTANT!
 | 
					       "addonInstance": "", // the plugin's root instance: Zotero.${addonInstance}
 | 
				
			||||||
       addonRef: "", // e.g. Element ID prefix
 | 
					       "prefsPrefix": "extensions.zotero.${addonRef}", // the prefix of prefs
 | 
				
			||||||
       addonInstance: "", // the plugin's root instance: Zotero.${addonInstance}
 | 
					 | 
				
			||||||
       prefsPrefix: "extensions.zotero.${addonRef}", // the prefix of prefs
 | 
					 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
 | 
					     "repository": {
 | 
				
			||||||
 | 
					       "type": "git",
 | 
				
			||||||
 | 
					       "url": "git+https://github.com/your-github-name/repo-name.git",
 | 
				
			||||||
 | 
					     },
 | 
				
			||||||
 | 
					     "author": "Your Name",
 | 
				
			||||||
 | 
					     "bugs": {
 | 
				
			||||||
 | 
					       "url": "https://github.com/your-github-name/repo-name/issues",
 | 
				
			||||||
 | 
					     },
 | 
				
			||||||
 | 
					     "homepage": "https://github.com/your-github-name/repo-name#readme",
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -206,9 +212,7 @@ Start development server with `npm start`, it will:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- Prebuild the plugin in development mode
 | 
					- Prebuild the plugin in development mode
 | 
				
			||||||
- Start Zotero with plugin loaded from `build/`
 | 
					- Start Zotero with plugin loaded from `build/`
 | 
				
			||||||
- Watch `src/**` and `addon/**`.
 | 
					- Watch `src/**` and `addon/**`, rebuild and reload plugin in Zotero when source code changed.
 | 
				
			||||||
  - If `src/**` changed, run esbuild and reload
 | 
					 | 
				
			||||||
  - If `addon/**` has changed, rebuild the plugin (in development mode) and reload
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Auto Hot Reload
 | 
					#### Auto Hot Reload
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -237,19 +241,21 @@ You can also:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### 4 Build
 | 
					### 4 Build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Run `npm run build` to build the plugin in production mode, and the xpi for installation and the built code is under `build` folder.
 | 
					Run `npm run build` to build the plugin in production mode. The build output will be located in the `.scaffold/build/` directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Steps of build:
 | 
					For detailed build steps, refer to the [zotero-plugin-scaffold documentation](https://northword.github.io/zotero-plugin-scaffold/build.html). In short, the process can be divided into the following steps:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Create/empty `build/`.
 | 
					- Create or clear the `build/` directory
 | 
				
			||||||
- Copy `addon/**` to `build/addon/**`
 | 
					- Copy `addon/**` to `.scaffold/build/addon/**`
 | 
				
			||||||
- Replace placeholders: use `replace-in-file` to replace keywords and configurations defined in `package.json` in non-build files (`xhtml`, `json`, et al.).
 | 
					- Replace placeholders: substitute keywords and configurations defined in `package.json`
 | 
				
			||||||
- Prepare locale files to [avoid conflict](https://www.zotero.org/support/dev/zotero_7_for_developers#avoiding_localization_conflicts)
 | 
					- Prepare localization files to avoid conflicts (see the [zotero_7_for_developers](https://www.zotero.org/support/dev/zotero_7_for_developers#avoiding_localization_conflicts) for more information):
 | 
				
			||||||
  - Rename `**/*.flt` to `**/${addonRef}-*.flt`
 | 
					  - Rename `**/*.flt` to `**/${addonRef}-*.flt`
 | 
				
			||||||
  - Prefix each fluent message with `addonRef-`
 | 
					  - Prefix each message with `addonRef-`
 | 
				
			||||||
- Use ESBuild to build `.ts` source code to `.js`, build `src/index.ts` to `./build/addon/content/scripts`.
 | 
					  - Generate type declaration files for FTL messages
 | 
				
			||||||
- (Production mode only) Zip the `./build/addon` to `./build/*.xpi`
 | 
					- Prepare preferences files: prefix preference keys with `package.json#prefsPrefix` and generate type declaration files for preferences
 | 
				
			||||||
- (Production mode only) Prepare `update.json` or `update-beta.json`
 | 
					- Use ESBuild to compile `.ts` source code to `.js`, building from `src/index.ts` to `.scaffold/build/addon/content/scripts`
 | 
				
			||||||
 | 
					- _(Production mode only)_ Compress the `.scaffold/build/addon` directory into `.scaffold/build/*.xpi`
 | 
				
			||||||
 | 
					- _(Production mode only)_ Prepare `update.json` or `update-beta.json`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!note]
 | 
					> [!note]
 | 
				
			||||||
>
 | 
					>
 | 
				
			||||||
 | 
				
			|||||||
@ -137,7 +137,7 @@ S'active avec `Shift+P`.
 | 
				
			|||||||
### 0. Pré-requis
 | 
					### 0. Pré-requis
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. Installez une version beta de Zotero: <https://www.zotero.org/support/beta_builds>
 | 
					1. Installez une version beta de Zotero: <https://www.zotero.org/support/beta_builds>
 | 
				
			||||||
2. Installez [Node.js](https://nodejs.org/en/) and [Git](https://git-scm.com/)
 | 
					2. Installez [Node.js latest LTS version](https://nodejs.org/en/) and [Git](https://git-scm.com/)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!NOTE]
 | 
					> [!NOTE]
 | 
				
			||||||
> Ce guide suppose que vous avez une compréhension initiale de la structure de base et du fonctionnement des extensiosn Zotero. Si ce n'est pas le cas, veuillez vous référer à la [documentation](https://www.zotero.org/support/dev/zotero_7_for_developers)et aux exemples officiels de l'extension [Make It Red](https://github.com/zotero/make-it-red) en premier lieu.
 | 
					> Ce guide suppose que vous avez une compréhension initiale de la structure de base et du fonctionnement des extensiosn Zotero. Si ce n'est pas le cas, veuillez vous référer à la [documentation](https://www.zotero.org/support/dev/zotero_7_for_developers)et aux exemples officiels de l'extension [Make It Red](https://github.com/zotero/make-it-red) en premier lieu.
 | 
				
			||||||
@ -164,19 +164,26 @@ S'active avec `Shift+P`.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
1. Modifier les paramètres dans `./package.json`, y compris :
 | 
					1. Modifier les paramètres dans `./package.json`, y compris :
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ```json5
 | 
					   ```jsonc
 | 
				
			||||||
   {
 | 
					   {
 | 
				
			||||||
     version: "", // to 0.0.0
 | 
					     "version": "0.0.0",
 | 
				
			||||||
     author: "",
 | 
					     "description": "",
 | 
				
			||||||
     description: "",
 | 
					     "config": {
 | 
				
			||||||
     homepage: "",
 | 
					       "addonName": "", // name to be displayed in the plugin manager
 | 
				
			||||||
     config: {
 | 
					       "addonID": "", // ID to avoid conflict. IMPORTANT!
 | 
				
			||||||
       addonName: "", // name to be displayed in the plugin manager
 | 
					       "addonRef": "", // e.g. Element ID prefix
 | 
				
			||||||
       addonID: "", // ID to avoid conflict. IMPORTANT!
 | 
					       "addonInstance": "", // the plugin's root instance: Zotero.${addonInstance}
 | 
				
			||||||
       addonRef: "", // e.g. Element ID prefix
 | 
					       "prefsPrefix": "extensions.zotero.${addonRef}", // the prefix of prefs
 | 
				
			||||||
       addonInstance: "", // the plugin's root instance: Zotero.${addonInstance}
 | 
					 | 
				
			||||||
       prefsPrefix: "extensions.zotero.${addonRef}", // the prefix of prefs
 | 
					 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
 | 
					     "repository": {
 | 
				
			||||||
 | 
					       "type": "git",
 | 
				
			||||||
 | 
					       "url": "git+https://github.com/your-github-name/repo-name.git",
 | 
				
			||||||
 | 
					     },
 | 
				
			||||||
 | 
					     "author": "Your Name",
 | 
				
			||||||
 | 
					     "bugs": {
 | 
				
			||||||
 | 
					       "url": "https://github.com/your-github-name/repo-name/issues",
 | 
				
			||||||
 | 
					     },
 | 
				
			||||||
 | 
					     "homepage": "https://github.com/your-github-name/repo-name#readme",
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -203,7 +210,7 @@ vim .env
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
   Si vous obtenez `npm ERR ! ERESOLVE unable to resolve dependency tree` avec `npm install`, qui est un bogue de dépendance en amont de typescript-eslint, utilisez la commande `npm i -f` pour l'installer.
 | 
					   Si vous obtenez `npm ERR ! ERESOLVE unable to resolve dependency tree` avec `npm install`, qui est un bogue de dépendance en amont de typescript-eslint, utilisez la commande `npm i -f` pour l'installer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 3. Codez !
 | 
					### 3. Codez
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Démarrez le serveur de développement avec `npm start`:
 | 
					Démarrez le serveur de développement avec `npm start`:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -248,7 +255,7 @@ Exécutez `npm run build` construire l'extension en mode production : t le xpi p
 | 
				
			|||||||
- Copiez `addon/**` dans `build/addon/**`.
 | 
					- Copiez `addon/**` dans `build/addon/**`.
 | 
				
			||||||
- Remplacez les espaces réservés : utilisez `replace-in-file` pour remplacer les mots-clés et les configurations définis dans `package.json` dans les fichiers non-construits (`xhtml`, `json`, et al.).
 | 
					- Remplacez les espaces réservés : utilisez `replace-in-file` pour remplacer les mots-clés et les configurations définis dans `package.json` dans les fichiers non-construits (`xhtml`, `json`, et al.).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Préparez les fichiers de locale pour [éviter les conflits] (https://www.zotero.org/support/dev/zotero_7_for_developers#avoiding_localization_conflicts)
 | 
					- Préparez les fichiers de locale pour [éviter les conflits](https://www.zotero.org/support/dev/zotero_7_for_developers#avoiding_localization_conflicts)
 | 
				
			||||||
- Renommer `**/*.flt` en `**/${addonRef}-*.flt`
 | 
					- Renommer `**/*.flt` en `**/${addonRef}-*.flt`
 | 
				
			||||||
- Préfixez chaque message fluent[TODO] avec `addonRef-`
 | 
					- Préfixez chaque message fluent[TODO] avec `addonRef-`
 | 
				
			||||||
- Utilisez ESBuild pour construire le code source `.ts` vers `.js`, construisez `src/index.ts` vers `./build/addon/content/scripts`.
 | 
					- Utilisez ESBuild pour construire le code source `.ts` vers `.js`, construisez `src/index.ts` vers `./build/addon/content/scripts`.
 | 
				
			||||||
@ -304,7 +311,7 @@ Lorsque la prochaine version normale sera mise à jour, `update.json` et `update
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### À propos des variables globales
 | 
					### À propos des variables globales
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> Voir aussi [`src/index.ts`] (https://github.com/windingwind/zotero-plugin-template/blob/main/src/index.ts)
 | 
					> Voir aussi [`src/index.ts`](https://github.com/windingwind/zotero-plugin-template/blob/main/src/index.ts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
L'extension 'bootstrappé' fonctionne dans un bac à sable, qui n'a pas de variables globales par défaut comme `Zotero` ou `window`, que nous avions l'habitude d'avoir en superposition dans la fenêtre d'environnement des extensions.
 | 
					L'extension 'bootstrappé' fonctionne dans un bac à sable, qui n'a pas de variables globales par défaut comme `Zotero` ou `window`, que nous avions l'habitude d'avoir en superposition dans la fenêtre d'environnement des extensions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
[](https://www.zotero.org)
 | 
					[](https://www.zotero.org)
 | 
				
			||||||
[](https://github.com/windingwind/zotero-plugin-template)
 | 
					[](https://github.com/windingwind/zotero-plugin-template)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
这是 [Zotero](https://www.zotero.org/) 的插件模板.
 | 
					这是 [Zotero](https://www.zotero.org/) 的插件模板。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[English](../README.md) | [简体中文](./README-zhCN.md) | [Français](./README-frFR.md)
 | 
					[English](../README.md) | [简体中文](./README-zhCN.md) | [Français](./README-frFR.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -18,7 +18,7 @@
 | 
				
			|||||||
  - [📌 Zotero 插件模板](https://github.com/windingwind/zotero-plugin-template) (即本仓库)
 | 
					  - [📌 Zotero 插件模板](https://github.com/windingwind/zotero-plugin-template) (即本仓库)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!tip]
 | 
					> [!tip]
 | 
				
			||||||
> 👁 Watch 本仓库,以及时收到修复或更新的通知.
 | 
					> 👁 Watch 本仓库,以及时收到修复或更新的通知。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 使用此模板构建的插件
 | 
					## 使用此模板构建的插件
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -41,10 +41,9 @@
 | 
				
			|||||||
[](https://github.com/MuiseDestiny/zotero-figure)
 | 
					[](https://github.com/MuiseDestiny/zotero-figure)
 | 
				
			||||||
[](https://github.com/l0o0/jasminum)
 | 
					[](https://github.com/l0o0/jasminum)
 | 
				
			||||||
[](https://github.com/lifan0127/ai-research-assistant)
 | 
					[](https://github.com/lifan0127/ai-research-assistant)
 | 
				
			||||||
 | 
					 | 
				
			||||||
[](https://github.com/daeh/zotero-markdb-connect)
 | 
					[](https://github.com/daeh/zotero-markdb-connect)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
如果你正在使用此库,我建议你将这个标志 ([](https://github.com/windingwind/zotero-plugin-template)) 放在 README 文件中:
 | 
					如果你正在使用此库,我建议你将这个标志 ([](https://github.com/windingwind/zotero-plugin-template)) 放在 README 文件中:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```md
 | 
					```md
 | 
				
			||||||
[](https://github.com/windingwind/zotero-plugin-template)
 | 
					[](https://github.com/windingwind/zotero-plugin-template)
 | 
				
			||||||
@ -54,36 +53,35 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- 事件驱动、函数式编程的可扩展框架;
 | 
					- 事件驱动、函数式编程的可扩展框架;
 | 
				
			||||||
- 简单易用,开箱即用;
 | 
					- 简单易用,开箱即用;
 | 
				
			||||||
- ⭐[新特性!]自动热重载!每当修改源码时,都会自动编译并重新加载插件;[详情请跳转→](#自动热重载)
 | 
					- `src/modules/examples.ts` 中有丰富的示例,涵盖了插件中常用的大部分 API (使用 [zotero-plugin-toolkit](https://github.com/windingwind/zotero-plugin-toolkit);
 | 
				
			||||||
- `src/modules/examples.ts` 中有丰富的示例,涵盖了插件中常用的大部分API (使用 [zotero-plugin-toolkit](https://github.com/windingwind/zotero-plugin-toolkit);
 | 
					- TypeScript 支持:
 | 
				
			||||||
- TypeScript 支持:
 | 
					 | 
				
			||||||
  - 为使用 JavaScript 编写的 Zotero 源码提供全面的类型定义支持 (使用 [zotero-types](https://github.com/windingwind/zotero-types));
 | 
					  - 为使用 JavaScript 编写的 Zotero 源码提供全面的类型定义支持 (使用 [zotero-types](https://github.com/windingwind/zotero-types));
 | 
				
			||||||
  - 全局变量和环境设置;
 | 
					  - 全局变量和环境设置;
 | 
				
			||||||
- 插件开发/构建/发布工作流:
 | 
					- 插件开发/构建/发布工作流:
 | 
				
			||||||
 | 
					  - ⭐自动热重载!每当修改源码时,都会自动编译并重新加载插件;
 | 
				
			||||||
  - 自动生成/更新插件版本、更新配置和设置环境变量 (`development`/`production`);
 | 
					  - 自动生成/更新插件版本、更新配置和设置环境变量 (`development`/`production`);
 | 
				
			||||||
  - 自动在 Zotero 中构建和重新加载代码;
 | 
					 | 
				
			||||||
  - 自动发布到 GitHub ;
 | 
					  - 自动发布到 GitHub ;
 | 
				
			||||||
- 集成 Prettier 和 ES Lint;
 | 
					- 集成 Prettier 和 ES Lint;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Examples 示例
 | 
					## Examples 示例
 | 
				
			||||||
 | 
					
 | 
				
			||||||
此库提供了 [zotero-plugin-toolkit](https://github.com/windingwind/zotero-plugin-toolkit) 中API的示例.
 | 
					此库提供了 [zotero-plugin-toolkit](https://github.com/windingwind/zotero-plugin-toolkit) 中 API 的示例。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
在 `src/examples.ts` 中搜索`@example` 查看示例. 这些示例在 `src/hooks.ts` 中调用演示.
 | 
					在 `src/examples.ts` 中搜索`@example` 查看示例。这些示例在 `src/hooks.ts` 中调用演示。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 基本示例(Basic Examples)
 | 
					### 基本示例 (Basic Examples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- registerNotifier
 | 
					- registerNotifier
 | 
				
			||||||
- registerPrefs, unregisterPrefs
 | 
					- registerPrefs, unregisterPrefs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 快捷键示例(Shortcut Keys Examples)
 | 
					### 快捷键示例 (Shortcut Keys Examples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- registerShortcuts
 | 
					- registerShortcuts
 | 
				
			||||||
- exampleShortcutLargerCallback
 | 
					- exampleShortcutLargerCallback
 | 
				
			||||||
- exampleShortcutSmallerCallback
 | 
					- exampleShortcutSmallerCallback
 | 
				
			||||||
- exampleShortcutConflictionCallback
 | 
					- exampleShortcutConflictionCallback
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### UI示例(UI Examples)
 | 
					### UI 示例 (UI Examples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -97,7 +95,7 @@
 | 
				
			|||||||
- registerLibraryTabPanel
 | 
					- registerLibraryTabPanel
 | 
				
			||||||
- registerReaderTabPanel
 | 
					- registerReaderTabPanel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 首选项面板示例(Preference Pane Examples)
 | 
					### 首选项面板示例 (Preference Pane Examples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -108,7 +106,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
详情参见 [`src/modules/preferenceScript.ts`](./src/modules/preferenceScript.ts)
 | 
					详情参见 [`src/modules/preferenceScript.ts`](./src/modules/preferenceScript.ts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 帮助示例(HelperExamples)
 | 
					### 帮助示例 (HelperExamples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -118,11 +116,11 @@
 | 
				
			|||||||
- progressWindowExample
 | 
					- progressWindowExample
 | 
				
			||||||
- vtableExample(See Preference Pane Examples)
 | 
					- vtableExample(See Preference Pane Examples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 指令行示例(PromptExamples)
 | 
					### 指令行示例 (PromptExamples)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Obsidian风格的指令输入模块,它通过接受文本来运行插件,并在弹出窗口中显示可选项.
 | 
					Obsidian 风格的指令输入模块,它通过接受文本来运行插件,并在弹出窗口中显示可选项。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
使用 `Shift+P` 激活.
 | 
					使用 `Shift+P` 激活。
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -133,59 +131,66 @@ Obsidian风格的指令输入模块,它通过接受文本来运行插件,并
 | 
				
			|||||||
### 0 环境要求
 | 
					### 0 环境要求
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 安装 [beta 版 Zotero](https://www.zotero.org/support/beta_builds)
 | 
					1. 安装 [beta 版 Zotero](https://www.zotero.org/support/beta_builds)
 | 
				
			||||||
2. 安装 [Node.js](https://nodejs.org/en/) 和 [Git](https://git-scm.com/)
 | 
					2. 安装 [Node.js 最新 LTS 版本](https://nodejs.org/zh-cn/download) 和 [Git](https://git-scm.com/)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!note]
 | 
					> [!note]
 | 
				
			||||||
> 本指南假定你已经对 Zotero 插件的基本结构和工作原理有初步的了解. 如果你还不了解,请先参考[官方文档](https://www.zotero.org/support/dev/zotero_7_for_developers) 和[官方插件样例 Make It Red](https://github.com/zotero/make-it-red)。
 | 
					> 本指南假定你已经对 Zotero 插件的基本结构和工作原理有初步的了解。如果你还不了解,请先参考[官方文档](https://www.zotero.org/support/dev/zotero_7_for_developers) 和[官方插件样例 Make It Red](https://github.com/zotero/make-it-red)。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 1 创建你的仓库(Create Your Repo)
 | 
					### 1 创建你的仓库 (Create Your Repo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 点击 `Use this template`;
 | 
					1. 点击 `Use this template`;
 | 
				
			||||||
2. 使用 `git clone` 克隆上一步生成的仓库;
 | 
					2. 使用 `git clone` 克隆上一步生成的仓库;
 | 
				
			||||||
   <details >
 | 
					   <details >
 | 
				
			||||||
   <summary>💡 从 GitHub Codespace 开始</summary>
 | 
					   <summary>💡 从 GitHub Codespace 开始</summary>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   _GitHub CodeSpace_ 使你可以直接开始开发而无需在本地下载代码/IDE/依赖.
 | 
					   _GitHub CodeSpace_ 使你可以直接开始开发而无需在本地下载代码/IDE/依赖。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   重复下列步骤,仅需三十秒即可开始构建你的第一个插件!
 | 
					   重复下列步骤,仅需三十秒即可开始构建你的第一个插件!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   - 点击首页 `Use this template` 按钮,随后点击 `Open in codespace`, 你需要登录你的 GitHub 账号.
 | 
					   - 点击首页 `Use this template` 按钮,随后点击 `Open in codespace`,你需要登录你的 GitHub 账号。
 | 
				
			||||||
   - 等待 codespace 加载.
 | 
					   - 等待 codespace 加载。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   </details>
 | 
					   </details>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
3. 进入项目文件夹;
 | 
					3. 进入项目文件夹;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 2 配置模板和开发环境(Config Template Settings and Enviroment)
 | 
					### 2 配置模板和开发环境 (Config Template Settings and Enviroment)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 修改 `./package.json` 中的设置,包括:
 | 
					1. 修改 `./package.json` 中的设置,包括:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ```json5
 | 
					   ```jsonc
 | 
				
			||||||
   {
 | 
					   {
 | 
				
			||||||
     version: "", // 修改为 0.0.0
 | 
					     "version": "", // 修改为 0.0.0
 | 
				
			||||||
     author: "",
 | 
					     "description": "",
 | 
				
			||||||
     description: "",
 | 
					     "config": {
 | 
				
			||||||
     homepage: "",
 | 
					       "addonName": "", // 插件名称
 | 
				
			||||||
     config: {
 | 
					       "addonID": "", // 插件 ID【重要:防止冲突】
 | 
				
			||||||
       addonName: "", // 插件名称
 | 
					       "addonRef": "", // 插件命名空间:元素前缀等
 | 
				
			||||||
       addonID: "", // 插件 ID 【重要:防止冲突】
 | 
					       "addonInstance": "", // 注册在 Zotero 根下的实例名
 | 
				
			||||||
       addonRef: "", // 插件命名空间:元素前缀等
 | 
					       "prefsPrefix": "extensions.zotero.${addonRef}", // 首选项的前缀
 | 
				
			||||||
       addonInstance: "", // 注册在 Zotero 根下的实例名
 | 
					 | 
				
			||||||
       prefsPrefix: "extensions.zotero.${addonRef}", // 首选项的前缀
 | 
					 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
 | 
					     "repository": {
 | 
				
			||||||
 | 
					       "type": "git",
 | 
				
			||||||
 | 
					       "url": "git+https://github.com/your-github-name/repo-name.git",
 | 
				
			||||||
 | 
					     },
 | 
				
			||||||
 | 
					     "author": "Your Name",
 | 
				
			||||||
 | 
					     "bugs": {
 | 
				
			||||||
 | 
					       "url": "https://github.com/your-github-name/repo-name/issues",
 | 
				
			||||||
 | 
					     },
 | 
				
			||||||
 | 
					     "homepage": "https://github.com/your-github-name/repo-name#readme",
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   > [!warning]
 | 
					   > [!warning]
 | 
				
			||||||
   > 注意设置 addonID 和 addonRef 以避免冲突.
 | 
					   > 注意设置 addonID 和 addonRef 以避免冲突。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   如果你需要在 GitHub 以外的地方托管你的 XPI 包,请修改 `zotero-plugin.config.ts` 中的 `updateURL` 和 `xpiDownloadLink`。
 | 
					   如果你需要在 GitHub 以外的地方托管你的 XPI 包,请修改 `zotero-plugin.config.ts` 中的 `updateURL` 和 `xpiDownloadLink`。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2. 复制 Zotero 启动配置,填入 Zotero 可执行文件路径和 profile 路径.
 | 
					2. 复制 Zotero 启动配置,填入 Zotero 可执行文件路径和 profile 路径。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   > (可选项) 创建开发用 profile 目录:
 | 
					   > (可选项) 创建开发用 profile 目录:
 | 
				
			||||||
   >
 | 
					   >
 | 
				
			||||||
   > 此操作仅需执行一次: 使用 `/path/to/zotero -p` 启动 Zotero,创建一个新的配置文件并用作开发配置文件。
 | 
					   > 此操作仅需执行一次:使用 `/path/to/zotero -p` 启动 Zotero,创建一个新的配置文件并用作开发配置文件。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ```sh
 | 
					   ```sh
 | 
				
			||||||
   cp .env.example .env
 | 
					   cp .env.example .env
 | 
				
			||||||
@ -196,7 +201,7 @@ Obsidian风格的指令输入模块,它通过接受文本来运行插件,并
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
3. 运行 `npm install` 以安装相关依赖
 | 
					3. 运行 `npm install` 以安装相关依赖
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   > 如果你使用 `pnpm` 作为包管理器,你需要添加 `public-hoist-pattern[]=*@types/bluebird*` 到`.npmrc`, 详情请查看 [zotero-types](https://github.com/windingwind/zotero-types?tab=readme-ov-file#usage) 的文档.
 | 
					   > 如果你使用 `pnpm` 作为包管理器,你需要添加 `public-hoist-pattern[]=*@types/bluebird*` 到`.npmrc`, 详情请查看 [zotero-types](https://github.com/windingwind/zotero-types?tab=readme-ov-file#usage) 的文档。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   如果你使用 `npm install` 的过程中遇到了 `npm ERR! ERESOLVE unable to resolve dependency tree` ,这是由于上游依赖 typescript-eslint 导致的错误,请使用 `npm i -f` 命令进行安装。
 | 
					   如果你使用 `npm install` 的过程中遇到了 `npm ERR! ERESOLVE unable to resolve dependency tree` ,这是由于上游依赖 typescript-eslint 导致的错误,请使用 `npm i -f` 命令进行安装。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -205,20 +210,18 @@ Obsidian风格的指令输入模块,它通过接受文本来运行插件,并
 | 
				
			|||||||
使用 `npm start` 启动开发服务器,它将:
 | 
					使用 `npm start` 启动开发服务器,它将:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 在开发模式下预构建插件
 | 
					- 在开发模式下预构建插件
 | 
				
			||||||
- 启动 Zotero ,并让其从 `build/` 中加载插件
 | 
					- 启动 Zotero,并让其从 `build/` 中加载插件
 | 
				
			||||||
- 打开开发者工具(devtool)
 | 
					- 打开开发者工具(devtool)
 | 
				
			||||||
- 监听 `src/**` 和 `addon/**`.
 | 
					- 监听 `src/**` 和 `addon/**`,当文件发生修改时,重新构建插件并且重新加载
 | 
				
			||||||
  - 如果 `src/**` 修改了,运行 esbuild 并且重新加载
 | 
					 | 
				
			||||||
  - 如果 `addon/**` 修改了,(在开发模式下)重新构建插件并且重新加载
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### 自动热重载
 | 
					#### 自动热重载
 | 
				
			||||||
 | 
					
 | 
				
			||||||
厌倦了无休止的重启吗?忘掉它,拥抱热加载!
 | 
					厌倦了无休止的重启吗?忘掉它,拥抱热加载!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 运行 `npm start`.
 | 
					1. 运行 `npm start`.
 | 
				
			||||||
2. 编码. (是的,就这么简单)
 | 
					2. 编码。(是的,就这么简单)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
当检测到 `src` 或 `addon` 中的文件修改时,插件将自动编译并重新加载.
 | 
					当检测到 `src` 或 `addon` 中的文件修改时,插件将自动编译并重新加载。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<details style="text-indent: 2em">
 | 
					<details style="text-indent: 2em">
 | 
				
			||||||
<summary>💡 将此功能添加到现有插件的步骤</summary>
 | 
					<summary>💡 将此功能添加到现有插件的步骤</summary>
 | 
				
			||||||
@ -229,38 +232,40 @@ Obsidian风格的指令输入模块,它通过接受文本来运行插件,并
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#### 调试代码
 | 
					#### 调试代码
 | 
				
			||||||
 | 
					
 | 
				
			||||||
你还可以:
 | 
					你还可以:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 在 Tools->Developer->Run Javascript 中测试代码片段;
 | 
					- 在 Tools->Developer->Run Javascript 中测试代码片段;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 使用 `Zotero.debug()` 调试输出. 在 Help->Debug Output Logging->View Output 查看输出;
 | 
					- 使用 `Zotero.debug()` 调试输出。在 Help->Debug Output Logging->View Output 查看输出;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 调试 UI. Zotero 建立在 Firefox XUL 框架之上. 使用 [XUL Explorer](https://udn.realityripple.com/docs/Archive/Mozilla/XUL_Explorer) 等软件调试 XUL UI.
 | 
					- 调试 UI. Zotero 建立在 Firefox XUL 框架之上。使用 [XUL Explorer](https://udn.realityripple.com/docs/Archive/Mozilla/XUL_Explorer) 等软件调试 XUL UI.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  > XUL 文档: <http://www.devdoc.net/web/developer.mozilla.org/en-US/docs/XUL.html>
 | 
					  > XUL 文档:<http://www.devdoc.net/web/developer.mozilla.org/en-US/docs/XUL.html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 4 构建插件
 | 
					### 4 构建插件
 | 
				
			||||||
 | 
					
 | 
				
			||||||
运行 `npm run build` 在生产模式下构建插件,构建的结果位于 `build/` 目录中.
 | 
					运行 `npm run build` 在生产模式下构建插件,构建的结果位于 `.scaffold/build/` 目录中。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
构建步骤:
 | 
					构建步骤文档可参阅 [zotero-plugin-scaffold](https://northword.github.io/zotero-plugin-scaffold/build.html)简单来说,可以分为以下几步:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 创建/清空 `build/`
 | 
					- 创建/清空 `build/`
 | 
				
			||||||
- 复制 `addon/**` 到 `build/addon/**`
 | 
					- 复制 `addon/**` 到 `.scaffold/build/addon/**`
 | 
				
			||||||
- 替换占位符:使用 `replace-in-file` 去替换在 `package.json` 中定义的关键字和配置 (`xhtml`、`.flt` 等)
 | 
					- 替换占位符:替换在 `package.json` 中定义的关键字和配置
 | 
				
			||||||
- 准备本地化文件以避免冲突,查看官方文档了解更多(<https://www.zotero.org/support/dev/zotero_7_for_developers#avoiding_localization_conflicts)>
 | 
					- 准备本地化文件以避免冲突,查看 [zotero_7_for_developers](https://www.zotero.org/support/dev/zotero_7_for_developers#avoiding_localization_conflicts) 了解更多
 | 
				
			||||||
  - 重命名`**/*.flt` 为 `**/${addonRef}-*.flt`
 | 
					  - 重命名`**/*.flt` 为 `**/${addonRef}-*.flt`
 | 
				
			||||||
  - 在每个消息前加上 `addonRef-`
 | 
					  - 在每个消息前加上 `addonRef-`
 | 
				
			||||||
- 使用 Esbuild 来将 `.ts` 源码构建为 `.js`,从 `src/index.ts` 构建到`./build/addon/content/scripts`
 | 
					  - 为 FTL 消息生成类型声明文件
 | 
				
			||||||
- (仅在生产模式下工作) 压缩 `./build/addon` 目录为 `./build/*.xpi`
 | 
					- 准备首选项文件,在首选项键前添加前缀 `package.json#prefsPrefix`,并为首选项生成类型声明文件
 | 
				
			||||||
 | 
					- 使用 ESBuild 来将 `.ts` 源码构建为 `.js`,从 `src/index.ts` 构建到`.scaffold/build/addon/content/scripts`
 | 
				
			||||||
 | 
					- (仅在生产模式下工作) 压缩 `.scaffold/build/addon` 目录为 `.scaffold/build/*.xpi`
 | 
				
			||||||
- (仅在生产模式下工作) 准备 `update.json` 或 `update-beta.json`
 | 
					- (仅在生产模式下工作) 准备 `update.json` 或 `update-beta.json`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!note]
 | 
					> [!note]
 | 
				
			||||||
>
 | 
					>
 | 
				
			||||||
> **Dev & prod 两者有什么区别?**
 | 
					> **Dev & prod 两者有什么区别?**
 | 
				
			||||||
>
 | 
					>
 | 
				
			||||||
> - 此环境变量存储在 `Zotero.${addonInstance}.data.env` 中,控制台输出在生产模式下被禁用.
 | 
					> - 此环境变量存储在 `Zotero.${addonInstance}.data.env` 中,控制台输出在生产模式下被禁用。
 | 
				
			||||||
> - 你可以根据此变量决定用户无法查看/使用的内容.
 | 
					> - 你可以根据此变量决定用户无法查看/使用的内容。
 | 
				
			||||||
> - 在生产模式下,构建脚本将自动打包插件并更新 `update.json`.
 | 
					> - 在生产模式下,构建脚本将自动打包插件并更新 `update.json`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 5 发布
 | 
					### 5 发布
 | 
				
			||||||
@ -274,38 +279,38 @@ npm run release
 | 
				
			|||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!note]
 | 
					> [!note]
 | 
				
			||||||
> 在此模板中,release-it 被配置为在本地更新版本号、提交并推送标签,随后 GitHub Action 将重新构建插件并将 XPI 发布到 GitHub Release.
 | 
					> 在此模板中,发布流程被配置为在本地更新版本号、提交并推送标签,随后 GitHub Action 将重新构建插件并将 XPI 发布到 GitHub Release。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### 关于预发布
 | 
					#### 关于预发布
 | 
				
			||||||
 | 
					
 | 
				
			||||||
该模板将 `prerelease` 定义为插件的测试版,当你在 release-it 中选择 `prerelease` 版本 (版本号中带有 `-` ),构建脚本将创建一个 `update-beta.json` 给预发布版本使用,这将确保常规版本的用户不会自动更新到测试版,只有手动下载并安装了测试版的用户才能自动更新到下一个测试版. 当下一个正式版本更新时,脚本将同步更新 `update.json` 和 `update-beta.json`,这将使正式版和测试版用户都可以更新到最新的正式版.
 | 
					该模板将 `prerelease` 定义为插件的测试版,当你在版本选择中选择 `prerelease` 版本 (版本号中带有 `-` ),构建脚本将创建一个 `update-beta.json` 给预发布版本使用,这将确保常规版本的用户不会自动更新到测试版,只有手动下载并安装了测试版的用户才能自动更新到下一个测试版。当下一个正式版本更新时,脚本将同步更新 `update.json` 和 `update-beta.json`,这将使正式版和测试版用户都可以更新到最新的正式版。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> [!warning]
 | 
					> [!warning]
 | 
				
			||||||
> 严格来说,区分 Zotero 6 和 Zotero 7 兼容的插件版本应该通过 `update.json` 的 `addons.__addonID__.updates[]` 中分别配置 `applications.zotero.strict_min_version`,这样 Zotero 才能正确识别,详情在 Zotero 7 开发文档(<https://www.zotero.org/support/dev/zotero_7_for_developers#updaterdf_updatesjson)获取>.
 | 
					> 严格来说,区分 Zotero 6 和 Zotero 7 兼容的插件版本应该通过 `update.json` 的 `addons.__addonID__.updates[]` 中分别配置 `applications.zotero.strict_min_version`,这样 Zotero 才能正确识别,详情请参阅 [Zotero 7 开发文档](https://www.zotero.org/support/dev/zotero_7_for_developers#updaterdf_updatesjson)。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Details 更多细节
 | 
					## Details 更多细节
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 关于Hooks(About Hooks)
 | 
					### 关于 Hooks(About Hooks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> 可以在 [`src/hooks.ts`](https://github.com/windingwind/zotero-plugin-template/blob/main/src/hooks.ts) 中查看更多
 | 
					> 可以在 [`src/hooks.ts`](https://github.com/windingwind/zotero-plugin-template/blob/main/src/hooks.ts) 中查看更多。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 当在 Zotero 中触发安装/启用/启动时,`bootstrap.js` > `startup` 被调用
 | 
					1. 当在 Zotero 中触发安装/启用/启动时,`bootstrap.js` > `startup` 被调用
 | 
				
			||||||
   - 等待 Zotero 就绪
 | 
					   - 等待 Zotero 就绪
 | 
				
			||||||
   - 加载 `index.js` (插件代码的主入口,从 `index.ts` 中构建)
 | 
					   - 加载 `index.js` (插件代码的主入口,从 `index.ts` 中构建)
 | 
				
			||||||
   - 如果是 Zotero 7 以上的版本则注册资源
 | 
					   - 如果是 Zotero 7 以上的版本则注册资源
 | 
				
			||||||
2. 主入口 `index.js` 中,插件对象被注入到 `Zotero` ,并且 `hooks.ts` > `onStartup` 被调用.
 | 
					2. 主入口 `index.js` 中,插件对象被注入到 `Zotero` ,并且 `hooks.ts` > `onStartup` 被调用。
 | 
				
			||||||
   - 初始化插件需要的资源,包括通知监听器、首选项面板和UI元素.
 | 
					   - 初始化插件需要的资源,包括通知监听器、首选项面板和 UI 元素。
 | 
				
			||||||
3. 当在 Zotero 中触发卸载/禁用时,`bootstrap.js` > `shutdown` 被调用.
 | 
					3. 当在 Zotero 中触发卸载/禁用时,`bootstrap.js` > `shutdown` 被调用。
 | 
				
			||||||
   - `events.ts` > `onShutdown` 被调用. 移除 UI 元素、首选项面板或插件创建的任何内容.
 | 
					   - `events.ts` > `onShutdown` 被调用。移除 UI 元素、首选项面板或插件创建的任何内容。
 | 
				
			||||||
   - 移除脚本并释放资源.
 | 
					   - 移除脚本并释放资源。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 关于全局变量(About Global Variables)
 | 
					### 关于全局变量 (About Global Variables)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> 可以在 [`src/index.ts`](https://github.com/windingwind/zotero-plugin-template/blob/main/src/index.ts)中查看更多
 | 
					> 可以在 [`src/index.ts`](https://github.com/windingwind/zotero-plugin-template/blob/main/src/index.ts)中查看更多
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bootstrap插件在沙盒中运行,但沙盒中没有默认的全局变量,例如 `Zotero` 或 `window` 等我们曾在overlay插件环境中使用的变量.
 | 
					bootstrap 插件在沙盒中运行,但沙盒中没有默认的全局变量,例如 `Zotero` 或 `window` 等我们曾在 overlay 插件环境中使用的变量。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
此模板将以下变量注册到全局范围:
 | 
					此模板将以下变量注册到全局范围:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```ts
 | 
					```ts
 | 
				
			||||||
Zotero, ZoteroPane, Zotero_Tabs, window, document, rootURI, ztoolkit, addon;
 | 
					Zotero, ZoteroPane, Zotero_Tabs, window, document, rootURI, ztoolkit, addon;
 | 
				
			||||||
@ -313,10 +318,10 @@ Zotero, ZoteroPane, Zotero_Tabs, window, document, rootURI, ztoolkit, addon;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### 创建元素 API(Create Elements API)
 | 
					### 创建元素 API(Create Elements API)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
插件模板为 bootstrap 插件提供了一些新的API. 我们有两个原因使用这些 API,而不是使用 `createElement/createElementNS`:
 | 
					插件模板为 bootstrap 插件提供了一些新的 API. 我们有两个原因使用这些 API,而不是使用 `createElement/createElementNS`:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 在 bootstrap 模式下,插件必须在推出(禁用或卸载)时清理所有 UI 元素,这非常麻烦. 使用 `createElement`,插件模板将维护这些元素. 仅仅在退出时 `unregisterAll` .
 | 
					- 在 bootstrap 模式下,插件必须在推出(禁用或卸载)时清理所有 UI 元素,这非常麻烦。使用 `createElement`,插件模板将维护这些元素。仅仅在退出时 `unregisterAll` .
 | 
				
			||||||
- Zotero 7 需要 createElement()/createElementNS() → createXULElement() 来表示其他的 XUL 元素,而 Zotero 6 并不支持 `createXULElement`. 类似于 React.createElement 的API `createElement` 检测 namespace(xul/html/svg) 并且自动创建元素,返回元素为对应的 TypeScript 元素类型.
 | 
					- Zotero 7 需要 createElement()/createElementNS() → createXULElement() 来表示其他的 XUL 元素,而 Zotero 6 并不支持 `createXULElement`. 类似于 React.createElement 的 API `createElement` 检测 namespace(xul/html/svg) 并且自动创建元素,返回元素为对应的 TypeScript 元素类型。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```ts
 | 
					```ts
 | 
				
			||||||
createElement(document, "div"); // returns HTMLDivElement
 | 
					createElement(document, "div"); // returns HTMLDivElement
 | 
				
			||||||
@ -326,23 +331,23 @@ createElement(document, "button", { namespace: "xul" }); // manually set namespa
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### 关于 Zotero API(About Zotero API)
 | 
					### 关于 Zotero API(About Zotero API)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Zotero 文档已过时且不完整,克隆 <https://github.com/zotero/zotero> 并全局搜索关键字.
 | 
					Zotero 文档已过时且不完整,克隆 <https://github.com/zotero/zotero> 并全局搜索关键字。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> ⭐[zotero-types](https://github.com/windingwind/zotero-types) 提供了最常用的 Zotero API,在默认情况下它被包含在此模板中. 你的 IDE 将为大多数的 API 提供提醒.
 | 
					> ⭐[zotero-types](https://github.com/windingwind/zotero-types) 提供了最常用的 Zotero API,在默认情况下它被包含在此模板中。你的 IDE 将为大多数的 API 提供提醒。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
猜你需要:查找所需 API的技巧
 | 
					猜你需要:查找所需 API 的技巧
 | 
				
			||||||
 | 
					
 | 
				
			||||||
在 `.xhtml`/`.flt` 文件中搜索 UI 标签,然后在 locale 文件中找到对应的键. ,然后在 `.js`/`.jsx` 文件中搜索此键.
 | 
					在 `.xhtml`/`.flt` 文件中搜索 UI 标签,然后在 locale 文件中找到对应的键。,然后在 `.js`/`.jsx` 文件中搜索此键。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 目录结构(Directory Structure)
 | 
					### 目录结构 (Directory Structure)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
本部分展示了模板的目录结构.
 | 
					本部分展示了模板的目录结构。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- 所有的 `.js/.ts` 代码都在 `./src`;
 | 
					- 所有的 `.js/.ts` 代码都在 `./src`;
 | 
				
			||||||
- 插件配置文件:`./addon/manifest.json`;
 | 
					- 插件配置文件:`./addon/manifest.json`;
 | 
				
			||||||
- UI 文件: `./addon/content/*.xhtml`.
 | 
					- UI 文件:`./addon/content/*.xhtml`.
 | 
				
			||||||
- 区域设置文件: `./addon/locale/**/*.flt`;
 | 
					- 区域设置文件:`./addon/locale/**/*.flt`;
 | 
				
			||||||
- 首选项文件: `./addon/prefs.js`;
 | 
					- 首选项文件:`./addon/prefs.js`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```shell
 | 
					```shell
 | 
				
			||||||
.
 | 
					.
 | 
				
			||||||
@ -401,6 +406,6 @@ Zotero 文档已过时且不完整,克隆 <https://github.com/zotero/zotero> 
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Disclaimer 免责声明
 | 
					## Disclaimer 免责声明
 | 
				
			||||||
 | 
					
 | 
				
			||||||
在 AGPL 下使用此代码. 不提供任何保证. 遵守你所在地区的法律!
 | 
					在 AGPL 下使用此代码。不提供任何保证。遵守你所在地区的法律!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
如果你想更改许可,请通过 <wyzlshx@foxmail.com> 与我联系.
 | 
					如果你想更改许可,请通过 <wyzlshx@foxmail.com> 与我联系。
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1149
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1149
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										12
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								package.json
									
									
									
									
									
								
							@ -30,17 +30,17 @@
 | 
				
			|||||||
    "update-deps": "npm update --save"
 | 
					    "update-deps": "npm update --save"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "zotero-plugin-toolkit": "^5.0.0-0"
 | 
					    "zotero-plugin-toolkit": "^5.0.0"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@eslint/js": "^9.25.1",
 | 
					    "@eslint/js": "^9.25.1",
 | 
				
			||||||
    "@types/node": "^22.14.1",
 | 
					    "@types/node": "^22.15.30",
 | 
				
			||||||
    "eslint": "^9.25.1",
 | 
					    "eslint": "^9.28.0",
 | 
				
			||||||
    "prettier": "^3.5.3",
 | 
					    "prettier": "^3.5.3",
 | 
				
			||||||
    "typescript": "^5.8.3",
 | 
					    "typescript": "^5.8.3",
 | 
				
			||||||
    "typescript-eslint": "^8.31.0",
 | 
					    "typescript-eslint": "^8.34.0",
 | 
				
			||||||
    "zotero-plugin-scaffold": "^0.5.0",
 | 
					    "zotero-plugin-scaffold": "^0.6.0",
 | 
				
			||||||
    "zotero-types": "^4.0.0-beta.3"
 | 
					    "zotero-types": "^4.0.3"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "prettier": {
 | 
					  "prettier": {
 | 
				
			||||||
    "printWidth": 80,
 | 
					    "printWidth": 80,
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
import { config } from "../../package.json";
 | 
					import { config } from "../../package.json";
 | 
				
			||||||
 | 
					import { FluentMessageId } from "../../typings/i10n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { initLocale, getString, getLocaleID };
 | 
					export { initLocale, getString, getLocaleID };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,10 +40,10 @@ function initLocale() {
 | 
				
			|||||||
 * getString("addon-dynamic-example", { args: { count: 2 } }); // I have 2 apples
 | 
					 * getString("addon-dynamic-example", { args: { count: 2 } }); // I have 2 apples
 | 
				
			||||||
 * ```
 | 
					 * ```
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function getString(localString: string): string;
 | 
					function getString(localString: FluentMessageId): string;
 | 
				
			||||||
function getString(localString: string, branch: string): string;
 | 
					function getString(localString: FluentMessageId, branch: string): string;
 | 
				
			||||||
function getString(
 | 
					function getString(
 | 
				
			||||||
  localeString: string,
 | 
					  localeString: FluentMessageId,
 | 
				
			||||||
  options: { branch?: string | undefined; args?: Record<string, unknown> },
 | 
					  options: { branch?: string | undefined; args?: Record<string, unknown> },
 | 
				
			||||||
): string;
 | 
					): string;
 | 
				
			||||||
function getString(...inputs: any[]) {
 | 
					function getString(...inputs: any[]) {
 | 
				
			||||||
@ -60,7 +61,7 @@ function getString(...inputs: any[]) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _getString(
 | 
					function _getString(
 | 
				
			||||||
  localeString: string,
 | 
					  localeString: FluentMessageId,
 | 
				
			||||||
  options: { branch?: string | undefined; args?: Record<string, unknown> } = {},
 | 
					  options: { branch?: string | undefined; args?: Record<string, unknown> } = {},
 | 
				
			||||||
): string {
 | 
					): string {
 | 
				
			||||||
  const localStringWithPrefix = `${config.addonRef}-${localeString}`;
 | 
					  const localStringWithPrefix = `${config.addonRef}-${localeString}`;
 | 
				
			||||||
@ -83,6 +84,6 @@ function _getString(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getLocaleID(id: string) {
 | 
					function getLocaleID(id: FluentMessageId) {
 | 
				
			||||||
  return `${config.addonRef}-${id}`;
 | 
					  return `${config.addonRef}-${id}`;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										26
									
								
								typings/i10n.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								typings/i10n.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					// Generated by zotero-plugin-scaffold
 | 
				
			||||||
 | 
					/* prettier-ignore */
 | 
				
			||||||
 | 
					/* eslint-disable */
 | 
				
			||||||
 | 
					// @ts-nocheck
 | 
				
			||||||
 | 
					export type FluentMessageId =
 | 
				
			||||||
 | 
					  | 'item-info-row-example-label'
 | 
				
			||||||
 | 
					  | 'item-section-example1-head-text'
 | 
				
			||||||
 | 
					  | 'item-section-example1-sidenav-tooltip'
 | 
				
			||||||
 | 
					  | 'item-section-example2-button-tooltip'
 | 
				
			||||||
 | 
					  | 'item-section-example2-head-text'
 | 
				
			||||||
 | 
					  | 'item-section-example2-sidenav-tooltip'
 | 
				
			||||||
 | 
					  | 'menuitem-filemenulabel'
 | 
				
			||||||
 | 
					  | 'menuitem-label'
 | 
				
			||||||
 | 
					  | 'menuitem-submenulabel'
 | 
				
			||||||
 | 
					  | 'menupopup-label'
 | 
				
			||||||
 | 
					  | 'pref-enable'
 | 
				
			||||||
 | 
					  | 'pref-help'
 | 
				
			||||||
 | 
					  | 'pref-input'
 | 
				
			||||||
 | 
					  | 'pref-title'
 | 
				
			||||||
 | 
					  | 'prefs-table-detail'
 | 
				
			||||||
 | 
					  | 'prefs-table-title'
 | 
				
			||||||
 | 
					  | 'prefs-title'
 | 
				
			||||||
 | 
					  | 'startup-begin'
 | 
				
			||||||
 | 
					  | 'startup-finish'
 | 
				
			||||||
 | 
					  | 'tabpanel-lib-tab-label'
 | 
				
			||||||
 | 
					  | 'tabpanel-reader-tab-label';
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user