Skip to content

Commit

Permalink
Replace calls to callback-less selectItems() (zotero#2758)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek authored Jan 3, 2022
1 parent 8d7bb94 commit 8e72a72
Show file tree
Hide file tree
Showing 24 changed files with 451 additions and 1,436 deletions.
151 changes: 76 additions & 75 deletions Alexander Street Press.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
{
"translatorID": "0a84a653-79ea-4c6a-8a68-da933e3b504a",
"translatorType": 4,
"label": "Alexander Street Press",
"creator": "John West and Michael Berkowitz",
"target": "^https?://(www\\.)alexanderstreet",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"lastUpdated": "2009-01-08 08:19:07"
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-12-28 04:42:00"
}

function detectWeb(doc, url) {
if ( url.indexOf("object.details.aspx") != -1 ) {
var zitemtype = doc.getElementById("ctl00_ctl00_MasterContentBody_ContentPlaceHolder1_txtZType").value;
switch (zitemtype.toLowerCase()) {
case "book":
return "book";
break;
case "chapter":
return "bookSection";
break;
case "journal":
return "journalArticle";
break;
case "manuscript":
return "manuscript";
break;
case "audio":
return "audioRecording";
break;
case "video":
return "videoRecording";
break;
case "issue":
return "journalArticle";
break;
case "article":
return "journalArticle";
break;
case "series":
return "interview";
break;
case "session":
return "interview";
break;
default:
return "document";
case "book":
return "book";
break;
case "chapter":
return "bookSection";
break;
case "journal":
return "journalArticle";
break;
case "manuscript":
return "manuscript";
break;
case "audio":
return "audioRecording";
break;
case "video":
return "videoRecording";
break;
case "issue":
return "journalArticle";
break;
case "article":
return "journalArticle";
break;
case "series":
return "interview";
break;
case "session":
return "interview";
break;
default:
return "document";
}
} else if (url.indexOf("results.aspx") != -1) {
return "multiple";
Expand Down Expand Up @@ -140,39 +141,39 @@ function scrape(doc, url) {

function GetItemType(zitemtype) {
switch (zitemtype.toLowerCase()) {
case "book":
return "book";
break;
case "chapter":
return "bookSection";
break;
case "journal":
return "journalArticle";
break;
case "manuscript":
return "manuscript";
break;
case "audio":
return "audioRecording";
break;
case "video":
return "videoRecording";
break;
case "issue":
return "journalArticle";
break;
case "article":
return "journalArticle";
break;
case "series":
return "interview";
break;
case "session":
return "interview";
break;
default:
return "document";
}
case "book":
return "book";
break;
case "chapter":
return "bookSection";
break;
case "journal":
return "journalArticle";
break;
case "manuscript":
return "manuscript";
break;
case "audio":
return "audioRecording";
break;
case "video":
return "videoRecording";
break;
case "issue":
return "journalArticle";
break;
case "article":
return "journalArticle";
break;
case "series":
return "interview";
break;
case "session":
return "interview";
break;
default:
return "document";
}
}

function doWeb(doc, url) {
Expand All @@ -185,13 +186,13 @@ function doWeb(doc, url) {
while (next_title = titles.iterateNext()) {
items[next_title.href] = next_title.textContent;
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
Zotero.selectItems(items, function (items) {
if (!items) return;
ZU.processDocuments(Object.keys(items), scrape);
});
} else {
articles = [url];
scrape(doc, url);
}

Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
}
}/** BEGIN TEST CASES **/
var testCases = []
/** END TEST CASES **/
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2020-03-09 12:23:02"
"lastUpdated": "2021-12-27 20:43:34"
}

/*
Expand Down Expand Up @@ -54,62 +54,59 @@ var metaTags = {
};

function doWeb(doc, url) {
var articles = [];
if (detectWeb(doc, url) == "multiple") {
var items = Zotero.Utilities.getItemArray(doc, doc, /sic_\d+|tel-\d+/);
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
Zotero.selectItems(items, function (items) {
if (!items) return;
ZU.processDocuments(Object.keys(items), scrape);
});
}
else {
articles = [url];
scrape(doc);
}
Zotero.Utilities.processDocuments(articles, function (doc) {
var xpath = '//meta[@name]';
var data = {};
var metas = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
var meta;
}

meta = metas.iterateNext();
while (meta) {
if (data[meta.name]) {
data[meta.name] = data[meta.name] + ";" + meta.content;
}
else {
data[meta.name] = meta.content;
}
meta = metas.iterateNext();
function scrape(doc) {
var xpath = '//meta[@name]';
var data = {};
var metas = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
var meta;

meta = metas.iterateNext();
while (meta) {
if (data[meta.name]) {
data[meta.name] = data[meta.name] + ";" + meta.content;
}
else {
data[meta.name] = meta.content;
}
meta = metas.iterateNext();
}

var item = new Zotero.Item("journalArticle");
for (var tag in metaTags) {
if (tag == "DC.creator") {
var authors = data['DC.creator'].split(";");
for (var i = 0; i < authors.length; i++) {
var aut = authors[i];
aut = aut.replace(/^([^,]+),\s+(.*)$/, "$2 $1");
item.creators.push(Zotero.Utilities.cleanAuthor(aut, "author"));
}
}
else {
item[metaTags[tag]] = data[tag];
var item = new Zotero.Item("journalArticle");
for (var tag in metaTags) {
if (tag == "DC.creator") {
var authors = data['DC.creator'].split(";");
for (var i = 0; i < authors.length; i++) {
var aut = authors[i];
aut = aut.replace(/^([^,]+),\s+(.*)$/, "$2 $1");
item.creators.push(Zotero.Utilities.cleanAuthor(aut, "author"));
}
}

var pdfurl = data.citation_pdf_url;

if (pdfurl) {
item.attachments = [
{ url: item.url, title: "AOSIC Snapshot", mimeType: "text/html" },
{ url: pdfurl, title: "AOSIC Full Text PDF", mimeType: "application/pdf" }
];
else {
item[metaTags[tag]] = data[tag];
}
item.complete();
}, function () {
Zotero.done();
});
Zotero.wait();
}

var pdfurl = data.citation_pdf_url;

if (pdfurl) {
item.attachments = [
{ url: item.url, title: "AOSIC Snapshot", mimeType: "text/html" },
{ url: pdfurl, title: "AOSIC Full Text PDF", mimeType: "application/pdf" }
];
}
item.complete();
}/** BEGIN TEST CASES **/
var testCases = [
{
Expand Down
37 changes: 20 additions & 17 deletions BIBSYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsbv",
"lastUpdated": "2014-04-04 10:08:22"
"browserSupport": "gcsibv",
"lastUpdated": "2021-12-28 04:44:52"
}

function detectWeb(doc, url) {
Expand All @@ -33,21 +33,24 @@ function doWeb(doc, url) {
titles.iterateNext();
while (title=titles.iterateNext())
items[codes.iterateNext().nodeValue]=title.nodeValue;
items=Zotero.selectItems(items);
var string="http://ask.bibsys.no/ask/action/result?control=ctr_top";
for (var codes in items)
string+="&valg="+codes;
string+="&control=ctr_bottom&eksportFormat=refmanager&eksportEpostAdresse=&eksportEpostFormat=fortekst&cmd=sendtil";
Zotero.Utilities.HTTP.doGet(string, function(text) {
var trans=Zotero.loadTranslator("import");
trans.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
trans.setString(text);
trans.setHandler("itemDone", function(obj, item) {
item.title = item.title.replace(/\s\s+/, " ").replace(/\s:/, ":");
item.complete();
});
trans.translate();
Zotero.selectItems(items, function (items) {
if (!items) return;
var string="http://ask.bibsys.no/ask/action/result?control=ctr_top";
for (var codes in items)
string+="&valg="+codes;
string+="&control=ctr_bottom&eksportFormat=refmanager&eksportEpostAdresse=&eksportEpostFormat=fortekst&cmd=sendtil";
Zotero.Utilities.HTTP.doGet(string, function(text) {
var trans=Zotero.loadTranslator("import");
trans.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
trans.setString(text);
trans.setHandler("itemDone", function(obj, item) {
item.title = item.title.replace(/\s\s+/, " ").replace(/\s:/, ":");
item.complete();
});
trans.translate();
});
});
return;
}
var singlereg=new RegExp("http://ask\.bibsys\.no/ask/action/show");
if (singlereg.test(url)) {
Expand Down Expand Up @@ -106,4 +109,4 @@ var testCases = [
]
}
]
/** END TEST CASES **/
/** END TEST CASES **/
17 changes: 6 additions & 11 deletions Beobachter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2016-09-07 21:24:35"
"lastUpdated": "2021-12-27 20:41:15"
}

/*
Expand Down Expand Up @@ -60,18 +60,13 @@ function doWeb(doc, url) {
if (!items || countObjectProperties(items) == 0) {
return true;
}
items = Z.selectItems(items);
if (!items) {
return true;
}

for (var i in items) {
urls.push(i);
}
items = Z.selectItems(items, function (items) {
if (!items) return;
ZU.processDocuments(Object.keys(items), scrape);
});
} else {
urls.push(doc.location.href);
scrape(doc);
}
ZU.processDocuments(urls, scrape);
}

/* Zotero API */
Expand Down
Loading

0 comments on commit 8e72a72

Please sign in to comment.