From e1f1003318e63810e62513efd3a1efa97aa3fae5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 15 May 2024 05:24:23 -0400 Subject: [PATCH] Add Zotero.Item::numFileAttachments() --- chrome/content/zotero/xpcom/data/item.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index a3f3d94859..ff4facbb1b 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2461,6 +2461,20 @@ Zotero.Item.prototype.numAttachments = function (includeTrashed) { } +/** + * Returns the number of file attachments of an item + * + * @return + */ +Zotero.Item.prototype.numFileAttachments = function () { + this._requireData('childItems'); + return this.getAttachments() + .map(itemID => Zotero.Items.get(itemID)) + .filter(item => item.isFileAttachment()) + .length; +}; + + Zotero.Item.prototype.numNonHTMLFileAttachments = function () { this._requireData('childItems'); return this.getAttachments()