diff --git a/chrome/content/overlay.xul b/chrome/content/overlay.xul index ca51cd5..8f90e36 100644 --- a/chrome/content/overlay.xul +++ b/chrome/content/overlay.xul @@ -11,19 +11,21 @@ src="chrome://delitem/content/scripts/delitem.js"/> - + - + - - - + + + + + + + + + diff --git a/chrome/content/scripts/delitem.js b/chrome/content/scripts/delitem.js index 19ff4a2..e89a507 100644 --- a/chrome/content/scripts/delitem.js +++ b/chrome/content/scripts/delitem.js @@ -22,6 +22,37 @@ Zotero.DelItem = { } }, + DelAtt: async function () { // 仅删除附件调用的函数 + + var zoteroPane = Zotero.getActiveZoteroPane(); + var items = zoteroPane.getSelectedItems(); + var truthBeTold = window.confirm("Are you sure you want to delete the attachment(s) of the item(s)? This action cannot be undone.") + if (truthBeTold) { + for (let item of items) { + if (item && !item.isNote()) { //2 if + if (item.isRegularItem()) { // Regular Item 一般条目//3 if + let attachmentIDs = item.getAttachments(); + for (let id of attachmentIDs) { //4 for + let attachment = Zotero.Items.get(id); + // if (attachment.attachmentContentType == 'text/html' ) { //可以筛选删除的附件类型 + attachment.deleted = true; //删除附件(快照) + await attachment.saveTx(); + // } + var file = await attachment.getFilePathAsync(); + await OS.File.remove(file); //删除文件 + } //4 for + } // 3 if + if (item.isAttachment()) { //附件条目 5 if + var file = await item.getFilePathAsync(); + await OS.File.remove(file); //删除文件 + item.deleted = true; + await item.saveTx(); + }//5if + } //2 if + } + } + }, + DelItems: async function (items) { //删除条目被调用的执行具体删除任务的函数 Components.utils.import("resource://gre/modules/osfile.jsm"); var zfPath = Zotero.ZotFile.getPref("dest_dir"); //得到zotfile路径 diff --git a/chrome/locale/en-US/overlay.dtd b/chrome/locale/en-US/overlay.dtd index 96ce27a..b012f9f 100644 --- a/chrome/locale/en-US/overlay.dtd +++ b/chrome/locale/en-US/overlay.dtd @@ -1,2 +1,4 @@ - + + + \ No newline at end of file diff --git a/chrome/locale/zh-CN/overlay.dtd b/chrome/locale/zh-CN/overlay.dtd index 92f000a..6d91624 100644 --- a/chrome/locale/zh-CN/overlay.dtd +++ b/chrome/locale/zh-CN/overlay.dtd @@ -1,2 +1,4 @@ - - \ No newline at end of file + + + + \ No newline at end of file