请问大家有没有方法实现脚本的顺序运行 #329
Unanswered
Phoebe-test
asked this question in
Q&A
Replies: 2 comments 10 replies
-
解决方案:将第二个 Action 写为函数,再延时触发环境
说明
Action 脚本 (Aciton Script)
// 先通过脚本调用插件 Linter (First call the plugin Linter via this script)
// 再延时调用插件 pdf-translate 翻译标题和摘要 (Then delayed call plugin pdf-translate translate title and summary via this script)
// link https://github.com/windingwind/zotero-actions-tags/discussions/329
// Action 中调用 Linter 方法 (Calling Plugin Linter via Action) https://github.com/northword/zotero-format-metadata/issues/189#issuecomment-2132715266
await Zotero.Linter.hooks.onLintInBatch("std", [item]); // 调用插件 Linter (Call the plugin Linter)
const translationResult = await new Promise((resolve) => {
setTimeout(() => {
resolve(trans());
}, 2000);
});
return translationResult; // 弹窗提示翻译结果 (Pop-up window for translation results)
// 将自动翻译标题和摘要的脚本写为函数 (Write scripts for automatic translation of titles and summaries as a function)
async function trans() {
// Translate item title and abstract automatically
// Wait for abstract to be filled before translating abstract
// author windingwind, PhoenixHwang, northword
// link https://github.com/windingwind/zotero-tag/discussions/107
// usage Event=Create Item
const Zotero = require("Zotero");
if (!Zotero.PDFTranslate) {
return "[Action:Translate Title and Abstract] Translate for Zotero is not installed or disabled.";
}
if (!item) {
return "[Action:Translate Title and Abstract] Target item is empty";
}
const skipLang = ["", "zh", "zh-CN"];
const lang = item.getField("language");
if (skipLang.includes(lang)) {
return "[Action:Translate Title and Abstract] Skip due to language"
}
const title = item.getField("title");
const abstract = item.getField("abstractNote");
const titleResult = (await Zotero.PDFTranslate.api.translate(title)).result;
Zotero.PDFTranslate.data.ztoolkit.ExtraField.setExtraField(item, "titleTranslation", titleResult);
let abstractResult = "";
if (abstract) {
abstractResult = (await Zotero.PDFTranslate.api.translate(abstract)).result;
Zotero.PDFTranslate.data.ztoolkit.ExtraField.setExtraField(item, "abstractTranslation", abstractResult);
} else {
const observerID = Zotero.Notifier.registerObserver({
notify: async (event, type, ids, extraData) => {
if (event === 'modify' && type === 'item' && ids.includes(item.id)) {
const newAbstract = item.getField('abstractNote');
if (newAbstract) {
abstractResult = (await Zotero.PDFTranslate.api.translate(newAbstract)).result;
Zotero.PDFTranslate.data.ztoolkit.ExtraField.setExtraField(item, "abstractTranslation", abstractResult);
Zotero.Notifier.unregisterObserver(observerID);
}
}
}
}, ['item']);
}
return `[Action:Translate Title and Abstract] successfully translate title and abstract.`;
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
最新版本支持action执行操作为顺序执行多个其他action |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
实现脚本的顺序运行
环境
详述:
新建条目后:
1. 通过 Action & Tags 运行 Linter 调整语言字段
2. 再运行 zotero-pdf-translate 翻译标题和摘要
以这篇文章为例
🙏🙏🙏感谢各位大佬!
Beta Was this translation helpful? Give feedback.
All reactions