Skip to content

Commit

Permalink
更新为0.94,修改正则表达式,xpath等,修复不能获取影响因子及分区。
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed Oct 25, 2022
1 parent 1899ceb commit 443e189
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 53 deletions.
125 changes: 76 additions & 49 deletions chrome/content/scripts/zoteroupdateifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,6 @@ Zotero.UpdateIFs.updateSelectedItem = async function (items) {
};




// 得到影响因子及详细网址函数
Zotero.UpdateIFs.getIFs = async function (item) {
var ifs = [];
Expand Down Expand Up @@ -706,29 +704,47 @@ Zotero.UpdateIFs.getIFs = async function (item) {
// var ifCurrent = jour[6];

//新函数结束
// var xPathJour = '//*[@id="app"]/div[1]/div/div[1]'; // 20221023为得到期刊名称
var xPathJour = "//table[@class='tb1']"; // 20221023为得到期刊名称 小林的xPath

var xPathJour = '//div[2]/div[1]/table[2]/tbody'; // 为得到期刊名称
// var xPathJour = '//div[2]/div[1]/table[2]/tbody'; // 为得到期刊名称
// var xPathJour = '//td[contains(text(),'Annu')]/..'

var AllJour = Zotero.Utilities.xpath(html, xPathJour)[0].innerText;
var AllJour = Zotero.Utilities.xpath(html, xPathJour)[0].textContent;
var publicationTitle = item.getField('publicationTitle');
var reg = '\n\t(.*)\n\t' + publicationTitle + // 分组1序号
'\n\t(.*)\n\t(.*)' + // 分组3 ISSN,分组4文章数
'\n\t(.*)\n\t(.*)' + //分组5 5年平均分, 分组6 非自引分
'\n\t(.*)\n\t(.*)'; // 分组7 影响因子
// 20221023 修改
var reg = '(\\d+)\n\\s+' + publicationTitle + // 分组1 序号
'\\s+\n\\s+' + '(.*)' + // 分组2 缩写
'\\s+' + '(.*)' + // 分组3 ISSN
'\\s+' + '(.*)' + //分组4文章数
'\\s+' + '(.*)' + //分组5 5年平均分
'\\s+' + '(.*)' + //分组6 非自引分
'\\s+' + '(.*)'; //分组7 影响因子
// 20221023 注释
// var reg = '\n\t(.*)\n\t' + publicationTitle + // 分组1序号
// '\n\t(.*)\n\t(.*)' + // 分组3 ISSN,分组4文章数
// '\n\t(.*)\n\t(.*)' + //分组5 5年平均分, 分组6 非自引分
// '\n\t(.*)\n\t(.*)'; // 分组7 影响因子
var patt = new RegExp(reg, 'i'); //
var jour = AllJour.match(patt);

var abbr = Zotero.UpdateIFs.titleCase(jour[2]); // 转为首字母大写
var if5Year = jour[5];
var ifCurrent = jour[7];


var xPathUrl = '//div[2]/div[1]/table[2]/tbody//@href'; // 为得到详情URL
var index = jour[1] - 1;
var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl);
var detailURL = 'http://sci.justscience.cn/' + detailURLPre[index].value;
var regAbbr = '\n\t' + publicationTitle + '\n.(.*)'; // 用于得到期刊缩写
var abbr = AllJour.match(regAbbr)[1]; // 匹配得到期刊缩写
var xPathUrl = "//table[@class='tb1']//a[contains(concat(' ', normalize-space(text()), ' '), ' " +
publicationTitle +
" ')]"; // 20221024 可用 小林的xPath,为得到详情URL

// var xPathUrl = "//a[contains(text(),'Meat Science')]"
// var xPathUrl = xPathJour + '//@href'; // 为得到详情URL 可用 20231024 需要用到index
// var index = Number(jour[1]) + 3; // 20221024
// var index = jour[1] + 3;
// var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl); // 20221024
// var detailURL = 'http://sci.justscience.cn/' + detailURLPre[index].value;//20221024
var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl)[0].href; // 20221024
var detailURL = 'http://sci.justscience.cn/' + detailURLPre; // 20221024
// var regAbbr = '\n\t' + publicationTitle + '\n.(.*)'; // 用于得到期刊缩写
// var abbr = AllJour.match(regAbbr)[1]; // 匹配得到期刊缩写

