-
Notifications
You must be signed in to change notification settings - Fork 40
/
16copy-creators-to-clipboard.js
43 lines (37 loc) · 1.43 KB
/
16copy-creators-to-clipboard.js
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
var zoteroPane = Zotero.getActiveZoteroPane();
var zitems = zoteroPane.getSelectedItems();
var clipboardText = ''
for (let zitem of zitems) {
var creatorsArray = [];
var whiteSpace = ' ';
var lan = zitem.getField("language");
if (lan.indexOf("中") != -1) //如果为中文
{ whiteSpace = ''; //如果为中文删除空格
}
let creators = zitem.getCreators();
for (let creator of creators) {
let creatorStr = creator.lastName + whiteSpace + creator.firstName;
if (creatorsArray.indexOf(creatorStr) == -1) {
creatorsArray.push(creatorStr);
}
var clipboardTextSingleItem = creatorsArray.join(', ');
}
clipboardText = clipboardText + clipboardTextSingleItem + '\r\n';
}
copyToClipboard(clipboardText);
return clipboardText;
function copyToClipboard(clipboardText) {
if (clipboardText) {
const gClipboardHelper =
Components.classes['@mozilla.org/widget/clipboardhelper;1']
.getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(clipboardText, document);
} else {
var prompts = Components.
classes['@mozilla.org/embedcomp/prompt-service;1'].
getService(Components.interfaces.nsIPromptService);
var title = Zutilo.getString('zutilo.error.copynoitemstitle')
var text = Zutilo.getString('zutilo.error.copynoitemstext')
prompts.alert(null, title, text)
}
}