-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpubpeer_fetcher.js
112 lines (88 loc) · 2.51 KB
/
pubpeer_fetcher.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function get_host(hostname){
for(i in ae_hosts["names"])
if(hostname.indexOf(ae_hosts["names"][i]) != -1)
return ae_hosts["names"][i];
}
function get_title_element(hostname){
var title = null;
var host = get_host(hostname);
var command = "";
for(i in ae_hosts[host])
command += ae_hosts[host][i] + "\n";
if(command.length > 0)
title = eval(command);
return title;
}
function Identifier () {
this.id = null;
this.type = null;
var doi = null;
var pmid = null;
var arxiv = null;
// we assume that DOI's are always in a <meta name="citation_doi"> tag
var meta = document.getElementsByTagName('meta');
for(var i=0; i<meta.length; i++){
if(meta[i].name == "citation_doi"){
doi = meta[i].content;
}
}
if(doi){
this.id = doi;
this.type = "doi";
return this;
}
if (!doi) {
var dd = document.getElementsByTagName('dd');
try{
pmid = dd[0].innerHTML;
} catch(err) {
}
if(pmid){
this.id = pmid;
this.type = "pmid";
return this;
}
}
if(!doi && !pmid){
var meta = document.getElementsByName('citation_arxiv_id')[0];
arxiv = meta.content;
if(arxiv){
this.id = arxiv;
this.type = "arxiv";
return this;
}
}
return null;
}
var title = null;
var hostname = window.location.hostname;
var identifier = new Identifier();
if(identifier)
title = get_title_element(hostname);
// if doi and title element found, search for PubPeer content and alter title element
if(title){
$(title).css("background", "#355f78");
title.style.paddingLeft = '6px';
title.style.paddingTop = '4px';
title.style.paddingRight = '6px';
title.style.paddingBottom = '4px';
title.style.border = "thick dashed #000";
title.style.color = "#fff";
$(title).css("cursor", "pointer");
var address = "http://api.pubpeer.com/v1/publications/"+identifier.id+"?idType="+identifier.type+"&devkey=hack4ac";
console.log("articlEnhancer: Address for PubPeer query: "+address);
$.ajax(address
).done(function(data) {
var json = $.parseJSON(data);
console.log("articlEnhancer: json.total_comments: "+json.total_comments);
if(json.total_comments > 0){
title.style.border = "thick solid #ff9e29";
}
else{
title.style.border = "thick solid #b5b5b5";
}
$(title).click(function(){
window.open(json.url, '_blank');
});
});
}