From d1f374384f1a559159e885d3208e0bd9ddf66cec Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Sun, 15 Oct 2023 14:56:17 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=8F=91=E5=B8=83RHHZ.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 RHHZ.js diff --git a/RHHZ.js b/RHHZ.js new file mode 100644 index 00000000..60e09996 --- /dev/null +++ b/RHHZ.js @@ -0,0 +1,137 @@ +{ + "translatorID": "3b4e0da7-d9b2-41e8-b4d3-38701241b872", + "label": "RHHZ", + "creator": "jiaojiaodubai23", + "target": "", + "minVersion": "5.0", + "maxVersion": "", + "priority": 100, + "inRepository": true, + "translatorType": 4, + "browserSupport": "gcsibv", + "lastUpdated": "2023-10-14 20:47:46" +} + +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2022 jiaojiaodubai23@gmail.com + + This file is part of Zotero. + + Zotero is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Zotero is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with Zotero. If not, see . + + ***** END LICENSE BLOCK ***** +*/ + + +function detectWeb(doc, url) { + let insite = doc.querySelector('div[class*="foot"] p > a[href*="www.rhhz.net"]'); + let itemID = doc.querySelector('meta[name="citation_id"]'); + if (insite && itemID) { + return 'journalArticle'; + } + else if (insite && getSearchResults(doc, true)) { + return 'multiple'; + } + return false; +} + +function getSearchResults(doc, checkOnly) { + var items = {}; + var found = false; + var rows = doc.querySelectorAll('div.article-list-title a:first-of-type'); + for (let row of rows) { + let href = row.href; + let title = ZU.trimInternal(row.textContent); + if (!href || !title) continue; + if (checkOnly) return true; + found = true; + items[href] = title; + } + return found ? items : false; +} + +async function doWeb(doc, url) { + if (detectWeb(doc, url) == 'multiple') { + let items = await Zotero.selectItems(getSearchResults(doc, false)); + if (!items) return; + for (let url of Object.keys(items)) { + await scrape(await requestDocument(url)); + } + } + else { + await scrape(doc, url); + } +} + +async function scrape(doc, url = doc.location.href) { + let translator = Zotero.loadTranslator('web'); + var pdfURL = ''; + let pdfButton = doc.querySelector('div.pdfView'); + let socallURL = doc.querySelector('head > meta[name="citation_pdf_url"]').content; + if (socallURL.endsWith('.pdf')) { + pdfURL = socallURL; + } + else if (pdfButton) { + pdfURL = pdfButton.parentElement.href; + } else { + let id = doc.querySelector('head > meta[name="citation_id"]').content; + let host = (new URL(url)).host; + pdfURL = `${url.split('//')[0]}//${host}/article/exportPdf?id=${id}` + } + Z.debug(pdfURL); + // Embedded Metadata + translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48'); + translator.setDocument(doc); + translator.setHandler('itemDone', (_obj, item) => { + var zhnamesplit = Z.getHiddenPref('zhnamesplit'); + for (var i = 0, n = item.creators.length; i < n; i++) { + var creator = item.creators[i]; + if (creator.lastName.search(/[A-Za-z]/) !== -1) { + // western name. split on last space + creator.firstName = creator.lastName.substr(0, lastSpace); + creator.lastName = creator.lastName.substr(lastSpace + 1); + } + else if (zhnamesplit === undefined ? true : zhnamesplit) { + // zhnamesplit is true, split firstname and lastname. + // Chinese name. first character is last name, the rest are first name + creator.firstName = creator.lastName.substr(1); + creator.lastName = creator.lastName.charAt(0); + } + item.creators[i] = creator + } + item.attachments = [ + { + url: pdfURL, + title: "Full Text PDF", + mimeType: "application/pdf" + } + ]; + item.attachments.push({ + url: url, + document: doc, + title: 'Snapshot', + mimeType: 'text/html' + }) + item.complete(); + }); + let em = await translator.getTranslatorObject(); + em.itemType = 'journalArticle'; + await em.doWeb(doc, url); +} +/** BEGIN TEST CASES **/ +var testCases = [ +] +/** END TEST CASES **/ From 63dce43faeb0921b1d7b34f3ba099a09942046d3 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Sun, 15 Oct 2023 15:10:19 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 1 deletion(-) diff --git a/RHHZ.js b/RHHZ.js index 60e09996..42f2fd24 100644 --- a/RHHZ.js +++ b/RHHZ.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2023-10-14 20:47:46" + "lastUpdated": "2023-10-15 07:09:42" } /* @@ -133,5 +133,149 @@ async function scrape(doc, url = doc.location.href) { } /** BEGIN TEST CASES **/ var testCases = [ + { + "type": "web", + "url": "http://www.hjbhkx.cn/article/doi/10.16803/j.cnki.issn.1004-6216.202307018", + "items": [ + { + "itemType": "journalArticle", + "title": "面向生态环境科技成果转化的产业基金研究及实践案例分析", + "creators": [ + { + "firstName": "茜", + "lastName": "曹", + "creatorType": "author" + }, + { + "firstName": "雯", + "lastName": "周", + "creatorType": "author" + }, + { + "firstName": "东洋", + "lastName": "魏", + "creatorType": "author" + }, + { + "firstName": "丽杰", + "lastName": "段", + "creatorType": "author" + }, + { + "firstName": "曼", + "lastName": "洪", + "creatorType": "author" + } + ], + "date": "2023-08-20", + "DOI": "10.16803/j.cnki.issn.1004-6216.202307018", + "ISSN": "1004-6216", + "abstractNote": "生态环境科技专项产生了一大批高水准的生态环境科研成果以及专业技术,但这些成果都停留在科学阶段,尚未形成产品,发挥社会价值。目前,国内外已经有很多成功的生态环境产业基金,如美国的清洁水州周转基金和国内的深圳清华大学研究院的力合科创投资孵化基金以及南京扬子江生态文明创新中心的源创基金,可以作为研究案例。文章选取国际国内代表性的运营多年和新兴的产业基金案例,分析生态环境产业基金在产业化过程中发挥的作用,结合调研内容总结产业基金运行模式的特点,根据先进经验提出针对我国生态环境产业基金运行主要存在问题的相关建议。", + "issue": "4", + "language": "zh", + "libraryCatalog": "www.hjbhkx.cn", + "pages": "1-8", + "publicationTitle": "环境保护科学", + "rights": "http://creativecommons.org/licenses/by/3.0/", + "url": "http://hjbh.cbpt.cnki.net//article/doi/10.16803/j.cnki.issn.1004-6216.202307018", + "volume": "49", + "attachments": [ + { + "title": "Full Text PDF", + "mimeType": "application/pdf" + }, + { + "title": "Snapshot", + "mimeType": "text/html" + } + ], + "tags": [ + { + "tag": "产业基金" + }, + { + "tag": "成果转化" + }, + { + "tag": "案例研究" + }, + { + "tag": "生态环境" + }, + { + "tag": "科技金融" + } + ], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "http://www.lczcyj.com/cn/article/doi/10.12344/lczcyj.2023.01.10.0003", + "items": [ + { + "itemType": "journalArticle", + "title": "宁夏退耕还林还草成果巩固问题探讨", + "creators": [ + { + "firstName": "治啸", + "lastName": "王", + "creatorType": "author" + }, + { + "firstName": "红军", + "lastName": "高", + "creatorType": "author" + } + ], + "date": "2023-03-30", + "DOI": "10.12344/lczcyj.2023.01.10.0003", + "ISSN": "2096-9546", + "abstractNote": "退耕还林还草是中共中央、国务院在20世纪末着眼中华民族长远发展和国家生态安全作出的重大决策。23年来的退耕还林还草工程实践取得了巨大的生态、经济和社会效益,赢得了社会各界赞誉。\"十四五\"以来,国家基于粮食安全和耕地保护考虑,已将工程重心转移到巩固已有建设成果上来。文中基于宁夏回族自治区退耕还林还草工程现状,总结退耕还林还草成果巩固的经验做法,梳理分析现存问题,并提出今后推动退耕还林还草高质量发展的建议:1)深挖后续产业发展潜力,促进\"以林养林\";2)合理优化退耕林地树种组成和植被配置模式,改善退耕林质量;3)提高生态效益补偿标准;4)稳定基层管理队伍。", + "issue": "1", + "journalAbbreviation": "lczcyj", + "language": "zh", + "libraryCatalog": "www.lczcyj.com", + "pages": "18-23", + "publicationTitle": "林草政策研究", + "rights": "http://creativecommons.org/licenses/by/3.0/", + "url": "http://www.lczcyj.com/cn/article/doi/10.12344/lczcyj.2023.01.10.0003", + "volume": "3", + "attachments": [ + { + "title": "Full Text PDF", + "mimeType": "application/pdf" + }, + { + "title": "Snapshot", + "mimeType": "text/html" + } + ], + "tags": [ + { + "tag": "宁夏回族自治区" + }, + { + "tag": "成果巩固" + }, + { + "tag": "生态补偿机制" + }, + { + "tag": "退耕还林还草" + } + ], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "http://www.yndxxb.ynu.edu.cn/yndxxbzrkxb/", + "items": "multiple" + } ] /** END TEST CASES **/ From cc460b5286a8b88db670f1c0c8797320adebeaeb Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Sun, 15 Oct 2023 15:21:42 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E5=90=8D=E5=88=86=E5=89=B2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RHHZ.js b/RHHZ.js index 42f2fd24..a290d680 100644 --- a/RHHZ.js +++ b/RHHZ.js @@ -104,7 +104,7 @@ async function scrape(doc, url = doc.location.href) { creator.firstName = creator.lastName.substr(0, lastSpace); creator.lastName = creator.lastName.substr(lastSpace + 1); } - else if (zhnamesplit === undefined ? true : zhnamesplit) { + else if ((zhnamesplit === undefined) ? true : zhnamesplit) { // zhnamesplit is true, split firstname and lastname. // Chinese name. first character is last name, the rest are first name creator.firstName = creator.lastName.substr(1); From c7cd34fc1bd7797c43049445c1e1e28e26c12143 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Sun, 15 Oct 2023 15:32:28 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ data/data.json | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da1e6d3e..423d83c3 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,11 @@ - 摘要信息:作者简介 + 内容简介 - 目录信息:目录存放至note附件里 - [详细截图](https://github.com/Captain2021/myTranslator/tree/main) ++ 仁和汇智 -> [RHHZ.js](./RHHZ.js) + - [x] 抓取引文信息 + - [x] 支持单条目 + - [x] 支持多条目 + - [x] PDF附件下载 + 来自[道格学社仓库](https://github.com/gezhongran/DougSociety)的翻译器 - [Bilibili 视频网站](./translators/BiliBili.js) - [当当网图书](./translators/Dangdang.js) diff --git a/data/data.json b/data/data.json index f27a8af0..721b79c3 100644 --- a/data/data.json +++ b/data/data.json @@ -24,5 +24,6 @@ "dpaper": "中国科学院文献情报中心", "xiaoyuzhouFM": "小宇宙FM", "PKULaw": "北大法宝", - "China Judgements Online": "中国裁判文书网" + "China Judgements Online": "中国裁判文书网", + "RHHZ": "仁和汇智" } \ No newline at end of file From 8652426db99f26308c593d4387224ca4b0092032 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Mon, 16 Oct 2023 10:13:29 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E8=A7=A3=E8=80=A6=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=9B=E8=A7=84=E8=8C=83=E2=80=9C=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E2=80=9D=E5=AD=97=E6=AE=B5=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/RHHZ.js b/RHHZ.js index a290d680..3955e443 100644 --- a/RHHZ.js +++ b/RHHZ.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2023-10-15 07:09:42" + "lastUpdated": "2023-10-16 02:08:06" } /* @@ -76,6 +76,33 @@ async function doWeb(doc, url) { } } +function matchCreator(creator) { + // Z.debug(creators); + var zhnamesplit = Z.getHiddenPref('zhnamesplit'); + if (creator.search(/[A-Za-z]/) !== -1) { + creator = ZU.cleanAuthor(creator, "author"); + } + else { + creator = creator.replace(/\s/g, ''); + if ((zhnamesplit === undefined) ? true : zhnamesplit) { + // zhnamesplit is true, split firstname and lastname. + // Chinese name. first character is last name, the rest are first name + creator = { + "firstName": creator.substr(1), + "lastName": creator.charAt(0), + "creatorType": "author" + } + } + else { + creator = { + "lastName": creator, + "creatorType": "author" + } + } + } + return creator; +} + async function scrape(doc, url = doc.location.href) { let translator = Zotero.loadTranslator('web'); var pdfURL = ''; @@ -96,22 +123,8 @@ async function scrape(doc, url = doc.location.href) { translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48'); translator.setDocument(doc); translator.setHandler('itemDone', (_obj, item) => { - var zhnamesplit = Z.getHiddenPref('zhnamesplit'); - for (var i = 0, n = item.creators.length; i < n; i++) { - var creator = item.creators[i]; - if (creator.lastName.search(/[A-Za-z]/) !== -1) { - // western name. split on last space - creator.firstName = creator.lastName.substr(0, lastSpace); - creator.lastName = creator.lastName.substr(lastSpace + 1); - } - else if ((zhnamesplit === undefined) ? true : zhnamesplit) { - // zhnamesplit is true, split firstname and lastname. - // Chinese name. first character is last name, the rest are first name - creator.firstName = creator.lastName.substr(1); - creator.lastName = creator.lastName.charAt(0); - } - item.creators[i] = creator - } + item.creators = item.creators.map((creator) => (matchCreator(creator.lastName))); + item.language = (item.language == 'zh') ? 'zh-CN' : 'en-US'; item.attachments = [ { url: pdfURL, @@ -131,6 +144,7 @@ async function scrape(doc, url = doc.location.href) { em.itemType = 'journalArticle'; await em.doWeb(doc, url); } + /** BEGIN TEST CASES **/ var testCases = [ { From 30de174b8652b8328bf4d6b4d2586206cb0a51e3 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Tue, 17 Oct 2023 15:02:29 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E5=90=8D=E5=88=86=E5=89=B2=EF=BC=9B=E6=9B=B4=E6=96=B0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 70 +++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/RHHZ.js b/RHHZ.js index 3955e443..127d68b4 100644 --- a/RHHZ.js +++ b/RHHZ.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2023-10-16 02:08:06" + "lastUpdated": "2023-10-17 07:01:33" } /* @@ -77,27 +77,16 @@ async function doWeb(doc, url) { } function matchCreator(creator) { - // Z.debug(creators); - var zhnamesplit = Z.getHiddenPref('zhnamesplit'); + // Z.debug(creator); if (creator.search(/[A-Za-z]/) !== -1) { creator = ZU.cleanAuthor(creator, "author"); } else { creator = creator.replace(/\s/g, ''); - if ((zhnamesplit === undefined) ? true : zhnamesplit) { - // zhnamesplit is true, split firstname and lastname. - // Chinese name. first character is last name, the rest are first name - creator = { - "firstName": creator.substr(1), - "lastName": creator.charAt(0), - "creatorType": "author" - } - } - else { - creator = { - "lastName": creator, - "creatorType": "author" - } + creator = { + "lastName": creator, + "creatorType": "author", + "fieldMode": true } } return creator; @@ -145,6 +134,7 @@ async function scrape(doc, url = doc.location.href) { await em.doWeb(doc, url); } + /** BEGIN TEST CASES **/ var testCases = [ { @@ -156,29 +146,29 @@ var testCases = [ "title": "面向生态环境科技成果转化的产业基金研究及实践案例分析", "creators": [ { - "firstName": "茜", - "lastName": "曹", - "creatorType": "author" + "lastName": "曹茜", + "creatorType": "author", + "fieldMode": true }, { - "firstName": "雯", - "lastName": "周", - "creatorType": "author" + "lastName": "周雯", + "creatorType": "author", + "fieldMode": true }, { - "firstName": "东洋", - "lastName": "魏", - "creatorType": "author" + "lastName": "魏东洋", + "creatorType": "author", + "fieldMode": true }, { - "firstName": "丽杰", - "lastName": "段", - "creatorType": "author" + "lastName": "段丽杰", + "creatorType": "author", + "fieldMode": true }, { - "firstName": "曼", - "lastName": "洪", - "creatorType": "author" + "lastName": "洪曼", + "creatorType": "author", + "fieldMode": true } ], "date": "2023-08-20", @@ -186,7 +176,7 @@ var testCases = [ "ISSN": "1004-6216", "abstractNote": "生态环境科技专项产生了一大批高水准的生态环境科研成果以及专业技术,但这些成果都停留在科学阶段,尚未形成产品,发挥社会价值。目前,国内外已经有很多成功的生态环境产业基金,如美国的清洁水州周转基金和国内的深圳清华大学研究院的力合科创投资孵化基金以及南京扬子江生态文明创新中心的源创基金,可以作为研究案例。文章选取国际国内代表性的运营多年和新兴的产业基金案例,分析生态环境产业基金在产业化过程中发挥的作用,结合调研内容总结产业基金运行模式的特点,根据先进经验提出针对我国生态环境产业基金运行主要存在问题的相关建议。", "issue": "4", - "language": "zh", + "language": "zh-CN", "libraryCatalog": "www.hjbhkx.cn", "pages": "1-8", "publicationTitle": "环境保护科学", @@ -234,14 +224,14 @@ var testCases = [ "title": "宁夏退耕还林还草成果巩固问题探讨", "creators": [ { - "firstName": "治啸", - "lastName": "王", - "creatorType": "author" + "lastName": "王治啸", + "creatorType": "author", + "fieldMode": true }, { - "firstName": "红军", - "lastName": "高", - "creatorType": "author" + "lastName": "高红军", + "creatorType": "author", + "fieldMode": true } ], "date": "2023-03-30", @@ -250,7 +240,7 @@ var testCases = [ "abstractNote": "退耕还林还草是中共中央、国务院在20世纪末着眼中华民族长远发展和国家生态安全作出的重大决策。23年来的退耕还林还草工程实践取得了巨大的生态、经济和社会效益,赢得了社会各界赞誉。\"十四五\"以来,国家基于粮食安全和耕地保护考虑,已将工程重心转移到巩固已有建设成果上来。文中基于宁夏回族自治区退耕还林还草工程现状,总结退耕还林还草成果巩固的经验做法,梳理分析现存问题,并提出今后推动退耕还林还草高质量发展的建议:1)深挖后续产业发展潜力,促进\"以林养林\";2)合理优化退耕林地树种组成和植被配置模式,改善退耕林质量;3)提高生态效益补偿标准;4)稳定基层管理队伍。", "issue": "1", "journalAbbreviation": "lczcyj", - "language": "zh", + "language": "zh-CN", "libraryCatalog": "www.lczcyj.com", "pages": "18-23", "publicationTitle": "林草政策研究", From f2c6066bd709a6a60495ff7db0e0a4d7b5b1c205 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Sat, 21 Oct 2023 18:08:09 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/RHHZ.js b/RHHZ.js index 127d68b4..06356494 100644 --- a/RHHZ.js +++ b/RHHZ.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2023-10-17 07:01:33" + "lastUpdated": "2023-10-21 10:06:47" } /* @@ -124,8 +124,8 @@ async function scrape(doc, url = doc.location.href) { item.attachments.push({ url: url, document: doc, - title: 'Snapshot', - mimeType: 'text/html' + title: "Snapshot", + mimeType: "text/html" }) item.complete(); }); @@ -133,8 +133,6 @@ async function scrape(doc, url = doc.location.href) { em.itemType = 'journalArticle'; await em.doWeb(doc, url); } - - /** BEGIN TEST CASES **/ var testCases = [ { From 439d712dfe189b98e42263b0893b0089c7feee98 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai23 Date: Tue, 24 Oct 2023 18:18:49 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E9=80=9A=E8=BF=87ESLint=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RHHZ.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/RHHZ.js b/RHHZ.js index 06356494..ec9a84fd 100644 --- a/RHHZ.js +++ b/RHHZ.js @@ -36,7 +36,7 @@ */ -function detectWeb(doc, url) { +function detectWeb(doc, _url) { let insite = doc.querySelector('div[class*="foot"] p > a[href*="www.rhhz.net"]'); let itemID = doc.querySelector('meta[name="citation_id"]'); if (insite && itemID) { @@ -78,16 +78,16 @@ async function doWeb(doc, url) { function matchCreator(creator) { // Z.debug(creator); - if (creator.search(/[A-Za-z]/) !== -1) { - creator = ZU.cleanAuthor(creator, "author"); + if (/[A-Za-z]/.test(creator)) { + creator = ZU.cleanAuthor(creator, 'author'); } else { creator = creator.replace(/\s/g, ''); creator = { - "lastName": creator, - "creatorType": "author", - "fieldMode": true - } + lastName: creator, + creatorType: 'author', + fieldMode: 1 + }; } return creator; } @@ -102,17 +102,18 @@ async function scrape(doc, url = doc.location.href) { } else if (pdfButton) { pdfURL = pdfButton.parentElement.href; - } else { + } + else { let id = doc.querySelector('head > meta[name="citation_id"]').content; let host = (new URL(url)).host; - pdfURL = `${url.split('//')[0]}//${host}/article/exportPdf?id=${id}` + pdfURL = `${url.split('//')[0]}//${host}/article/exportPdf?id=${id}`; } Z.debug(pdfURL); // Embedded Metadata translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48'); translator.setDocument(doc); translator.setHandler('itemDone', (_obj, item) => { - item.creators = item.creators.map((creator) => (matchCreator(creator.lastName))); + item.creators = item.creators.map(creator => (matchCreator(creator.lastName))); item.language = (item.language == 'zh') ? 'zh-CN' : 'en-US'; item.attachments = [ { @@ -126,13 +127,14 @@ async function scrape(doc, url = doc.location.href) { document: doc, title: "Snapshot", mimeType: "text/html" - }) + }); item.complete(); }); let em = await translator.getTranslatorObject(); em.itemType = 'journalArticle'; await em.doWeb(doc, url); } + /** BEGIN TEST CASES **/ var testCases = [ {