Skip to content

Commit

Permalink
Add google scholar (from @WenyanLiu)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnshhslsh committed May 30, 2021
1 parent 5243fba commit 864b7a8
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 1 deletion.
79 changes: 79 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,84 @@
"https://dblp.uni-trier.de/*",
"https://dblp2.uni-trier.de/*",
"https://dblp.dagstuhl.de/*",
"https://scholar.google.ae/*",
"https://scholar.google.at/*",
"https://scholar.google.be/*",
"https://scholar.google.bg/*",
"https://scholar.google.ca/*",
"https://scholar.google.cat/*",
"https://scholar.google.ch/*",
"https://scholar.google.cl/*",
"https://scholar.google.co.cr/*",
"https://scholar.google.co.hu/*",
"https://scholar.google.co.id/*",
"https://scholar.google.co.il/*",
"https://scholar.google.co.in/*",
"https://scholar.google.co.jp/*",
"https://scholar.google.co.kr/*",
"https://scholar.google.co.nz/*",
"https://scholar.google.co.th/*",
"https://scholar.google.co.uk/*",
"https://scholar.google.co.ve/*",
"https://scholar.google.co.za/*",
"https://scholar.google.com/*",
"https://scholar.google.com.ar/*",
"https://scholar.google.com.au/*",
"https://scholar.google.com.bo/*",
"https://scholar.google.com.br/*",
"https://scholar.google.com.co/*",
"https://scholar.google.com.cu/*",
"https://scholar.google.com.do/*",
"https://scholar.google.com.ec/*",
"https://scholar.google.com.eg/*",
"https://scholar.google.com.gr/*",
"https://scholar.google.com.gt/*",
"https://scholar.google.com.hk/*",
"https://scholar.google.com.ly/*",
"https://scholar.google.com.mx/*",
"https://scholar.google.com.my/*",
"https://scholar.google.com.ni/*",
"https://scholar.google.com.pa/*",
"https://scholar.google.com.pe/*",
"https://scholar.google.com.ph/*",
"https://scholar.google.com.pk/*",
"https://scholar.google.com.pl/*",
"https://scholar.google.com.pr/*",
"https://scholar.google.com.py/*",
"https://scholar.google.com.ru/*",
"https://scholar.google.com.sg/*",
"https://scholar.google.com.sv/*",
"https://scholar.google.com.tr/*",
"https://scholar.google.com.tw/*",
"https://scholar.google.com.ua/*",
"https://scholar.google.com.uy/*",
"https://scholar.google.com.vn/*",
"https://scholar.google.cz/*",
"https://scholar.google.de/*",
"https://scholar.google.dk/*",
"https://scholar.google.es/*",
"https://scholar.google.fi/*",
"https://scholar.google.fr/*",
"https://scholar.google.gr/*",
"https://scholar.google.hk/*",
"https://scholar.google.hn/*",
"https://scholar.google.hr/*",
"https://scholar.google.hu/*",
"https://scholar.google.is/*",
"https://scholar.google.it/*",
"https://scholar.google.li/*",
"https://scholar.google.lt/*",
"https://scholar.google.lu/*",
"https://scholar.google.lv/*",
"https://scholar.google.nl/*",
"https://scholar.google.no/*",
"https://scholar.google.pl/*",
"https://scholar.google.pt/*",
"https://scholar.google.ro/*",
"https://scholar.google.ru/*",
"https://scholar.google.se/*",
"https://scholar.google.si/*",
"https://scholar.google.sk/*",
"https://link.springer.com/search*",
"https://www.engineeringvillage.com/search*"
],
Expand All @@ -37,6 +115,7 @@
"site/ieee.js",
"site/dblp.js",
"site/springer.js",
"site/scholar.js",
"data/ccf-index.js",
"data/ccf-rank.js",
"script.js"
Expand Down
7 changes: 6 additions & 1 deletion ranking/ccf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ ccf.getRankingInfo = function(names){
ranking = rank + '?';
}
}
} else if (ranking == undefined){
ranking = 'none';
} else {
rankingInfo.info += name.full + ": CCF " + ranking + "\n"
}
rankingInfo.rankings.push(ranking);
}
if(rankingInfo.info.length == 0) {
rankingInfo.info = "not found"
}
return rankingInfo;
}

