zotero-javascripts文章題目大小寫轉(zhuǎn)為每個(gè)單詞首字母大寫-
zoteroPane = Zotero.getActiveZoteroPane();
items = zoteroPane.getSelectedItems();
var result = "";
// 列出常見的介詞
var prepositions = ["of", "in", "on", "and", "the", "with", "for", "to", "at", "by", "from"];
for (item of items) {
? ? var title = item.getField('title');
? ? result += " " + title + "\n";
? ??
? ? var new_title = title.replace(/\b\w+\b/g, function (word) {
? ? ? ? if (prepositions.includes(word.toLowerCase())) {
? ? ? ? ? ? return word.toLowerCase();
? ? ? ? } else {
? ? ? ? ? ? return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
? ? ? ? }
? ? });
? ??
? ? result += "-> " + new_title + "\n\n";
? ??
? ? // Do it at your own risk
? ? item.setField('title', new_title);
? ? await item.saveTx();
}
return result;
? ? ?? ?陳? 林?
2023年8月17日 上海 FDU
參考資料:
https://www.zotero.org/support/dev/client_coding/javascript_api
https://github.com/redleafnew/zotero-javascripts/blob/main/02change-the-item-title-to-sentence-case.js
https://chat.openai.com/