From 59612916d3c4235201dbfb41e281c0f4df692c76 Mon Sep 17 00:00:00 2001 From: redleafnew Date: Sun, 25 Apr 2021 18:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=B8=BA0.0.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome/content/scripts/delitem.js | 96 ++++++++++++++++++++++++++++++- chrome/locale/zh-CN/overlay.dtd | 2 +- install.rdf | 2 +- update.rdf | 6 +- 4 files changed, 99 insertions(+), 7 deletions(-) diff --git a/chrome/content/scripts/delitem.js b/chrome/content/scripts/delitem.js index 8d88bf5..b7dc01a 100644 --- a/chrome/content/scripts/delitem.js +++ b/chrome/content/scripts/delitem.js @@ -139,5 +139,97 @@ Zotero.DelItem = { } //2 if } ; - } -} \ No newline at end of file + }, + + // 检查附件是否存在函数 + checkItemAtt: function (item) { + if (item && !item.isNote()) { + if (item.isRegularItem()) { // not an attachment already + let attachmentIDs = item.getAttachments(); + for (let id of attachmentIDs) { + let attachment = Zotero.Items.get(id); + var attType = attachment.attachmentContentType; + } + } + if (item.isAttachment()) { + var attType = item.attachmentContentType; + } + } + + + if (attType != undefined ) { + return true;} else { + return false;} + }, + + // 检查快照是否存在函数 + checkItemSnap: function (item) { + if (item && !item.isNote()) { + if (item.isRegularItem()) { // not an attachment already + let attachmentIDs = item.getAttachments(); + for (let id of attachmentIDs) { + let attachment = Zotero.Items.get(id); + var attType = attachment.attachmentContentType; + } + } + if (item.isAttachment()) { + var attType = item.attachmentContentType; + } + } + + + if (attType == 'text/html' ) { + return true;} else { + return false;} + }, + + // 是否显示菜单函数 + displayMenuitem: function () { // 如果无附件则不显示菜单 + var pane = Services.wm.getMostRecentWindow("navigator:browser") + .ZoteroPane; + var items = pane.getSelectedItems(); + //Zotero.debug("**Jasminum selected item length: " + items.length); + var showMenuAtt = items.some((item) => Zotero.DelItem.checkItemAtt(item)); // 检查附件 + var showMenuSnap = items.some((item) => Zotero.DelItem.checkItemSnap(item)); // 检查快照 + + //pane.document.getElementById("id-delitem-separator").hidden = !( // 分隔条是否出现 + // showMenuAtt || + // showMenuSnap); + + pane.document.getElementById( //总菜单 + "zotero-itemmenu-delitem-namehandler" + ).disabled = !( // 总菜单是否可用 + showMenuAtt || + showMenuSnap); + pane.document.getElementById( //删除条目和附件 + "zotero-itemmenu-delitem" + ).disabled = !( // 删除条目和附件是否可用 + showMenuAtt || + showMenuSnap); + pane.document.getElementById( // 仅删除附件菜单 + "zotero-itemmenu-delatt" + ).disabled = !showMenuAtt; // 仅删除附件菜单是否可用 + + pane.document.getElementById( // 仅删除快照菜单 + "zotero-itemmenu-delsnap" + ).disabled = !showMenuSnap;// 仅删除快照是否可用 + + }, +}; + +window.addEventListener( + "load", + function (e) { + if (window.ZoteroPane) { + var doc = window.ZoteroPane.document; + // add event listener for menu items + doc.getElementById("zotero-itemmenu").addEventListener( + "popupshowing", + Zotero.DelItem.displayMenuitem, + false + ); + } + }, + false +); + diff --git a/chrome/locale/zh-CN/overlay.dtd b/chrome/locale/zh-CN/overlay.dtd index 7ec4bf9..bcc5ca6 100644 --- a/chrome/locale/zh-CN/overlay.dtd +++ b/chrome/locale/zh-CN/overlay.dtd @@ -2,4 +2,4 @@ - + diff --git a/install.rdf b/install.rdf index 4e42d1b..d609e7c 100644 --- a/install.rdf +++ b/install.rdf @@ -7,7 +7,7 @@ RDF:about="urn:mozilla:install-manifest" em:id="delitemwithatt@redleaf.me" em:name="Del Item With Att" - em:version="0.0.5" + em:version="0.0.6" em:type="2" em:creator="Minyi Han" em:description="Delete Item(s) With Attachment(s)" diff --git a/update.rdf b/update.rdf index 73d3745..baa66c5 100644 --- a/update.rdf +++ b/update.rdf @@ -6,13 +6,13 @@ - 0.0.5 + 0.0.6 zotero@chnm.gmu.edu 5.0.0 5.* - https://github.com/redleafnew/delitemwithatt/releases/download/0.0.5/delitemwithatt.xpi + https://github.com/redleafnew/delitemwithatt/releases/download/0.0.6/delitemwithatt.xpi @@ -21,7 +21,7 @@ juris-m@juris-m.github.io 4.999 5.* - https://github.com/redleafnew/delitemwithatt/releases/download/0.0.5/delitemwithatt.xpi + https://github.com/redleafnew/delitemwithatt/releases/download/0.0.6/delitemwithatt.xpi