From 243f36e262cac98399ef6a941e3766cbaa525d19 Mon Sep 17 00:00:00 2001 From: redleafnew Date: Mon, 19 Apr 2021 14:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=85=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome/content/overlay.xul | 22 ++++++++++++---------- chrome/content/scripts/delitem.js | 31 +++++++++++++++++++++++++++++++ chrome/locale/en-US/overlay.dtd | 4 +++- chrome/locale/zh-CN/overlay.dtd | 6 ++++-- 4 files changed, 50 insertions(+), 13 deletions(-) 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