
























先复习QuickAdd的Capture、Template脚本的使用与撰写,再说明宏操作的3个步骤。
Capture: Admonition的两个版本
<%*
let selection = window.getSelection();
let choice = await tp.system.suggester(
[ "✏️ note", "📘 abstract", "ℹ️ info", "🔥 tip", "✅ success",
"❓ question", "⚠️ warning", "❌ fail", "🪲 bug", "📋 example",
"✍️ quote", "💡 comment", "😝 LOL" ],
[ 0,1,2,3,4,5,6,7,8,9,10,11,12 ]
);
const admonitions = [
["ad-note", "重点"], ["ad-abstract", "摘要"], ["ad-info", "信息"], ["ad-tip", "技巧"], ["ad-success", "完成"],
["ad-question", "问题"], ["ad-warning", "警告"], ["ad-fail", "失败"], ["ad-error", "错误"], ["ad-example", "范例"],
["ad-quote", "引用"], ["ad-comment", "建议"], ["ad-LOL", "好笑"]
];
admonition = admonitions[choice][0];
title = admonitions[choice][1];
const nl = String.fromCharCode(10);
choice = "```" + admonition + nl +
//"collapse: on" + nl +
"title: " + title + nl + selection + nl +
"```";
//tR += choice;
%>
<% choice %>js quickadd
//const selection = window.getSelection();
const selection = this.quickAddApi.utility.getSelectedText();
const aTexts = [ "✏️ note", "📘 abstract", "ℹ️ info", "🔥 tip", "✅ success",
"❓ question", "⚠️ warning", "❌ fail", "🪲 bug", "📋 example",
"✍️ quote", "💡 comment", "😝 LOL" ];
const aValues = [ "0", "1", "2" , "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" ];
let choice = await this.quickAddApi.suggester(aTexts, aValues);
//console.log("choice", choice);
const admonitions = [
["ad-note", "重点"], ["ad-abstract", "摘要"], ["ad-info", "信息"], ["ad-tip", "技巧"], ["ad-success", "完成"],
["ad-question", "问题"], ["ad-warning", "警告"], ["ad-fail", "失败"], ["ad-error", "错误"], ["ad-example", "范例"],
["ad-quote", "引用"], ["ad-comment", "建议"], ["ad-LOL", "好笑"]
];
admonition = admonitions[choice][0];
title = admonitions[choice][1];
// 在脚本里,换行符号和倒引号不要在字符串里使用,改用String.fromCharCode()才不会出现解析错误
const nl = String.fromCharCode(10);
const backQuotes = String.fromCharCode(96) + String.fromCharCode(96) + String.fromCharCode(96);
result = backQuotes + admonition + nl +
"title: " + title + nl + selection + nl + backQuotes;
return result;输入关键字以插入动态图片。
<%*
let keywords = await tp.system.prompt("随机图片:输入关键字(以 , 分隔)");
keywords = keywords.replace(/ /g, "");
//console.log("keywords", keywords);
%>
<% tp.web.random_picture("1600x900", keywords) %>将编码后的网址转换回正常网址。
```js quickadd
selObj = window.getSelection();
text = selObj.toString();
//await this.quickAddApi.utility.getClipboard();
text = await decodeURIComponent(text)
this.quickAddApi.utility.setClipboard(text);
//console.log("main " + text);
return text;
```
以每日笔记为范例(使用Templater、Tasks插件),介绍如何输出条件式内容。
宏操作由三个步骤组成:
在文件总管里保存库任何文件夹添加脚本档,如:my_script.js
async function notice1(params) {
//({ quickAddApi } = params);
//const quickAddApi = params.quickAddApi;
const text = await params.quickAddApi.inputPrompt("随意输入文本...");
new Notice(text, 5000);
return text;
}
async function notice2(params) {
//({ quickAddApi } = params);
//const quickAddApi = params.quickAddApi;
const text = await params.quickAddApi.inputPrompt("随意输入文本2...");
new Notice(text, 5000);
return text;
}
module.exports = { notice1,notice2 };
在Capture format字段输入如下内容,会弹出窗口以选择要用那个函数:
{{MACRO:macro_notice}}直接使用指定的函数,此写法似乎会影响Templater的动态命令:
{{MACRO:macro_notice::notice2}}##
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。