Skip to content

Commit 864b7a8

Browse files
committed
Add google scholar (from @WenyanLiu)
1 parent 5243fba commit 864b7a8

File tree

4 files changed

+218
-1
lines changed

4 files changed

+218
-1
lines changed

manifest.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,84 @@
2525
"https://dblp.uni-trier.de/*",
2626
"https://dblp2.uni-trier.de/*",
2727
"https://dblp.dagstuhl.de/*",
28+
"https://scholar.google.ae/*",
29+
"https://scholar.google.at/*",
30+
"https://scholar.google.be/*",
31+
"https://scholar.google.bg/*",
32+
"https://scholar.google.ca/*",
33+
"https://scholar.google.cat/*",
34+
"https://scholar.google.ch/*",
35+
"https://scholar.google.cl/*",
36+
"https://scholar.google.co.cr/*",
37+
"https://scholar.google.co.hu/*",
38+
"https://scholar.google.co.id/*",
39+
"https://scholar.google.co.il/*",
40+
"https://scholar.google.co.in/*",
41+
"https://scholar.google.co.jp/*",
42+
"https://scholar.google.co.kr/*",
43+
"https://scholar.google.co.nz/*",
44+
"https://scholar.google.co.th/*",
45+
"https://scholar.google.co.uk/*",
46+
"https://scholar.google.co.ve/*",
47+
"https://scholar.google.co.za/*",
48+
"https://scholar.google.com/*",
49+
"https://scholar.google.com.ar/*",
50+
"https://scholar.google.com.au/*",
51+
"https://scholar.google.com.bo/*",
52+
"https://scholar.google.com.br/*",
53+
"https://scholar.google.com.co/*",
54+
"https://scholar.google.com.cu/*",
55+
"https://scholar.google.com.do/*",
56+
"https://scholar.google.com.ec/*",
57+
"https://scholar.google.com.eg/*",
58+
"https://scholar.google.com.gr/*",
59+
"https://scholar.google.com.gt/*",
60+
"https://scholar.google.com.hk/*",
61+
"https://scholar.google.com.ly/*",
62+
"https://scholar.google.com.mx/*",
63+
"https://scholar.google.com.my/*",
64+
"https://scholar.google.com.ni/*",
65+
"https://scholar.google.com.pa/*",
66+
"https://scholar.google.com.pe/*",
67+
"https://scholar.google.com.ph/*",
68+
"https://scholar.google.com.pk/*",
69+
"https://scholar.google.com.pl/*",
70+
"https://scholar.google.com.pr/*",
71+
"https://scholar.google.com.py/*",
72+
"https://scholar.google.com.ru/*",
73+
"https://scholar.google.com.sg/*",
74+
"https://scholar.google.com.sv/*",
75+
"https://scholar.google.com.tr/*",
76+
"https://scholar.google.com.tw/*",
77+
"https://scholar.google.com.ua/*",
78+
"https://scholar.google.com.uy/*",
79+
"https://scholar.google.com.vn/*",
80+
"https://scholar.google.cz/*",
81+
"https://scholar.google.de/*",
82+
"https://scholar.google.dk/*",
83+
"https://scholar.google.es/*",
84+
"https://scholar.google.fi/*",
85+
"https://scholar.google.fr/*",
86+
"https://scholar.google.gr/*",
87+
"https://scholar.google.hk/*",
88+
"https://scholar.google.hn/*",
89+
"https://scholar.google.hr/*",
90+
"https://scholar.google.hu/*",
91+
"https://scholar.google.is/*",
92+
"https://scholar.google.it/*",
93+
"https://scholar.google.li/*",
94+
"https://scholar.google.lt/*",
95+
"https://scholar.google.lu/*",
96+
"https://scholar.google.lv/*",
97+
"https://scholar.google.nl/*",
98+
"https://scholar.google.no/*",
99+
"https://scholar.google.pl/*",
100+
"https://scholar.google.pt/*",
101+
"https://scholar.google.ro/*",
102+
"https://scholar.google.ru/*",
103+
"https://scholar.google.se/*",
104+
"https://scholar.google.si/*",
105+
"https://scholar.google.sk/*",
28106
"https://link.springer.com/search*",
29107
"https://www.engineeringvillage.com/search*"
30108
],
@@ -37,6 +115,7 @@
37115
"site/ieee.js",
38116
"site/dblp.js",
39117
"site/springer.js",
118+
"site/scholar.js",
40119
"data/ccf-index.js",
41120
"data/ccf-rank.js",
42121
"script.js"

ranking/ccf.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ ccf.getRankingInfo = function(names){
2525
ranking = rank + '?';
2626
}
2727
}
28+
} else if (ranking == undefined){
29+
ranking = 'none';
2830
} else {
2931
rankingInfo.info += name.full + ": CCF " + ranking + "\n"
3032
}
3133
rankingInfo.rankings.push(ranking);
3234
}
35+
if(rankingInfo.info.length == 0) {
36+
rankingInfo.info = "not found"
37+
}
3338
return rankingInfo;
3439
}
3540

