-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCopyItemLink
50 lines (41 loc) · 1.14 KB
/
CopyItemLink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copy item link
// @author windingwind
// @link https://github.com/windingwind/zotero-actions-tags/discussions/115
// @usage Select an item in the library and press the assigned shortcut keys
//
// [Copy Item Link]
// Name: Copy Item Link
// Event: None
// Operation: Script
// Data: JS code below
// Shortcut: None
// Menu Label: Copy Item Link
if (!item) {
return "[Copy Item Link] item is empty";
}
const libraryType = item.library.libraryType;
const key = item.key;
let uri;
if (libraryType === "user") {
uri = "zotero://select/library/items/" + key;
}
else {
const groupID = Zotero.Libraries.get(item.libraryID).groupID;
uri = "zotero://select/groups/" + groupID + "/items/" + key;
}
const clipboard = new Zotero.ActionsTags.api.utils.ClipboardHelper();
let linkText;
// Use title
linkText = item.getField("title");
// Use citation key
// linkText = item.getField("citationKey");
let plainText;
// Use plain-text
// plainText = uri;
// Use MarkDown
plainText = `[${linkText}](${uri})`
clipboard
.addText(plainText, "text/unicode")
.addText(`<a href="${uri}">${linkText}</a>`, "text/html")
.copy();
return `[Copy Item Link] item link ${uri} copied.`