ifs.push(if5Year, ifCurrent, detailURL, abbr)
return ifs;
Expand All @@ -740,31 +756,32 @@ Zotero.UpdateIFs.getIFs = async function (item) {
try { // 期刊名字中有&的情况
var html = await Zotero.UpdateIFs.getHtml(item);

var xPathJour = '//div[2]/div[1]/table[2]/tbody'; // 为得到期刊名称
var xPathJour = "//table[@class='tb1']"; // 为得到期刊名称

var AllJour = Zotero.Utilities.xpath(html, xPathJour)[0].innerText;
var AllJour = Zotero.Utilities.xpath(html, xPathJour)[0].textContent;
var publicationTitle = item.getField('publicationTitle').
replace(/&/g, 'and'). // 替换&为and
replace(/ - /g, '-').
replace(/,/g, ''). // 替换逗号(,)
replace(/: /g, '-'); // 替换冒号空格(:) 全局替换代码源于@crazyi
var reg = '\n\t(.*)\n\t' + publicationTitle + // 分组1序号
'\n\t(.*)\n\t(.*)' + // 分组3 ISSN,分组4文章数
'\n\t(.*)\n\t(.*)' + //分组5 5年平均分, 分组6 非自引分
'\n\t(.*)\n\t(.*)'; // 分组7 影响因子
var reg = '(\\d+)\n\\s+' + publicationTitle + // 分组1 序号
'\\s+\n\\s+' + '(.*)' + // 分组2 缩写
'\\s+' + '(.*)' + // 分组3 ISSN
'\\s+' + '(.*)' + //分组4文章数
'\\s+' + '(.*)' + //分组5 5年平均分
'\\s+' + '(.*)' + //分组6 非自引分
'\\s+' + '(.*)'; //分组7 影响因子
var patt = new RegExp(reg, 'i'); //
var jour = AllJour.match(patt);

var abbr = Zotero.UpdateIFs.titleCase(jour[2]); // 转为首字母大写
var if5Year = jour[5];
var ifCurrent = jour[7];


var xPathUrl = '//div[2]/div[1]/table[2]/tbody//@href'; // 为得到详情URL
var index = jour[1] - 1;
var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl);
var detailURL = 'http://sci.justscience.cn/' + detailURLPre[index].value;
var regAbbr = '\n\t' + publicationTitle + '\n.(.*)'; // 用于得到期刊缩写
var abbr = AllJour.match(regAbbr)[1]; // 匹配得到期刊缩写
var xPathUrl = "//table[@class='tb1']//a[contains(concat(' ', normalize-space(text()), ' '), ' " +
publicationTitle +
" ')]";
var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl)[0].href; // 20221024
var detailURL = 'http://sci.justscience.cn/' + detailURLPre; // 20221024

ifs.push(if5Year, ifCurrent, detailURL, abbr)
// ifs.push(if5Year, ifCurrent, detailURL)
Expand All @@ -776,33 +793,37 @@ Zotero.UpdateIFs.getIFs = async function (item) {
try { // 更名或剔除情况
var html = await Zotero.UpdateIFs.getHtml(item);

var xPathJour = '//div[2]/div[1]/table[2]/tbody'; // 为得到期刊名称
var xPathJour = "//table[@class='tb1']"; // 为得到期刊名称

var AllJour = Zotero.Utilities.xpath(html, xPathJour)[0].innerText;
var AllJour = Zotero.Utilities.xpath(html, xPathJour)[0].textContent;
var publicationTitle = item.getField('publicationTitle').
replace('&', 'and').
replace(' - ', '-');
var reg = '\n\t(.*)\n\t' + publicationTitle + '(更名\/剔除)(.*)' + // 分组1序号
'\n\t(.*)\n\t(.*)' + // 分组7 ISSN,分组8文章数
'\n\t(.*)\n\t(.*)' + //分组7 5年平均分, 分组6 非自引分
'\n\t(.*)\n\t(.*)'; // 分组9 影响因子
var reg = '(\\d+)\n\\s+' + publicationTitle + '(更名\/剔除)(.*)' + // 分组1序号 后面还有两个分组
'\\s+\n\\s+' + '(.*)' + // 分组4 缩写
'\\s+' + '(.*)' + // 分组3 ISSN
'\\s+' + '(.*)' + //分组6文章数
'\\s+' + '(.*)' + //分组7 5年平均分
'\\s+' + '(.*)' + //分组8 非自引分
'\\s+' + '(.*)'; //分组9 影响因子
var patt = new RegExp(reg, 'i'); //
var jour = AllJour.match(patt);


var abbr = Zotero.UpdateIFs.titleCase(jour[4]); // 转为首字母大写
var if5Year = jour[7];
var ifCurrent = jour[9];

var xPathUrl = "//table[@class='tb1']//a[contains(concat(' ', normalize-space(text()), ' '), ' " +
publicationTitle +
" ')]";
var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl)[0].href; // 20221024
var detailURL = 'http://sci.justscience.cn/' + detailURLPre; // 20221024

var xPathUrl = '//div[2]/div[1]/table[2]/tbody//@href'; // 为得到详情URL
var index = jour[1] - 1;
var detailURLPre = Zotero.Utilities.xpath(html, xPathUrl);
var detailURL = 'http://sci.justscience.cn/' + detailURLPre[index].value;
var regAbbr = '\n\t' + publicationTitle + '(更名\/剔除)\n.(.*)';// 用于得到期刊缩写
//var regAbbr = /\t{2}\n.*\n.*\n.(.*)/;
var abbr = AllJour.match(regAbbr)[2]; // 匹配得到期刊缩写
ifs.push(if5Year, ifCurrent, detailURL, abbr)

ifs.push(if5Year, ifCurrent, detailURL, abbr);
return ifs;

} catch (error) {
// numFail = numFail + 1;
}
Expand Down Expand Up @@ -933,14 +954,20 @@ Zotero.UpdateIFs.generateJCR = async function (detailURL) {
);


var xPath2 = '//table[3]';
var pattJCR2 = /JCR分区(.*)|大类\n.(.*)\n{3}.小类\n.(.*)/g
// var xPath2 = '//table[3]'; // 20221024
// var xPath2 = "//td[contains(text(), 'JCR')]/../.."; // 20221024
// var xPath2 = "//div[@class='detail-table']"; // 20221024
var xPath2 = "//table[@class='tb1']"; // 20221024 来自林 //div[@class='detail-table']
var jourJCR = Zotero.Utilities.xpath(html, xPath2)[0].innerText;

// var pattJCR2 = /JCR分区(.*)|大类\n.(.*)\n{3}.小类\n.(.*)/g // 20221025
var pattJCR2 = /JCR分区(.*)|大类\n.(.*)\n\s*小类\n\s*(.*)/g // 20221025
var getJCR = jourJCR.match(pattJCR2);
var qu = getJCR[0].match('JCR分区(.*)')[1].replace(/\/以上面为准/g, '');
var basic21 = getJCR[1].match('大类\n\t(.*)\n\n\n\t小类\n\t(.*)');
var update21 = getJCR[2].match('大类\n\t(.*)\n\n\n\t小类\n\t(.*)');

// var basic21 = getJCR[1].match('大类\n\t(.*)\n\n\n\t小类\n\t(.*)');
// var update21 = getJCR[2].match('大类\n\t(.*)\n\n\n\t小类\n\t(.*)');
var basic21 = getJCR[1].match(/大类\n\s+(.*)\n\s+小类\n\s+(.*)/); // 20221025
var update21 = getJCR[2].match(/大类\n\s+(.*)\n\s+小类\n\s+(.*)/); // 20221025
var firstCat = ifsType == 'updated' ? update21[1] : basic21[1]; // 大类:如果为升级版为updated,否则为基础版
var secCat = ifsType == 'updated' ? update21[2].replace(//g, '区 ') : basic21[2].replace(//g, '区 '); // 大类:如果为升级版为updated,否则为基础版,并且将区替换为区;,以美化
JCR.push(qu, firstCat, secCat);
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RDF:about="urn:mozilla:install-manifest"
em:id="[email protected]"
em:name="Zotero Update IFs"
em:version="0.93.5"
em:version="0.94"
em:type="2"
em:creator="Minyi Han"
em:description="Zotero plugin for update IF from http://sci.justscience.cn/"
Expand Down
6 changes: 3 additions & 3 deletions update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<em:version>0.93.5</em:version>
<em:version>0.94</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
<em:minVersion>5.0.0</em:minVersion>
<em:maxVersion>6.*</em:maxVersion>
<em:updateLink>https://github.com/redleafnew/zotero-updateifs/releases/download/0.93.5/zotero-updateifs.xpi</em:updateLink>
<em:updateLink>https://github.com/redleafnew/zotero-updateifs/releases/download/0.94/zotero-updateifs.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>

Expand All @@ -21,7 +21,7 @@
<em:id>[email protected]</em:id>
<em:minVersion>4.999</em:minVersion>
<em:maxVersion>6.*</em:maxVersion>
<em:updateLink>https://github.com/redleafnew/zotero-updateifs/releases/download/0.93.5/zotero-updateifs.xpi</em:updateLink>
<em:updateLink>https://github.com/redleafnew/zotero-updateifs/releases/download/0.94/zotero-updateifs.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>

Expand Down

0 comments on commit 443e189

Please sign in to comment.