Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Sep 15, 2023
0 parents commit 5b632b3
Show file tree
Hide file tree
Showing 32 changed files with 2,204 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"env": {
"browser": true,
"es2021": true
},
"root": true,
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"sort-imports": [
"off",
{
"ignoreCase": true
}
],
"@typescript-eslint/ban-ts-comment": [
"warn",
{
"ts-expect-error": "allow-with-description",
"ts-ignore": "allow-with-description",
"ts-nocheck": "allow-with-description",
"ts-check": "allow-with-description"
}
],
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off"
},
"ignorePatterns": [
"**/build/**",
"**/node_modules/**",
"scripts/**",
"dist/**",
"src/libs/**",
"**/**/*.js",
"**/abbrevIso*",
"**/example*",
"**/*.bak",
"!.vuepress/**",
"**/.vuepress/.cache/**",
"**/.vuepress/.temp/**"
]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/build
node_modules
package-lock.json
zotero-cmd.json
15 changes: 15 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**/build
node_modules
package-lock.json
# zotero-cmd.json

# libs
src/libs/**

# tmp
**/*.bak
**/*.new
**/examples.ts
**/abbrevIso*
**/data*
*.html
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 4,
"printWidth": 120
}
14 changes: 14 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"npm": {
"publish": false
},
"github": {
"release": true,
"assets": ["build/*.xpi"]
},
"hooks": {
"before:init": " npm:lint",
"after:bump": "npm run build",
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
}
}
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Zotero Ciation

![Reference](addon/chrome/content/icons/favicon.png)

