@@ -388,6 +388,15 @@ Zotero.Jasminum = {
388
388
return { dbname : dbname [ 1 ] , filename : filename [ 1 ] , dbcode : dbcode [ 1 ] } ;
389
389
} ,
390
390
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
+
391
400
search : async function ( fileData ) {
392
401
Zotero . debug ( "**Jasminum start search" ) ;
393
402
var postData = Zotero . Jasminum . createPostData ( fileData ) ;
@@ -424,8 +433,7 @@ Zotero.Jasminum = {
424
433
425
434
getSearchItems : function ( resptext ) {
426
435
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 ) ;
429
437
var rows = html . querySelectorAll (
430
438
"table.result-table-list > tbody > tr"
431
439
) ;
@@ -628,11 +636,7 @@ Zotero.Jasminum = {
628
636
var extraString = '' ;
629
637
Zotero . debug ( "** Jasminum get article page." ) ;
630
638
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 ) ;
636
640
// Full abstract note.
637
641
if ( newItem . getField ( "abstractNote" ) . endsWith ( "..." ) ) {
638
642
var abs = html . querySelector ( "#ChDivSummary" ) ;
@@ -792,11 +796,7 @@ Zotero.Jasminum = {
792
796
793
797
getChapterUrl : async function ( readerUrl ) {
794
798
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 ) ;
800
800
return (
801
801
"https://kreader.cnki.net/Kreader/" +
802
802
readerHTML . querySelector ( "iframe" ) . getAttribute ( "src" )
@@ -807,10 +807,8 @@ Zotero.Jasminum = {
807
807
var key = item . key ;
808
808
var lib = item . libraryID ;
809
809
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
814
812
) ;
815
813
var tree = chapterHTML . getElementById ( "treeDiv" ) ;
816
814
var rows = tree . querySelectorAll ( "tr" ) ;
0 commit comments