-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# ignore | ||
|
||
# file | ||
Zotlink* | ||
*.xpi | ||
|
||
# dir | ||
/图片 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Zotero.Zotlink = { | ||
// reference from [jlegewie/zotfile at v5.1.1](https://github.com/jlegewie/zotfile/tree/v5.1.1) | ||
// get zotfile settings | ||
moveSupplemantaryFile: function() { | ||
/* moveFile */ | ||
// get old path | ||
var win = Services.wm.getMostRecentWindow("navigator:browser"); | ||
var sel_attachments = win.ZoteroPane.getSelectedItems() | ||
.map(item => item.isRegularItem() ? item.getAttachments() : item) | ||
.reduce((a, b) => a.concat(b), []) | ||
.map(item => typeof item == 'number' ? Zotero.Items.get(item) : item) | ||
.filter(item => item.isAttachment()) | ||
.filter(att => att.attachmentLinkMode !== Zotero.Attachments.LINK_MODE_LINKED_URL) | ||
.map(att => att.id); | ||
var atts = Zotero.Items.get(sel_attachments) | ||
att = atts[0] | ||
old_filepath = att.getFilePath() | ||
old_filepath = OS.Path.normalize(old_filepath) | ||
// get all files in the parent item | ||
parent_item = Zotero.Items.get(att.parentItemID) | ||
attachments = parent_item.getAttachments() | ||
atts_all = Zotero.Items.get(attachments) | ||
// get linked file's dir(conducted by zotfile) | ||
atts_filteer = atts_all.filter(atts_all => atts_all.attachmentLinkMode === 2); | ||
filepath = atts_filteer[0].getFilePath() | ||
// target_folder = filePath.substring(0, filePath.lastIndexOf('\\')) | ||
target_folder = OS.Path.dirname(filepath) | ||
// target_folder;old_filepath | ||
// filename = old_filepath.split('\\').pop() | ||
filename = OS.Path.basename(old_filepath) | ||
// get target path | ||
foldersep = Zotero.isWin ? '\\' : '/' | ||
target_filepath = target_folder + foldersep + filename | ||
target_filepath = OS.Path.normalize(target_filepath) | ||
// target_filepath | ||
// move | ||
OS.File.move(old_filepath, target_filepath) | ||
/* Link and remove old from zotero database */ | ||
// linkFromFile | ||
var options = {file: target_filepath, libraryID: parent_item.libraryID, parentItemID: parent_item.id, collections: undefined, saveOptions: {skipSelect: true}}; | ||
Zotero.Attachments.linkFromFile(options) | ||
// erase old attachment | ||
att.eraseTx() | ||
}, | ||
|
||
// test | ||
// selectedItemsTest: function () { | ||
// let selectedItems = ZoteroPane.getSelectedItems(); | ||
// if (selectedItems.length > 0) { | ||
// var msg = ""; | ||
// for (let item of selectedItems) { | ||
// msg += `${item.itemType} - ${item.getField("title")}`; | ||
// Zotero.debug(`** ${msg}`); | ||
// } | ||
// Zotero.debug(msg); | ||
// alert(msg); | ||
// } | ||
// } | ||
}; | ||
|