From 606fa0158ebb9c889df353efbf6277d3e66c457a Mon Sep 17 00:00:00 2001 From: l0o0 Date: Thu, 6 Aug 2020 16:34:47 +0800 Subject: [PATCH] Add pdftk check before adding bookmark. Update query title in function splieFilename. Fix #2 issue mix VO and IS. --- chrome/content/scripts/jasminum.js | 33 ++++++++++++++++++++++++--- chrome/content/scripts/preferences.js | 22 ++---------------- install.rdf | 2 +- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/chrome/content/scripts/jasminum.js b/chrome/content/scripts/jasminum.js index 4ef1d07..3723847 100644 --- a/chrome/content/scripts/jasminum.js +++ b/chrome/content/scripts/jasminum.js @@ -136,9 +136,10 @@ Zotero.Jasminum = { splitFilename: function (filename) { // Make query parameters from filename + var patent = Zotero.Prefs.get("jasminum.namepatent"); var patentArr = patent.split("_"); var prefix = filename.substr(0, filename.length - 4); - + var prefix = prefix.replace("_省略_", ""); // Long title contains _省略_ var author = ""; var title = ""; // Remove year string @@ -155,9 +156,9 @@ Zotero.Jasminum = { console.log(authorIdx); author = prefixArr[authorIdx]; prefixArr.splice(authorIdx, 1); - title = prefixArr.join(""); + title = prefixArr.join(" "); } else { - title = prefixArr.join(""); + title = prefixArr.join(" "); } return { @@ -362,6 +363,7 @@ Zotero.Jasminum = { if (!authors[authors.length - 1].trim()) authors.pop(); return tag + " " + authors.join("\n" + tag + " "); }); + var data = data.replace(/vo (\d+)\n/, "VO $1\n"); // Divide VO and IS to different line. targetUrl = `https://kns.cnki.net/KCMS/detail/detail.aspx?dbcode=${targetID.dbcode}&dbname=${targetID.dbname}&filename=${targetID.filename}&v=`; Zotero.debug(data); return [data, targetUrl]; @@ -444,6 +446,7 @@ Zotero.Jasminum = { var libraryID = item.libraryID; if (!Zotero.Jasminum.checkItem(item)) return; // TODO Need notify var fileData = Zotero.Jasminum.splitFilename(item.getFilename()); + Zotero.debug(fileData); var searchPrepareOut = await Zotero.Jasminum.searchPrepare(fileData); Zotero.debug("searchPrepareOut"); Zotero.debug(searchPrepareOut); @@ -661,10 +664,34 @@ Zotero.Jasminum = { addBookmarkItem: async function () { var item = ZoteroPane.getSelectedItems()[0]; + if (!(await Zotero.Jasminum.checkPath())) { + alert( + "Can't find PDFtk Server execute file. Please install PDFtk Server and choose the folder in the Jasminum preference window." + ); + return false; + } var bookmark = await Zotero.Jasminum.getBookmark(item); await Zotero.Jasminum.addBookmark(item, bookmark); }, + checkPath: async function () { + Zotero.debug("** Jasminum check path."); + var pdftkpath = Zotero.Prefs.get("jasminum.pdftkpath"); + Zotero.debug(pdftkpath); + var pdftk = ""; + if (Zotero.isWin) { + Zotero.debug("1"); + pdftk = OS.Path.join(pdftkpath, "pdftk.exe"); + } else { + Zotero.debug("2"); + pdftk = OS.Path.join(pdftkpath, "pdftk"); + } + Zotero.debug(pdftk); + var fileExist = await OS.File.exists(pdftk); + Zotero.debug(fileExist); + return fileExist; + }, + checkItemName: function (item) { return item.isRegularItem() && item.isTopLevelItem(); }, diff --git a/chrome/content/scripts/preferences.js b/chrome/content/scripts/preferences.js index c032bb2..fb332b5 100644 --- a/chrome/content/scripts/preferences.js +++ b/chrome/content/scripts/preferences.js @@ -2,7 +2,7 @@ initPref = async function () { Components.utils.import("resource://gre/modules/osfile.jsm"); var jasminum_pdftk_path = Zotero.Prefs.get("jasminum.pdftkpath"); document.getElementById("jasminum-pdftk-path").value = jasminum_pdftk_path; - var fileExist = await checkPath(); + var fileExist = await Zotero.Jasminum.checkPath(); pathCheckIcon(fileExist); }; @@ -27,28 +27,10 @@ choosePath = async function () { Zotero.debug("** Jasminum " + fp.file.path); Zotero.Prefs.set("jasminum.pdftkpath", fp.file.path); document.getElementById("jasminum-pdftk-path").value = fp.file.path; - var fileExist = await checkPath(); + var fileExist = await Zotero.Jasminum.checkPath(); pathCheckIcon(fileExist); }; -checkPath = async function () { - Zotero.debug("** Jasminum check path."); - var pdftkpath = Zotero.Prefs.get("jasminum.pdftkpath"); - Zotero.debug(pdftkpath); - var pdftk = ""; - if (Zotero.isWin) { - Zotero.debug("1"); - pdftk = OS.Path.join(pdftkpath, "pdftk.exe"); - } else { - Zotero.debug("2"); - pdftk = OS.Path.join(pdftkpath, "pdftk"); - } - Zotero.debug(pdftk); - var fileExist = await OS.File.exists(pdftk); - Zotero.debug(fileExist); - return fileExist; -}; - pathCheckIcon = function (fileExist) { document.getElementById("path-accept").hidden = !fileExist; document.getElementById("path-error").hidden = fileExist; diff --git a/install.rdf b/install.rdf index fe5ef2b..de67402 100644 --- a/install.rdf +++ b/install.rdf @@ -5,7 +5,7 @@ jasminum@linxzh.com Jasminum - 0.0.2 + 0.0.3 2 chrome://jasminum/skin/icon.png true