ccf.getRankingClass = function (rankings){
for(let ranking of 'ABC'){
for(let result of rankings){
if(result[0] == ranking){
if(result != undefined && result[0] == ranking){
return 'ccf-' + ranking.toLowerCase();
}
}
Expand Down
4 changes: 4 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ if(location.href.startsWith("https://ieeexplore.ieee.org/search/searchresult.jsp
} else if(location.href.startsWith("https://www.engineeringvillage.com/search")){
ei.rankingSpanProvider.push(ccf.getRankingSpan);
ei.start();
} else if (location.hostname.startsWith("scholar.google")) {
ccf.custom2rank = dblp.uri2rank
scholar.rankSpanList.push(ccf.getRankingSpan)
scholar.run();
}
129 changes: 129 additions & 0 deletions site/scholar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* Based on https://github.com/WenyanLiu/CCFrank4dblp/blob/704960f95393fdcacdd5f71864f3768518a9fb2a/js/scholar.js
*
* MIT License
*
* Copyright (c) 2019 wyliu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const scholar = {};

scholar.rankSpanList = [];

scholar.run = function () {
let url = window.location.pathname;
if (url == "/scholar") {
scholar.appendRank();
} else if (url == "/citations") {
setInterval(function () {
$(window).bind("popstate", function () {
scholar.appendRanks();
});
scholar.appendRanks();
}, 2000);
}
};

scholar.appendRank = function () {
let elements = $("#gs_res_ccl_mid > div > div.gs_ri");
elements.each(function () {
let node = $(this).find("h3 > a");
let title = node.text().replace(/[^A-z]/g, " ");
let data = $(this)
.find("div.gs_a")
.text()
.replace(/[\,\-\…]/g, "")
.split(" ");
let author = data[1];
let year = data.slice(-3)[0];
fetchRank(node, title, author, year);
});
};

scholar.appendRanks = function () {
let elements = $("tr.gsc_a_tr");
elements.each(function () {
let node = $(this).find("td.gsc_a_t > a");
if (!node.next().hasClass("ccf-rank")) {
let title = node.text().replace(/[^A-z]/g, " ");
let author = $(this)
.find("div.gs_gray")
.text()
.replace(/[\,\…]/g, "")
.split(" ")[1];
let year = $(this).find("td.gsc_a_y").text();
fetchRank(node, title, author, year);
}
});
};

function fetchRank(node, title, author, year) {
var xhr = new XMLHttpRequest();
api_format = "https://dblp.org/search/publ/api?q=" + encodeURIComponent(title + " " + author) + "&format=json";
xhr.open("GET", api_format, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
var dblp_url = "";
var resp = JSON.parse(xhr.responseText).result.hits;
if (resp["@total"] == 0) {
dblp_url == "";
} else if (resp["@total"] == 1) {
url = resp.hit[0].info.url;
dblp_url = url.substring(
url.indexOf("/rec/") + 5,
url.lastIndexOf("/")
);
} else {
for (var h = 0; h < resp["@total"]; h++) {
info = resp.hit[h].info
author_1st = info.authors.author[0].text;
year_fuzzy = info.year;
year_last_check = 0;
if (Math.abs(Number(year) - year_fuzzy) <= 1
&& author_1st.toLowerCase().split(" ").indexOf(author.toLowerCase()) != -1
&& year_fuzzy != year_last_check) {
year_last_check = year_fuzzy;
url = resp.hit[h].info.url;
dblp_url_last_check = url.substring(
url.indexOf("/rec/") + 5,
url.lastIndexOf("/")
);
if (year_fuzzy == year + 1) {
dblp_url = dblp_url_last_check;
} else if (year_fuzzy == year) {
dblp_url = dblp_url_last_check;
break;
} else {
if (dblp_url == "") {
dblp_url = dblp_url_last_check;
};
}
}
}
}
const names = [{uri: dblp_url}];
for (let getRankSpan of scholar.rankSpanList) {
$(node).after(getRankSpan(names));
}
}
};
xhr.send();
};

0 comments on commit 864b7a8

Please sign in to comment.