Skip to content

Commit cbcccba

Browse files
committed
fix: 更新DOMParser函数,避免与scite等插件冲突
1 parent d181865 commit cbcccba

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

chrome/content/scripts/jasminum.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,15 @@ Zotero.Jasminum = {
388388
return { dbname: dbname[1], filename: filename[1], dbcode: dbcode[1] };
389389
},
390390

391+
string2HTML: function (text) {
392+
// Use DOMParser to parse text to HTML.
393+
// This DOMParser is from XPCOM.
394+
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
395+
.createInstance(Components.interfaces.nsIDOMParser);
396+
return parser.parseFromString(text, "text/html");
397+
},
398+
399+
391400
search: async function (fileData) {
392401
Zotero.debug("**Jasminum start search");
393402
var postData = Zotero.Jasminum.createPostData(fileData);
@@ -424,8 +433,7 @@ Zotero.Jasminum = {
424433

425434
getSearchItems: function (resptext) {
426435
Zotero.debug("**Jasminum get item from search");
427-
var parser = new DOMParser();
428-
var html = parser.parseFromString(resptext, "text/html");
436+
var html = Zotero.Jasminum.string2HTML(resptext);
429437
var rows = html.querySelectorAll(
430438
"table.result-table-list > tbody > tr"
431439
);
@@ -628,11 +636,7 @@ Zotero.Jasminum = {
628636
var extraString = '';
629637
Zotero.debug("** Jasminum get article page.");
630638
var resp = await Zotero.HTTP.request("GET", targetData.targetUrls[idx]);
631-
var parser = new DOMParser();
632-
var html = parser.parseFromString(
633-
resp.responseText,
634-
"text/html"
635-
);
639+
var html = Zotero.Jasminum.string2HTML(resp.responseText);
636640
// Full abstract note.
637641
if (newItem.getField("abstractNote").endsWith("...")) {
638642
var abs = html.querySelector("#ChDivSummary");
@@ -792,11 +796,7 @@ Zotero.Jasminum = {
792796

793797
getChapterUrl: async function (readerUrl) {
794798
var reader = await Zotero.HTTP.request("GET", readerUrl);
795-
var parser = new DOMParser();
796-
var readerHTML = parser.parseFromString(
797-
reader.responseText,
798-
"text/html"
799-
);
799+
var readerHTML = Zotero.Jasminum.string2HTML(reader.responseText);
800800
return (
801801
"https://kreader.cnki.net/Kreader/" +
802802
readerHTML.querySelector("iframe").getAttribute("src")
@@ -807,10 +807,8 @@ Zotero.Jasminum = {
807807
var key = item.key;
808808
var lib = item.libraryID;
809809
var chapter = await Zotero.HTTP.request("GET", chapterUrl);
810-
var parser = new DOMParser();
811-
var chapterHTML = parser.parseFromString(
812-
chapter.responseText,
813-
"text/html"
810+
var chapterHTML = Zotero.Jasminum.string2HTML(
811+
chapter.responseText
814812
);
815813
var tree = chapterHTML.getElementById("treeDiv");
816814
var rows = tree.querySelectorAll("tr");

0 commit comments

Comments
 (0)