在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:zotero/zotero-connectors开源软件地址:https://github.com/zotero/zotero-connectors开源编程语言:JavaScript 88.8%开源软件介绍:Zotero ConnectorsBuilding
The connectors are built in Running from the build directoryChrome
Firefox
OR
SafariSee https://github.com/zotero/safari-app-extension Automatic rebuilding/reloadingChrome on MacOS
As files are changed, the connectors will be rebuilt automatically and Chrome will reload the extension. Firefox
As files are changed, the connectors will be rebuilt automatically and Firefox will reload the extension. Others
As files are changed, the connectors will be rebuilt automatically. You will need to manually reload the extension in the browser being developed for. Requirements for packaging extensions from the command line
TestsTo run tests locally, build the extension with the -d flag, and then run
Test files are located at DevelopingZotero Connectors are built with standard tools, such as browser extension APIs, but the architecture is quite complex. This section is a short overview of some of the complexities, to make it more accessible for newcomers. TechnologiesChrome/Firefox Browser Extension FrameworkThe functionality exposed on Chrome and Firefox is provided by the Chrome extension framework, which has also been adopted by Firefox. See Chrome Extension docs and Firefox Extension docs for more information. Safari Extension FrameworkFor Safari specifics see https://github.com/zotero/safari-app-extension Zotero Translator FrameworkThe Connectors share code with Zotero desktop application, to support translation. A basic understanding of how translation works or at least the handlers it exposes in Zotero will be highly useful in understanding the codebase. ComponentsSaving resources to Zotero library is facilitated by two major components: the Zotero Connector running in the browser and either the Zotero client or zotero.org web api. The Zotero Connector itself is split into two components: code running on the webpage and a background process. a) Injected scripts for individual webpagesEach webpage is injected (Chrome/Firefox/Safari) with a full Zotero translation framework. A Zotero.Translate.Web instance orchestrates running individual translators for detection and translation. The translation framework shares some code with the Zotero codebase and provides custom classes concerning translator retrieval and item saving. These custom classes talk to the background process (b) of the Zotero Connector for functionality outside the translation framework, such as retrieving translator code and sending translated items either to Zotero (c) or zotero.org (d). b) Background processThe Connector runs a background process (Chrome/Firefox/Safari) which works as a middle-layer between the translation framework running in inject scripts (a) and Zotero (c) or zotero.org (d). The background process maintains a cache of translators and performs the initial translator detection using URL matching.
Translators whose target regexp matches the URL of a given webpage are then further tested by running The background process is also responsible for updating the extension UI, kicking off translations, storing and retrieving connector preferences and sending translated items to Zotero or zotero.org. Browser specific scripts are available for BrowserExt and Safari. c) Connector server in ZoteroWhen Zotero is open it runs a connector HTTP server on port 23119. The HTTP server API accommodates interactions between the Connectors and Zotero client. Calls to Zotero.Connector.callMethod(endpoint) in this codebase are translated to HTTP requests to the connector server. Note that Zotero cannot interact with the connectors on its own accord. All communication is Connector initiated. d) zotero.org APIWhen Zotero is not available item saving falls back to using zotero.org API. The interactions with zotero.org API are defined in api.js Message passingThe only way for the background extension process and injected scripts to communicate is using the message passing protocol provided by the browsers (Chrome/Firefox/Safari). Injected scripts often need to communicate to background scripts. To simplify these interactions, calls to functions in background scripts are monkey-patched in injected scripts. These calls are asynchronous and if a return value is required, it is provided either to a callback function as the last argument of the call or as a resolving value of a promise returned. messages.js contains the list of the monkey-patched methods. If the method value is false no response is expected, otherwise the calls provide a response. An optional pre-send processing on the background end and post-receive processing on the injected end is possible to treat values that cannot be sent as-is via the messaging protocol. The background process registers message listeners in messaging.js.
The injected scripts monkey-patch methods in messaging_injected.js(BrowserExt/Safari)
Build processThe build process combines files from the Zotero codebase, common files to all connectors and specific files for Chrome/Firefox/Safari connectors. At the moment the build process is awkward and uses a SH script and gulp procedures. This will be reconciled in the future to only use gulp.
ContactIf you have any questions about developing Zotero Connectors you can join the discussion in the zotero-dev mailing list. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论