Skip to content

Commit bbbe86d

Browse files
committed
修复姓名拆分时英文姓,名的顺序,名不为空时不进行拆分
1 parent b2b3e3f commit bbbe86d

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

chrome/content/scripts/jasminum.js

+18-38
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Zotero.Jasminum = new function () {
213213
// 没有查询结果
214214
this.Utils.showPopup(
215215
"No results found!",
216-
`作者:${fileData.author}\n篇名${fileData.keyword}\n请检查设置中的文件名模板是否与实际实际情况相符`,
216+
`作者:${fileData.author},\n 篇名${fileData.keyword},\n 请检查设置中的文件名模板是否与实际实际情况相符`,
217217
true)
218218
}
219219
}
@@ -279,39 +279,23 @@ Zotero.Jasminum = new function () {
279279
var creators = item.getCreators();
280280
for (var i = 0; i < creators.length; i++) {
281281
var creator = creators[i];
282-
if (
283-
// English Name pass
284-
creator.lastName.search(/[A-Za-z]/) !== -1 ||
285-
creator.firstName.search(/[A-Za-z]/) !== -1 ||
286-
creator.firstName // 如果有名就不拆分了
282+
if ( // English Name
283+
(creator.lastName.search(/[A-Za-z]/) >= 0 ||
284+
creator.firstName.search(/[A-Za-z]/) >= 0) &&
285+
creator.firstName === "" // 名为空
287286
) {
288287
var EnglishName = creator.lastName;
289-
var temp = EnglishName.split(/[\n\s+,]/g);
290-
for (var k = 0; k < temp.length; k++) {
291-
if (temp[k] == "") {
292-
// 删除数组中空值
293-
temp.splice(k, 1);
294-
k--;
295-
}
296-
}
297-
if (temp.length < 3) {
298-
creator.lastName = temp[0];
299-
creator.firstName = temp[1];
300-
} else {
301-
creator.lastName = temp[0];
302-
creator.firstName = temp[1].concat(" ", temp[2]);
303-
}
304-
creator.fieldMode = 0;// 0: two-field, 1: one-field (with empty first name)
305-
creators[i] = creator;
306-
} else { // For Chinese Name
307-
var chineseName = creator.lastName
308-
? creator.lastName
309-
: creator.firstName;
288+
var temp = EnglishName.split(/[\n\s+,]/g)
289+
.filter(Boolean); // 过滤空字段
290+
creator.lastName = temp.pop();
291+
creator.firstName = temp.join(" ");
292+
} else if (creator.firstName === "") { // For Chinese Name,名为空
293+
var chineseName = creator.lastName || creator.firstName;
310294
creator.lastName = chineseName.charAt(0);
311295
creator.firstName = chineseName.substr(1);
312-
creator.fieldMode = 0;
313-
creators[i] = creator;
314296
}
297+
creator.fieldMode = 0;// 0: two-field, 1: one-field (with empty first name)
298+
creators[i] = creator;
315299
}
316300
if (creators != item.getCreators()) {
317301
item.setCreators(creators);
@@ -325,21 +309,17 @@ Zotero.Jasminum = new function () {
325309
var creators = item.getCreators();
326310
for (var i = 0; i < creators.length; i++) {
327311
var creator = creators[i];
328-
if (
329-
// English Name pass
312+
if ( // English Name
330313
creator.lastName.search(/[A-Za-z]/) !== -1 ||
331314
creator.lastName.search(/[A-Za-z]/) !== -1
332315
) {
333-
creator.lastName = creator.lastName + " " + creator.firstName;
334-
creator.firstName = "";
335-
creator.fieldMode = 1;// 0: two-field, 1: one-field (with empty first name)
336-
creators[i] = creator;
316+
creator.lastName = creator.firstName + " " + creator.lastName;
337317
} else { // For Chinese Name
338318
creator.lastName = creator.lastName + creator.firstName;
339-
creator.firstName = "";
340-
creator.fieldMode = 1;
341-
creators[i] = creator;
342319
}
320+
creator.firstName = "";
321+
creator.fieldMode = 1;// 0: two-field, 1: one-field (with empty first name)
322+
creators[i] = creator;
343323
}
344324
if (creators != item.getCreators()) {
345325
item.setCreators(creators);

0 commit comments

Comments
 (0)