Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] The same script code can work in 'run javascript', but doesn't work ideally in zotero action tag plugin #394

Closed
2 tasks done
xjtusjtu opened this issue Sep 29, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@xjtusjtu
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest Zotero and the latest plugin?

  • I have confirmed I'm using the latest Zotero and the latest plugin

Environment

  • OS: Windows 10
  • Zotero Version: 7.0.5
  • Plugin Version: 2.0.2

Describe the bug

My same code - inserting the specified content at the current note cursor - executes fine in run javascript (inserts the specified content once), but the script wrapped in the zotero action tags plugin, which executes (using shortcuts) inserts it twice. Could this be due to the better notes plugin, or the action tags plugin? (I'd like to raise an issue, but I don't know where to do it)

let localeditor;
switch (Zotero_Tabs.selectedType) {
    case "reader":
        localeditor = ZoteroContextPane.activeEditor;
        break;
    case "library":
        localeditor = ZoteroPane.itemPane._noteEditor;
        break;
    case "note":
        localeditor = Zotero.BetterNotes?.api.workspace
            .getWorkspaceByTabID()
            ?.querySelector("#BetterNotes-editor-main");
        break;
}
console.log(localeditor);
console.log(localeditor._item);
console.log(localeditor._item.isNote());
let currentItem = localeditor._item;
let noteID = currentItem.id; // 获取笔记的note ID
let noteContent = currentItem.getNote(); // 获取笔记的内容
const localeditor2 = Zotero.BetterNotes.api.editor.getEditorInstance(currentItem.id);

Zotero.BetterNotes.api.editor.insert(
    localeditor2,
    content = "xxxx",
    position = "cursor"
);

return `Note ID: ${noteID}, Note Content: ${noteContent}`;

image

Debug Output

Submit…

Clear

Submitted with Debug ID 📋

1727587436070 addons.webextension.jasminum@linxzh.com WARN Loading extension 'jasminum@linxzh.com': Reading manifest: Warning processing version: version must be a version string consisting of at most 4 integers of at most 9 digits without leading zeros, and separated with dots

1727587438214 addons.xpi-utils WARN disabling legacy extension zoteroupdateifs@redleafnew.me

1727587438214 addons.xpi-utils WARN disabling legacy extension zoteroif@qnscholar

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "TypeError: emptyListMessage is null" {file: "chrome://zotero/content/standalone/standalone.js" line: 687}]
ZoteroStandalone</this.updateAddonsPane/<@chrome://zotero/content/standalone/standalone.js:687:7

[JavaScript Error: "Passing a URI to Zotero.File.getContentsAsync() is deprecated -- use Zotero.HTTP.request() instead"]

[JavaScript Error: "Passing a URI to Zotero.File.getContentsAsync() is deprecated -- use Zotero.HTTP.request() instead"]

appName => Zotero, version => 7.0.5 (x64), os => Windows 10.0 19045, locale => en-US, extensions => Zotero Debug Bridge (53.0, extension), Jasminum (1.0.0-16, extension), Zotero Attanger (1.2.6, extension), Translate for Zotero (2.0.1, extension), Better Notes for Zotero (2.0.8, extension), Actions and Tags for Zotero (2.0.2, extension), Magic for Zotero (1.8.3, extension), Ethereal Reference (1.1.3, extension), Awesome GPT (1.2.6, extension), Ethereal Style (5.0.3, extension), Linter for Zotero (1.18.7, extension), Zotero Update IFs (0.95.6, extension, disabled), Zotero IF Pro Max (4.7.3, extension, disabled), Easier Citation (0.4.0, extension, disabled), Wandering File (0.2.8, extension, disabled), Tara (1.0.0-8, extension, disabled), MarkDB-Connect (0.1.1, extension, disabled), Del Item With Attachment (0.3.3, extension, disabled), Better BibTex for Zotero (6.7.238, extension, disabled), PDF Figure (0.2.4, extension, disabled)

Anything else?

No response

@xjtusjtu xjtusjtu added the bug Something isn't working label Sep 29, 2024
@xjtusjtu
Copy link
Author

经尝试,需要把代码放在 if (item) {...} 当中,但是仍然不清楚为什么不放在这里面就会重复执行。。。

@windingwind
Copy link
Owner

When selecting multiple items in the library, the action will be triggered once for all items (items=[...], item=undefined) and then one by one for each item (items=[], item=...). You can use the items variable to get the selected items array and avoid duplicate executions.

请仔细阅读文档

@windingwind windingwind closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2024
@xjtusjtu
Copy link
Author

感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants