[Share] [Custom-Template] Run selected Better Notes template for current item #319
ramonmi
started this conversation in
Action Scripts
Replies: 3 comments 9 replies
-
/**
* Select the Better Notes template when triggering the shortcut.
* @author windingwind, ramonmi
* @usage Trigger with shortcuts
* @link https://github.com/windingwind/zotero-actions-tags/discussions/319
* @see https://github.com/windingwind/zotero-actions-tags/discussions/319
* @ref https://github.com/windingwind/zotero-better-notes/issues/1250
*/
if (!Zotero.BetterNotes?.api.note?.insert) {
return "[Custom-Template] Better Notes for Zotero > 1.1.4-21 is not installed or disabled.";
}
if (!item) { return; }
// Select template name from input
templateName = (await Zotero.BetterNotes.hooks.onShowTemplatePicker("pick"))[0]
templateContent = Zotero.BetterNotes.api.template.getTemplateText(templateName);
if (!templateContent) {
return "[Custom-Template] Template is invalid";
}
// Define refreshable template array
// change the array with your template names with refreshable content
// Hint: [item] or [text] mush be lower case!
const templateArray = ['[item]item_Academic_Vocabulary','[item]item_Extensive_Reading','[item]item_Flow_Notes','[item]item_Intensive_Reading','[item]item_Tag_Journal'];
// check if the template have refreshable content
if (templateName && templateArray.includes(templateName)) {
var refreshableTag = "refreshable-template";
}
const parentItem = Zotero.Items.getTopLevel([item])[0];
const noteItem = new Zotero.Item("note");
noteItem.libraryID = parentItem.libraryID;
noteItem.parentID = parentItem.id;
if (refreshableTag) {
noteItem.addTag(refreshableTag, 0);
}
await noteItem.saveTx();
let html = "";
html = await Zotero.BetterNotes.api.template.runItemTemplate(templateName, {
itemIds: [parentItem.id],
targetNoteId: noteItem.id,
});
await Zotero.BetterNotes.api.note.insert(
noteItem,
html,
-1,
);
return `[Custom-Template] Note ${noteItem.getNoteTitle()} is created on item ${item.getField("title")} from template ${templateName}`; |
Beta Was this translation helpful? Give feedback.
2 replies
-
直接复制进来不能用 请问是模版名字没有替换好吗 如何替换呢 |
Beta Was this translation helpful? Give feedback.
5 replies
-
发现其实是1.13最好用,因为创建之后肯定是需要打开的,能否进一步增加一个版本,默认创建后打开,不需要再选择yes了呢 |
Beta Was this translation helpful? Give feedback.
2 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
Event
None
Operation
Script
Data
Hint: The JS code in the first comment below (version edit date: 2025-1-8) is more recommended. i.e., #319 (comment)
Anything else
Beta Was this translation helpful? Give feedback.
All reactions