Skip to content

Commit

Permalink
增加仅删除附件
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed Apr 19, 2021
1 parent dfd62d7 commit 243f36e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
22 changes: 12 additions & 10 deletions chrome/content/overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
src="chrome://delitem/content/scripts/delitem.js"/>


<popup id="zotero-collectionmenu">
<menupopup id="zotero-collectionmenu">
<menuitem
id="zotero-collectionmenu-delitem"
label="&zotero.delitem.delitems.label;"
oncommand="Zotero.DelItem.DelColl()"/>
</popup>
</menupopup>

<popup
id="zotero-itemmenu"
onpopupshowing="ZoteroPane.buildItemContextMenu();">
<menuitem
id="zotero-itemmenu-delitem"
label="&zotero.delitem.delitem.label;"
oncommand="Zotero.DelItem.DelItem()"/>
</popup>
<menupopup id="zotero-itemmenu">
<menuseparator id="id-delitem-separator"/>
<menu id="zotero-itemmenu-delitem-namehandler"
label="&zotero.delitem.namehandler.label;">
<menupopup id="delitem">
<menuitem id="zotero-itemmenu-delitem" label="&zotero.delitem.delitem.label;" oncommand="Zotero.DelItem.DelItem()"/> <!-- 删除条目和附件 -->
<menuitem id="zotero-itemmenu-delatt" label="&zotero.delitem.delatt.label;" oncommand="Zotero.DelItem.DelAtt()"/> <!-- 仅删除附件 -->
</menupopup>
</menu>
</menupopup>
</overlay>
31 changes: 31 additions & 0 deletions chrome/content/scripts/delitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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路径
Expand Down
4 changes: 3 additions & 1 deletion chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<!ENTITY zotero.delitem.delitem.label "Delete Item(s) with Attachment(s)">
<!ENTITY zotero.delitem.delatt.label "Delete Attachment(s) only">
<!ENTITY zotero.delitem.delitem.label "Delete Attachment(s) and Item(s)">
<!ENTITY zotero.delitem.delitems.label "Delete Collection with Attachments">
<!ENTITY zotero.delitem.namehandler.label "Delete Attachment(s)">
6 changes: 4 additions & 2 deletions chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<!ENTITY zotero.delitem.delitem.label "删除条目包括附件">
<!ENTITY zotero.delitem.delitems.label "删除分类条目包括附件">
<!ENTITY zotero.delitem.delatt.label "仅删除附件">
<!ENTITY zotero.delitem.delitem.label "删除附件和条目">
<!ENTITY zotero.delitem.delitems.label "删除分类条目包括附件">
<!ENTITY zotero.delitem.namehandler.label "删除附件">

0 comments on commit 243f36e

Please sign in to comment.