-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverlay.user.js
67 lines (61 loc) · 2.25 KB
/
overlay.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ==UserScript==
// @name Google Scholar Credibility Overlay
// @namespace http://rhok.org/
// @description reputation annotation for scientific search results
// @include http://scholar.google.tld/scholar*
// @include http://scholar.google.com/scholar*
// @include http://scholar.google.de/scholar*
// @run-at document-end
// ==/UserScript==
SERVICE = "http://localhost:8000/"
function getScore(author, title, callback) {
GM_xmlhttpRequest({
method: "POST",
url: SERVICE + "score",
data: "author=" + escape(author) + "&title=" + escape(title),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "text/plain"
},
onload: callback
});
}
var p = document.getElementById("scife_hdr").getElementsByTagName("a")[1].parentElement;
p.appendChild(document.createElement("br"));
var navlink = document.createElement("a");
navlink.setAttribute("href", SERVICE + "search?q=" +
escape(document.getElementsByName("q")[0].value.replace(" ", "+")));
navlink.appendChild(document.createTextNode("Climate Goggles"));
p.appendChild(navlink);
var nodes = document.getElementsByClassName("gs_r");
var completed = 0;
function finish() {
for (var i = 0; i < nodes.length; i++) {
for (var j = 0; j < nodes.length-1; j++) {
cur = nodes[j]; next = nodes[j+1];
if (cur.getAttribute("score") < next.getAttribute("score")) {
next.parentElement.removeChild(next);
cur.parentElement.insertBefore(next, cur);
}
}
}
}
for (var i = 0; i < nodes.length; i++) {
(function(){
var article = nodes[i];
var meta = article.getElementsByClassName("gs_a")[0];
var desc = meta.textContent;
var author = desc.substring(0, desc.indexOf("…"));
var title = article.getElementsByTagName("h3")[0].textContent;
getScore(author, title, function(response) {
completed += 1;
var score = parseInt(response.responseText);
article.setAttribute("score", score);
if (nodes.length == completed) {
finish();
}
meta.appendChild(
document.createTextNode(" - Credibility: " + score + "% "));
});
})();
}