3641
ccf.getRankingClass = function (rankings){
3742
for(let ranking of 'ABC'){
3843
for(let result of rankings){
39-
if(result[0] == ranking){
44+
if(result != undefined && result[0] == ranking){
4045
return 'ccf-' + ranking.toLowerCase();
4146
}
4247
}

script.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ if(location.href.startsWith("https://ieeexplore.ieee.org/search/searchresult.jsp
1414
} else if(location.href.startsWith("https://www.engineeringvillage.com/search")){
1515
ei.rankingSpanProvider.push(ccf.getRankingSpan);
1616
ei.start();
17+
} else if (location.hostname.startsWith("scholar.google")) {
18+
ccf.custom2rank = dblp.uri2rank
19+
scholar.rankSpanList.push(ccf.getRankingSpan)
20+
scholar.run();
1721
}

site/scholar.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* Based on https://github.com/WenyanLiu/CCFrank4dblp/blob/704960f95393fdcacdd5f71864f3768518a9fb2a/js/scholar.js
3+
*
4+
* MIT License
5+
*
6+
* Copyright (c) 2019 wyliu
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
27+
const scholar = {};
28+
29+
scholar.rankSpanList = [];
30+
31+
scholar.run = function () {
32+
let url = window.location.pathname;
33+
if (url == "/scholar") {
34+
scholar.appendRank();
35+
} else if (url == "/citations") {
36+
setInterval(function () {
37+
$(window).bind("popstate", function () {
38+
scholar.appendRanks();
39+
});
40+
scholar.appendRanks();
41+
}, 2000);
42+
}
43+
};
44+
45+
scholar.appendRank = function () {
46+
let elements = $("#gs_res_ccl_mid > div > div.gs_ri");
47+
elements.each(function () {
48+
let node = $(this).find("h3 > a");
49+
let title = node.text().replace(/[^A-z]/g, " ");
50+
let data = $(this)
51+
.find("div.gs_a")
52+
.text()
53+
.replace(/[\,\-\…]/g, "")
54+
.split(" ");
55+
let author = data[1];
56+
let year = data.slice(-3)[0];
57+
fetchRank(node, title, author, year);
58+
});
59+
};
60+
61+
scholar.appendRanks = function () {
62+
let elements = $("tr.gsc_a_tr");
63+
elements.each(function () {
64+
let node = $(this).find("td.gsc_a_t > a");
65+
if (!node.next().hasClass("ccf-rank")) {
66+
let title = node.text().replace(/[^A-z]/g, " ");
67+
let author = $(this)
68+
.find("div.gs_gray")
69+
.text()
70+
.replace(/[\,\…]/g, "")
71+
.split(" ")[1];
72+
let year = $(this).find("td.gsc_a_y").text();
73+
fetchRank(node, title, author, year);
74+
}
75+
});
76+
};
77+
78+
function fetchRank(node, title, author, year) {
79+
var xhr = new XMLHttpRequest();
80+
api_format = "https://dblp.org/search/publ/api?q=" + encodeURIComponent(title + " " + author) + "&format=json";
81+
xhr.open("GET", api_format, true);
82+
xhr.onreadystatechange = function () {
83+
if (xhr.readyState == 4) {
84+
var dblp_url = "";
85+
var resp = JSON.parse(xhr.responseText).result.hits;
86+
if (resp["@total"] == 0) {
87+
dblp_url == "";
88+
} else if (resp["@total"] == 1) {
89+
url = resp.hit[0].info.url;
90+
dblp_url = url.substring(
91+
url.indexOf("/rec/") + 5,
92+
url.lastIndexOf("/")
93+
);
94+
} else {
95+
for (var h = 0; h < resp["@total"]; h++) {
96+
info = resp.hit[h].info
97+
author_1st = info.authors.author[0].text;
98+
year_fuzzy = info.year;
99+
year_last_check = 0;
100+
if (Math.abs(Number(year) - year_fuzzy) <= 1
101+
&& author_1st.toLowerCase().split(" ").indexOf(author.toLowerCase()) != -1
102+
&& year_fuzzy != year_last_check) {
103+
year_last_check = year_fuzzy;
104+
url = resp.hit[h].info.url;
105+
dblp_url_last_check = url.substring(
106+
url.indexOf("/rec/") + 5,
107+
url.lastIndexOf("/")
108+
);
109+
if (year_fuzzy == year + 1) {
110+
dblp_url = dblp_url_last_check;
111+
} else if (year_fuzzy == year) {
112+
dblp_url = dblp_url_last_check;
113+
break;
114+
} else {
115+
if (dblp_url == "") {
116+
dblp_url = dblp_url_last_check;
117+
};
118+
}
119+
}
120+
}
121+
}
122+
const names = [{uri: dblp_url}];
123+
for (let getRankSpan of scholar.rankSpanList) {
124+
$(node).after(getRankSpan(names));
125+
}
126+
}
127+
};
128+
xhr.send();
129+
};

0 commit comments

Comments
 (0)