-
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.
Merge pull request #13 from RaymondWJang/start-extension
Start extension!!!
- Loading branch information
Showing
15 changed files
with
7,417 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Notes for the Zotero Plugin | ||
|
||
## Plugin format | ||
|
||
Bootstrapped Zotero plugins in Zotero 7 require two components: | ||
|
||
- A WebExtension-style manifest.json file, as described above | ||
- A bootstrap.js file containing functions to handle various events: | ||
- Plugin lifecycle hooks | ||
- Window hooks | ||
|
||
## Hooks | ||
|
||
Plugin lifecycle hooks are modeled after the legacy Mozilla bootstrapped-extension framework: | ||
|
||
|
||
Plugin lifecycle hooks are passed two parameters: | ||
|
||
- An object with these properties: | ||
- id, the plugin id | ||
- version, the plugin version | ||
- rootURI, a string URL pointing to the plugin's files. For XPIs, this will be a jar:file:/// URL. This value will always end in a slash, so you can append a relative path to get a URL for a file bundled with your plugin (e.g., rootURI + 'style.css'). | ||
- A number representing the reason for the event, which can be checked against the following constants: APP_STARTUP, APP_SHUTDOWN, ADDON_ENABLE, ADDON_DISABLE, ADDON_INSTALL, ADDON_UNINSTALL, ADDON_UPGRADE, ADDON_DOWNGRADE | ||
|
||
Window hooks are passed one parameter: | ||
|
||
- An object with a window property containing the target window | ||
|
||
|
||
### `startup()` | ||
|
||
Any initialization unrelated to specific windows should be triggered by startup | ||
|
||
### `onMainWindowLoad()` | ||
|
||
(Zotero 7 only) | ||
|
||
On some platforms, the main window can be opened and closed multiple times during a Zotero session, so any window-related activities, such as modifying the main UI, adding menus, or binding shortcuts must be performed by onMainWindowLoad so that new main windows contain your changes. | ||
|
||
### `onMainWindowUnload()` | ||
|
||
(Zotero 7 only) | ||
|
||
You must then remove all references to a window or objects within it, cancel any timers, etc., when onMainWindowUnload is called, or else you'll risk creating a memory leak every time the window is closed. | ||
|
||
### `shutdown()` | ||
|
||
removal should be triggered by shutdown. | ||
|
||
DOM elements added to a window will be automatically destroyed when the window is closed, so you only need to remove those in shutdown(), which you can do by cycling through all windows: | ||
|
||
```js | ||
function shutdown() { | ||
var windows = Zotero.getMainWindows(); | ||
for (let win of windows) { | ||
win.document.getElementById('make-it-red-stylesheet')?.remove(); | ||
} | ||
} | ||
``` | ||
### `install()` | ||
### `uninstall()` | ||
## Features | ||
### Panes | ||
Zotero now includes a built-in function to register a preference pane. In your plugin's startup function: | ||
```js | ||
Zotero.PreferencePanes.register({ | ||
pluginID: '[email protected]', | ||
src: 'prefs.xhtml', | ||
scripts: ['prefs.js'], | ||
stylesheets: ['prefs.css'], | ||
}); | ||
``` | ||
See also: https://github.com/zotero/zotero/blob/main/chrome/content/zotero/xpcom/preferencePanes.js | ||
## References | ||
- https://www.zotero.org/support/dev/zotero_7_for_developers - the elusive description of what in the heck zotero plugins actually are | ||
- [preferencesPanes.js](https://github.com/zotero/zotero/blob/main/chrome/content/zotero/xpcom/preferencePanes.js) - settings for preferences panes |
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,296 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "tsconfig.json", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"eslint-plugin-import", | ||
"eslint-plugin-prefer-arrow", | ||
"@typescript-eslint", | ||
"@typescript-eslint/eslint-plugin" | ||
], | ||
"rules": { | ||
"@typescript-eslint/adjacent-overload-signatures": "error", | ||
"@typescript-eslint/array-type": [ | ||
"error", | ||
{ | ||
"default": "array" | ||
} | ||
], | ||
"@typescript-eslint/await-thenable": "error", | ||
"@typescript-eslint/ban-ts-comment": "warn", | ||
"@typescript-eslint/ban-types": [ | ||
"warn", | ||
{ | ||
"types": { | ||
"Object": { | ||
"message": "Avoid using the `Object` type. Did you mean `object`?" | ||
}, | ||
"Function": { | ||
"message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`." | ||
}, | ||
"Boolean": { | ||
"message": "Avoid using the `Boolean` type. Did you mean `boolean`?" | ||
}, | ||
"Number": { | ||
"message": "Avoid using the `Number` type. Did you mean `number`?" | ||
}, | ||
"String": { | ||
"message": "Avoid using the `String` type. Did you mean `string`?" | ||
}, | ||
"Symbol": { | ||
"message": "Avoid using the `Symbol` type. Did you mean `symbol`?" | ||
} | ||
} | ||
} | ||
], | ||
"@typescript-eslint/consistent-type-assertions": "error", | ||
"@typescript-eslint/dot-notation": "error", | ||
"@typescript-eslint/explicit-module-boundary-types": "warn", | ||
"@typescript-eslint/indent": [ | ||
"error", | ||
2 | ||
], | ||
"@typescript-eslint/member-delimiter-style": [ | ||
"error", | ||
{ | ||
"multiline": { | ||
"delimiter": "none", | ||
"requireLast": false | ||
}, | ||
"singleline": { | ||
"delimiter": "comma", | ||
"requireLast": false | ||
} | ||
} | ||
], | ||
"@typescript-eslint/member-ordering": "off", | ||
"@typescript-eslint/naming-convention": "off", | ||
"@typescript-eslint/no-array-constructor": "error", | ||
"@typescript-eslint/no-empty-function": "error", | ||
"@typescript-eslint/no-empty-interface": "error", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-extra-non-null-assertion": "error", | ||
"@typescript-eslint/no-extra-semi": "error", | ||
"@typescript-eslint/no-floating-promises": "error", | ||
"@typescript-eslint/no-for-in-array": "error", | ||
"@typescript-eslint/no-implied-eval": "off", | ||
"@typescript-eslint/no-inferrable-types": "error", | ||
"@typescript-eslint/no-misused-new": "error", | ||
"@typescript-eslint/no-misused-promises": "error", | ||
"@typescript-eslint/no-namespace": "error", | ||
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | ||
"@typescript-eslint/no-non-null-assertion": "warn", | ||
"@typescript-eslint/no-parameter-properties": "off", | ||
"@typescript-eslint/no-shadow": [ | ||
"error", | ||
{ | ||
"hoist": "all" | ||
} | ||
], | ||
"@typescript-eslint/no-this-alias": "error", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "error", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unsafe-return": "error", | ||
"@typescript-eslint/no-unused-expressions": "error", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_" | ||
} | ||
], | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/prefer-as-const": "error", | ||
"@typescript-eslint/prefer-for-of": "error", | ||
"@typescript-eslint/prefer-function-type": "error", | ||
"@typescript-eslint/prefer-namespace-keyword": "error", | ||
"@typescript-eslint/prefer-regexp-exec": "off", | ||
"@typescript-eslint/quotes": [ | ||
"error", | ||
"single", | ||
{ | ||
"avoidEscape": true | ||
} | ||
], | ||
"@typescript-eslint/require-await": "error", | ||
"@typescript-eslint/restrict-plus-operands": "error", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"@typescript-eslint/semi": [ | ||
"error", | ||
"never" | ||
], | ||
"@typescript-eslint/triple-slash-reference": [ | ||
"error", | ||
{ | ||
"path": "always", | ||
"types": "prefer-import", | ||
"lib": "always" | ||
} | ||
], | ||
"@typescript-eslint/unbound-method": "error", | ||
"@typescript-eslint/unified-signatures": "error", | ||
"arrow-body-style": "error", | ||
"arrow-parens": [ | ||
"error", | ||
"as-needed" | ||
], | ||
"brace-style": [ | ||
"error", | ||
"stroustrup", | ||
{ | ||
"allowSingleLine": true | ||
} | ||
], | ||
"comma-dangle": [ | ||
"error", | ||
{ | ||
"objects": "always-multiline", | ||
"arrays": "always-multiline", | ||
"functions": "never" | ||
} | ||
], | ||
"complexity": "off", | ||
"constructor-super": "error", | ||
"curly": [ | ||
"error", | ||
"multi-line" | ||
], | ||
"eol-last": "error", | ||
"eqeqeq": [ | ||
"error", | ||
"smart" | ||
], | ||
"guard-for-in": "error", | ||
"id-blacklist": [ | ||
"error", | ||
"any", | ||
"Number", | ||
"number", | ||
"String", | ||
"string", | ||
"Boolean", | ||
"boolean", | ||
"Undefined", | ||
"undefined" | ||
], | ||
"id-match": "error", | ||
"import/order": "off", | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"max-classes-per-file": "off", | ||
"max-len": [ | ||
"warn", | ||
{ | ||
"code": 240 | ||
} | ||
], | ||
"new-parens": "off", | ||
"no-array-constructor": "off", | ||
"no-bitwise": "error", | ||
"no-caller": "error", | ||
"no-cond-assign": "off", | ||
"no-console": "error", | ||
"no-debugger": "error", | ||
"no-empty": [ | ||
"error", | ||
{ | ||
"allowEmptyCatch": true | ||
} | ||
], | ||
"no-empty-function": "off", | ||
"no-eval": "error", | ||
"no-extra-semi": "off", | ||
"no-fallthrough": "off", | ||
"no-implied-eval": "off", | ||
"no-invalid-this": "off", | ||
"no-irregular-whitespace": "error", | ||
"no-magic-numbers": "off", | ||
"@typescript-eslint/no-magic-numbers": "off", | ||
"no-new-wrappers": "error", | ||
"no-redeclare": "error", | ||
"no-throw-literal": "error", | ||
"no-trailing-spaces": "error", | ||
"no-undef-init": "error", | ||
"no-underscore-dangle": [ | ||
"error", | ||
{ | ||
"allowAfterThis": true | ||
} | ||
], | ||
"no-unsafe-finally": "error", | ||
"no-unused-labels": "error", | ||
"no-unused-vars": "off", | ||
"no-var": "error", | ||
"object-shorthand": "error", | ||
"one-var": [ | ||
"off", | ||
"never" | ||
], | ||
"prefer-arrow/prefer-arrow-functions": [ | ||
"error", | ||
{ | ||
"allowStandaloneDeclarations": true | ||
} | ||
], | ||
"prefer-const": [ | ||
"error", | ||
{ | ||
"destructuring": "all" | ||
} | ||
], | ||
"prefer-object-spread": "error", | ||
"prefer-template": "error", | ||
"quote-props": [ | ||
"error", | ||
"as-needed" | ||
], | ||
"radix": "off", | ||
"require-await": "off", | ||
"space-before-function-paren": [ | ||
"error", | ||
{ | ||
"anonymous": "never", | ||
"named": "never", | ||
"asyncArrow": "always" | ||
} | ||
], | ||
"spaced-comment": [ | ||
"error", | ||
"always", | ||
{ | ||
"markers": [ | ||
"/" | ||
] | ||
} | ||
], | ||
"use-isnan": "error", | ||
"valid-typeof": "off", | ||
"yoda": "error", | ||
"@typescript-eslint/consistent-type-definitions": "off", | ||
"no-new-func": "off" | ||
}, | ||
"ignorePatterns": [ | ||
"webpack.config.ts", | ||
"util/*.ts", | ||
"minitests/*.ts", | ||
"content/minitests/*.ts" | ||
] | ||
} |
Oops, something went wrong.