Skip to content

Commit

Permalink
Add function to remove dot in Chinese lastname and firstname. Fix err…
Browse files Browse the repository at this point in the history
…or in 0.0.5
  • Loading branch information
l0o0 committed Sep 2, 2020
1 parent ff403c1 commit c0ac560
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions chrome/content/overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<menupopup id="jasminum">
<menuitem label="&jasminum.namehandler.split.label;" oncommand="Zotero.Jasminum.splitNameM();"/>
<menuitem label="&jasminum.namehandler.merge.label;" oncommand="Zotero.Jasminum.mergeNameM();"/>
<menuitem label="&jasminum.namehandler.removeDot.label;" oncommand="Zotero.Jasminum.removeDotM();"/>
</menupopup>
</menu>
<menuitem id="zotero-itemmenu-jasminum"
Expand Down
2 changes: 2 additions & 0 deletions chrome/content/preferences.xul
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<preference id="pref-jasminum.zhnamesplit" name="extensions.zotero.jasminum.zhnamesplit" type="bool"/>
<preference id="pref-jasminum.rename" name="extensions.zotero.jasminum.rename" type="bool"/>
<preference id="pref-jasminum.autobookmark" name="extensions.zotero.jasminum.autobookmark" type="bool"/>
<preference id="pref-jasminum.zhnamedot" name="extensions.zotero.jasminum.zhnamedot" type="bool"/>
</preferences>
<tabbox>
<tabs>
Expand All @@ -30,6 +31,7 @@
<checkbox id="jasminum.zhnamesplit" label="&jasminum.zhnamesplit.label;" preference="pref-jasminum.zhnamesplit"/>
<checkbox id="jasminum.rename" label="&jasminum.rename.label;" preference="pref-jasminum.rename"/>
<checkbox id="jasminum.autobookmark" label="&jasminum.autobookmark.label;" preference="pref-jasminum.autobookmark"/>
<!-- <checkbox id="jasminum.zhnamedot" label="&jasminum.zhnamedot.label;" preference="pref-jasminum.zhnamedot"/> -->
<separator/>
<vbox flex="1">
<description>&jasminum.namepatent.desc;</description>
Expand Down
23 changes: 22 additions & 1 deletion chrome/content/scripts/jasminum.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ Zotero.Jasminum = {
}
var bookmark = await Zotero.Jasminum.getBookmark(item);
if (!bookmark) {
alert("No Bookmark found!\n书签信息未找到")
alert("No Bookmark found!\n书签信息未找到");
}
await Zotero.Jasminum.addBookmark(item, bookmark);
// Use zotfile to add TOC
Expand Down Expand Up @@ -965,6 +965,27 @@ Zotero.Jasminum = {
}
}
},

removeDotM: function () {
var items = ZoteroPane.getSelectedItems();
Zotero.Jasminum.removeDot(items);
},

removeDot: async function (items) {
for (let item of items) {
var attachmentIDs = item.getAttachments();
for (let id of attachmentIDs) {
var atta = Zotero.Items.get(id);
var newName = atta.attachmentFilename.replace(
/([\u4e00-\u9fa5]), ([\u4e00-\u9fa5])/g,
"$1$2"
);
await atta.renameAttachmentFile(newName);
atta.setField("title", newName);
atta.saveTx();
}
}
},
};

window.addEventListener(
Expand Down
4 changes: 3 additions & 1 deletion chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<!ENTITY jasminum.namepatent.desc "Filename format:{&#37;g}=Chinese fullname,{&#37;t}=title, {&#37;y}=year, seperate by '_',ignore file extension">
<!ENTITY jasminum.zhnamesplit.label "Split firstname and lastname when get metadata(Including CNKI web translators)">
<!ENTITY jasminum.rename.label "Use Zotfile to rename attachment(Need Zotfile installed)">
<!ENTITY jasminum.autobookmark.label "Add bookmark to thesis PDF when adding thesis item from CNKI">
<!ENTITY jasminum.autobookmark.label "Add bookmark to thesis PDF when adding thesis item from CNKI">
<!ENTITY jasminum.zhnamedot.label "Remove ', ' between Chinese characters when Zotfile rename attachment file.">
<!ENTITY jasminum.namehandler.removeDot.label "Remove dot in filename">
4 changes: 3 additions & 1 deletion chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<!ENTITY jasminum.namepatent.desc "根据文件名抓取知网元数据,文件名格式设置:{&#37;g}=全名,{&#37;t}=标题名,{&#37;y}=年份,以下划线_分隔,不用考虑文件后缀名">
<!ENTITY jasminum.zhnamesplit.label "抓取题录信息时拆分中文姓,名(包括知网页面抓取)">
<!ENTITY jasminum.rename.label "拉取知网元数据后调用Zotfile重命名附件(需安装Zotfile)">
<!ENTITY jasminum.autobookmark.label "从知网添加学位论文时自动添加书签">
<!ENTITY jasminum.autobookmark.label "从知网添加学位论文时自动添加书签(暂不支持从知网网页抓取论文)">
<!ENTITY jasminum.zhnamedot.label "当拉取知网元数据时去除 Zotfile 重命名文件名中的逗号(, )">
<!ENTITY jasminum.namehandler.removeDot.label "去除文件中逗号">

0 comments on commit c0ac560

Please sign in to comment.