zotero-javascripts期刊大小写转为首字母大写
var items = ZoteroPane.getSelectedItems();
// 列出需要保持大写的特定期刊名称
var uppercaseJournals = ['ACS', 'RSC'];
// 列出需要保持小写的介词
var lowercaseWords = ['a', 'an', 'the', 'in', 'on', 'of', 'and', 'for', 'with', 'to'];
for (var i = 0; i < items.length; i++) {
var item = items[i];
var itemType = Zotero.ItemTypes.getName(item.itemTypeID);
if (itemType === 'journalArticle') {
var pubTitle = item.getField('publicationTitle');
// 分割标题为单词,并调整大小写
var formattedPubTitle = pubTitle.replace(/\b\w+/g, function(txt) {
if (uppercaseJournals.includes(txt.toUpperCase())) {
return txt.toUpperCase();
} else if (lowercaseWords.includes(txt.toLowerCase())) {
return txt.toLowerCase();
} else {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
});
item.setField('publicationTitle', formattedPubTitle);
await item.saveTx();
}
}
return "期刊名称大小写已调整完成(保持特定期刊名称大写,保持介词小写)。";
陈 林
2023年8月19日 上海 FDU
参考资料:
https://github.com/redleafnew/zotero-javascripts/blob/main/23copy-publication-title-to-journal-abbreviation.js
https://chat.openai.com