-
Notifications
You must be signed in to change notification settings - Fork 3
/
retriever-console.js
44 lines (35 loc) · 1.02 KB
/
retriever-console.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
var re = /name="citation_doi" content=(.*?)\/>/g
var s = new Zotero.Search();
s.libraryID = Zotero.Libraries.userLibraryID;
s.addCondition('url', 'contains', 'arxiv');
s.addCondition('url', 'doesNotContain', ' ');
s.addCondition('itemType', 'is', 'journalArticle');
var results = await s.search();
var items = await Zotero.Items.getAsync(results);
var DOIs = []
var titles = []
for(item of items){
let url = item.getField('url');
var req = new XMLHttpRequest();
req.open('GET', url, false);
req.send();
text = req.response;
if (text.match(re)!=null){
DOI = re.exec(text)[1].replace(/\"/g, "");
// item.setField('DOI', DOI);
let DOIurl = "https://doi.org/" + DOI;
DOIs.push(DOIurl);
titles.push(item.getField('title'))
}
}
var s = ''
for (i=0; i<DOIs.length; i++){
s += i+1 + ') "' + titles[i] + '", ' + DOIs[i] + ';\n'
}
if(DOIs.length==0){
alert('No published versions found.');
}
else
{
alert('Found ' + DOIs.length + ' DOIs for your arXiv papers:\n\n' + s);
}