Skip to content

Instantly share code, notes, and snippets.

@RayBB
Created November 1, 2017 15:03
Show Gist options
  • Save RayBB/6e9da6cadb05deea89daa82b56c624c0 to your computer and use it in GitHub Desktop.
Save RayBB/6e9da6cadb05deea89daa82b56c624c0 to your computer and use it in GitHub Desktop.
Adds citation count next to references and citations on ACM Digital Library
/* Created by Ray Berger https://github.com/RayBB/
This program works on the ACM digital library.
When looking looking at the references or cited by tab for any article, simply paste this code into the console.
It will put the number of citations next to each refence.
*/
function getURL(url, row) {
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var resp = request.responseText;
let citations = getCitationCount(resp);
row.innerHTML += "<td>" + citations + "</td>";
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
console.log("There was a connection error of some sort");
};
request.send();
}
function getCitationCount(body) {
let word = body.match(/Citation Count: \d*/)[0];
word = word.match(/\d+/);
return word;
}
function start() {
let table = $("#references > div > table > tbody");
if (table == null) {
table = $("#citedby > div > table > tbody");
}
let limit = table.children.length;
for (let i = 0; i < limit; i++) {
let row = table.children[i];
try { // try/catch is needed because not all rows in tables have links
let url = row.querySelector("a").href;
getURL(url, row);
} catch (err) {
console.log(err);
}
}
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment