[Share] Trigger insertCitation
in the note editor
#346
inertia42
started this conversation in
Action Scripts
Replies: 2 comments 2 replies
-
Fixes to the original action:
/**
* Trigger `insertCitation` in the note editor
* @author inertia42 windingwind
* @usage
* @link https://github.com/windingwind/zotero-actions-tags/discussions/346
* @see https://github.com/windingwind/zotero-actions-tags/discussions/346
*/
// Replace with the corresponding tooltip text of the `Insert Citation` button
// const ButtonTitle = "插入引注";
const ButtonTitle = "Insert Citation";
// Skip if in items loop
if (item) return;
const document = require("document");
const ZoteroPane = require("ZoteroPane");
const ZoteroContextPane = require("ZoteroContextPane");
const Zotero_Tabs = require("Zotero_Tabs");
let editor;
switch (Zotero_Tabs.selectedType) {
case "reader":
editor = ZoteroContextPane.activeEditor;
break;
case "library":
editor = ZoteroPane.itemPane._noteEditor;
break;
case "note":
editor = Zotero.BetterNotes?.api.workspace
.getWorkspaceByTabID()
?.querySelector("#BetterNotes-editor-main");
break;
}
if (!editor) {
return `Not in the note editor!`;
}
const insertButton = editor._iframe.contentDocument.querySelector(
'button.toolbar-button[title="' + ButtonTitle + '"]',
);
insertButton?.click(); |
Beta Was this translation helpful? Give feedback.
2 replies
-
For anyone interested, it seems like Zotero is implementing a keyboard shortcut for inserting citation in note editor soon. Here is the commit from yesterday. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
To easily insert citations in the note editor, I implemented an action script that simulates clicking the
insertCitation
button.The version provided by windingwind in the comments is better.
Event
None
Operation
Script
Data
Anything else
However, this script still has a bug. When triggered, it inserts two
{citation}
tags, but only one of them becomes a citation format. When simulating a click using the same DOM element in the debugger, it works normally. I'm not sure if it's due to the note editor or the action plugin. Since I'm not familiar with JavaScript, and I couldn't spot any issues in the note editor's relevant code, I was wondering if anyone knows the reason for this behavior? Thank you very much!Beta Was this translation helpful? Give feedback.
All reactions