-
Notifications
You must be signed in to change notification settings - Fork 40
/
10add-bold-tag-around-author.js
63 lines (52 loc) · 1.8 KB
/
10add-bold-tag-around-author.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//英文替换
var oldName = "Wuji Zhang";
var newFirstName = "<b>Wuji</b>";
var newLastName = "<b>Zhang</b>";
var newFieldMode = 0; // 0: two-field, 1: one-field (with empty first name)
var rn = 0; //计数替换条目个数
await Zotero.DB.executeTransaction(async function () {
zoteroPane = Zotero.getActiveZoteroPane();
items = zoteroPane.getSelectedItems();
for (item of items) {
let creators = item.getCreators();
let newCreators = [];
for (let creator of creators) {
if (`${creator.firstName} ${creator.lastName}`.trim() == oldName) {
creator.firstName = newFirstName;
creator.lastName = newLastName;
creator.fieldMode = newFieldMode;
rn+=1;
}
newCreators.push(creator);
}
item.setCreators(newCreators);
await item.save();
}
});
return rn + " item(s) updated";
//中文替换
var oldName = "无忌 张";
var newFirstName = "";
var newLastName = "<b>张无忌</b>";
var newFieldMode = 1; // 0: two-field, 1: one-field (with empty first name)
var rn = 0; //计数替换条目个数
await Zotero.DB.executeTransaction(async function () {
zoteroPane = Zotero.getActiveZoteroPane();
items = zoteroPane.getSelectedItems();
for (item of items) {
let creators = item.getCreators();
let newCreators = [];
for (let creator of creators) {
if (`${creator.firstName} ${creator.lastName}`.trim() == oldName) {
creator.firstName = newFirstName;
creator.lastName = newLastName;
creator.fieldMode = newFieldMode;
rn+=1;
}
newCreators.push(creator);
}
item.setCreators(newCreators);
await item.save();
}
});
return rn + " item(s) updated";