[![Using Zotero Plugin Template](https://img.shields.io/badge/Using-Zotero%20Plugin%20Template-blue?style=flat-round&logo=github)](https://github.com/windingwind/zotero-plugin-template)
[![Latest release](https://img.shields.io/github/v/release/MuiseDestiny/zotero-citation)](https://github.com/MuiseDestiny/zotero-citation/releases)
![Release Date](https://img.shields.io/github/release-date/MuiseDestiny/zotero-citation?color=9cf)
[![License](https://img.shields.io/github/license/MuiseDestiny/zotero-citation)](https://github.com/MuiseDestiny/zotero-citation/blob/master/LICENSE)
![Downloads latest release](https://img.shields.io/github/downloads/MuiseDestiny/zotero-citation/latest/total?color=yellow)

🤝 Zotero 里的 Word 插件要和 Word 中的加载项版本保持一致,如果提示整合错误可以卸载 Word 里的加载项重装。

🎈 插件对 Windows 全功能支持,Mac不支持临时文件夹自动改名,可能需要手动更改。

🪐 你需要在 Word 里点一次刷新,插件在 Zotero 生成的文件夹才能被重命名为你打开的 Word 的文件名。

⌛ 插件生成的文件夹生命周期为:[在 Word 里插入第一条引用,关闭Zotero];每次打开 Word 都会重新生成这个文件夹。

🎉 使用插件提供的引用,相邻引用自动合并,如在 [1] 后面插入新的文献,会变成 [1, 2],而非 [1][2]

⭐ 这是一个完全基于用户角度开发的插件,觉得好用,欢迎Star。

---

## 功能

### 1. 引用归类

> 将 Word 中的引文整理到 Zotero,并创建引用列
<details>
<summary>演示</summary>

![image](https://user-images.githubusercontent.com/51939531/218295007-d603f9b8-3147-4cd6-9e7e-c75351889d84.png)

</details>

当你在 Word 中插入参考文献时,自动将打开的 Word 的所有引用整理到一个文件夹下。

如果你用过 EndNote,相信你很熟悉这个功能。

这个文件夹是临时的,关闭 Zotero 后会自动删除(如果自动删除失败,下次打开时可手动删除)。

### 2. 快捷引用条目到 Word

#### 2.1 快捷键引用

> 在 Word 中将光标定位到待插入引用的位置,在 Zotero 中选择条目后按键盘上的 `'` 键。
<details>
<summary>演示</summary>

![cite-item-by-quote-key](https://user-images.githubusercontent.com/44738481/215477177-c0a58567-a5e4-410c-a8d4-c1207fab02b0.gif)

</details>

#### 2.2 拖拽引用

> 在 Zotero 中拖拽(鼠标按下)待引用的条目(可多选)拖拽到 Word 中需要添加引用的位置(松开鼠标)。
**需要开启引用列才可以使用,反之若想禁用拖拽引用,关闭引用列即可**

<details>
<summary>演示</summary>

![cite-item-by-drag](https://user-images.githubusercontent.com/51939531/220587000-ce2842cd-8ec5-4f8a-92f3-f78662abb6be.gif)

</details>

## TODO

- [x] Word 引文序号如,[1] 在 Zotero 里标注
- [x] 适配 Mac 用户快捷引用,目前版本 Mac 用户只能使用功能 1

## 致谢

- 本插件基于 [模板](https://github.com/MuiseDestiny/zotero-addon-template)
- 在此特别感谢 `@鑫鑫胖胖``@小明同学classic` 二位同学主动联系我提供Mac设备远程调试适配 Mac

## 赞助

[这里](https://github.com/MuiseDestiny/zotero-reference#%E8%B5%9E%E5%8A%A9)
146 changes: 146 additions & 0 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* Most of this code is from Zotero team's official Make It Red example[1]
* or the Zotero 7 documentation[2].
* [1] https://github.com/zotero/make-it-red
* [2] https://www.zotero.org/support/dev/zotero_7_for_developers
*/

if (typeof Zotero == "undefined") {
var Zotero;
}

var chromeHandle;

// In Zotero 6, bootstrap methods are called before Zotero is initialized, and using include.js
// to get the Zotero XPCOM service would risk breaking Zotero startup. Instead, wait for the main
// Zotero window to open and get the Zotero object from there.
//
// In Zotero 7, bootstrap methods are not called until Zotero is initialized, and the 'Zotero' is
// automatically made available.
async function waitForZotero() {
if (typeof Zotero != "undefined") {
await Zotero.initializationPromise;
}

var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var windows = Services.wm.getEnumerator("navigator:browser");
var found = false;
while (windows.hasMoreElements()) {
let win = windows.getNext();
if (win.Zotero) {
Zotero = win.Zotero;
found = true;
break;
}
}
if (!found) {
await new Promise((resolve) => {
var listener = {
onOpenWindow: function (aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
domWindow.addEventListener(
"load",
function () {
domWindow.removeEventListener("load", arguments.callee, false);
if (domWindow.Zotero) {
Services.wm.removeListener(listener);
Zotero = domWindow.Zotero;
resolve();
}
},
false,
);
},
};
Services.wm.addListener(listener);
});
}
await Zotero.initializationPromise;
}

function install(data, reason) {}

async function startup({ id, version, resourceURI, rootURI }, reason) {
await waitForZotero();

// String 'rootURI' introduced in Zotero 7
if (!rootURI) {
rootURI = resourceURI.spec;
}

var aomStartup = Components.classes["@mozilla.org/addons/addon-manager-startup;1"].getService(
Components.interfaces.amIAddonManagerStartup,
);
var manifestURI = Services.io.newURI(rootURI + "manifest.json");
chromeHandle = aomStartup.registerChrome(manifestURI, [
["content", "__addonRef__", rootURI + "chrome/content/"],
["locale", "__addonRef__", "en-US", rootURI + "chrome/locale/en-US/"],
["locale", "__addonRef__", "zh-CN", rootURI + "chrome/locale/zh-CN/"],
]);

/**
* Global variables for plugin code.
* The `_globalThis` is the global root variable of the plugin sandbox environment
* and all child variables assigned to it is globally accessible.
* See `src/index.ts` for details.
*/
const ctx = {
rootURI,
};
ctx._globalThis = ctx;

Services.scriptloader.loadSubScript(`${rootURI}/chrome/content/scripts/index.js`, ctx);
}

function shutdown({ id, version, resourceURI, rootURI }, reason) {
if (reason === APP_SHUTDOWN) {
return;
}
if (reason == ADDON_DISABLE) {
Services.obs.notifyObservers(null, "startupcache-invalidate", null);
}
if (typeof Zotero === "undefined") {
Zotero = Components.classes["@zotero.org/Zotero;1"].getService(
Components.interfaces.nsISupports,
).wrappedJSObject;
}
Zotero.__addonInstance__.hooks.onShutdown();

Cc["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService).flushBundles();

Cu.unload(`${rootURI}/chrome/content/scripts/index.js`);

if (chromeHandle) {
chromeHandle.destruct();
chromeHandle = null;
}
}

function uninstall(data, reason) {}

// Loads default preferences from defaults/preferences/prefs.js in Zotero 6
function setDefaultPrefs(rootURI) {
var branch = Services.prefs.getDefaultBranch("");
var obj = {
pref(pref, value) {
switch (typeof value) {
case "boolean":
branch.setBoolPref(pref, value);
break;
case "string":
branch.setStringPref(pref, value);
break;
case "number":
branch.setIntPref(pref, value);
break;
default:
Zotero.logError(`Invalid type '${typeof value}' for pref '${pref}'`);
}
},
};
Zotero.getMainWindow().console.log(rootURI + "prefs.js");
Services.scriptloader.loadSubScript(rootURI + "prefs.js", obj);
}
Binary file added addon/chrome/content/icons/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added addon/chrome/content/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added addon/chrome/content/icons/word.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
column-citation=Citation
1 change: 1 addition & 0 deletions addon/locale/zh-CN/addon.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
column-citation=引用
20 changes: 20 additions & 0 deletions addon/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"manifest_version": 2,
"name": "__addonName__",
"version": "__buildVersion__",
"description": "__description__",
"homepage_url": "__homepage__",
"author": "__author__",
"icons": {
"48": "chrome/content/icons/[email protected]",
"96": "chrome/content/icons/favicon.png"
},
"applications": {
"zotero": {
"id": "__addonID__",
"update_url": "__updaterdf__",
"strict_min_version": "6.999",
"strict_max_version": "7.0.*"
}
}
}
1 change: 1 addition & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pref("extensions.zotero.__addonRef__.enable", true);
Loading

0 comments on commit 5b632b3

Please sign in to comment.