Chrome/Safari-compatible NYTimes.com translator
This commit is contained in:
parent
e35c25e31d
commit
1695ab4bdf
|
@ -3,32 +3,34 @@
|
||||||
"translatorType":4,
|
"translatorType":4,
|
||||||
"label":"NYTimes.com",
|
"label":"NYTimes.com",
|
||||||
"creator":"Simon Kornblith",
|
"creator":"Simon Kornblith",
|
||||||
"target":"^https?://(?:query\\.nytimes\\.com/search/(?:alternate/)?query|(?:select\\.|www\\.)?nytimes\\.com/.)",
|
"target":"^https?://(?:query\\.nytimes\\.com/search/(?:alternate/)?|(?:select\\.|www\\.)?nytimes\\.com/.)",
|
||||||
"minVersion":"1.0.0b3.r1",
|
"minVersion":"1.0.0b3.r1",
|
||||||
|
"browserSupport":"gcs",
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":100,
|
"priority":100,
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2011-03-21 20:48:32"
|
"lastUpdated":"2011-06-17 18:21:52"
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
if(doc.title.substr(0, 30) == "The New York Times: Search for") {
|
// Check for search results
|
||||||
var namespace = doc.documentElement.namespaceURI;
|
var searchResults = doc.evaluate('//div[@id="search_results"]', doc, null,
|
||||||
var nsResolver = namespace ? function(prefix) {
|
|
||||||
if (prefix == 'x') return namespace; else return null;
|
|
||||||
} : null;
|
|
||||||
|
|
||||||
var result = doc.evaluate('//div[@id="srchContent"]', doc, nsResolver,
|
|
||||||
XPathResult.ANY_TYPE, null).iterateNext();
|
XPathResult.ANY_TYPE, null).iterateNext();
|
||||||
if(result) {
|
if(searchResults) return "multiple";
|
||||||
return "multiple";
|
|
||||||
}
|
// Check for article meta tags
|
||||||
} else {
|
|
||||||
var metaTags = doc.getElementsByTagName("meta");
|
var metaTags = doc.getElementsByTagName("meta");
|
||||||
if(metaTags.namedItem("hdl") && metaTags.namedItem("byl")) {
|
var haveHdl = false;
|
||||||
return "newspaperArticle";
|
var haveByl = false;
|
||||||
|
for(var i in metaTags) {
|
||||||
|
if(metaTags[i].name === "hdl") {
|
||||||
|
haveHdl = true;
|
||||||
|
} else if(metaTags[i].name == "byl") {
|
||||||
|
haveByl = true;
|
||||||
}
|
}
|
||||||
|
if(haveHdl && haveByl) return "newspaperArticle";
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function associateMeta(newItem, metaTags, field, zoteroField) {
|
function associateMeta(newItem, metaTags, field, zoteroField) {
|
||||||
|
@ -142,28 +144,18 @@ function scrape(doc, url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function doWeb(doc, url) {
|
function doWeb(doc, url) {
|
||||||
if(doc.title.substr(0, 30) == "The New York Times: Search for") {
|
var searchResults = doc.evaluate('//div[@id="search_results"]', doc, null,
|
||||||
var namespace = doc.documentElement.namespaceURI;
|
|
||||||
var nsResolver = namespace ? function(prefix) {
|
|
||||||
if (prefix == 'x') return namespace; else return null;
|
|
||||||
} : null;
|
|
||||||
|
|
||||||
var result = doc.evaluate('//div[@id="srchContent"]', doc, nsResolver,
|
|
||||||
XPathResult.ANY_TYPE, null).iterateNext();
|
XPathResult.ANY_TYPE, null).iterateNext();
|
||||||
var items = Zotero.Utilities.getItemArray(doc, result, '^http://(?:select\.|www\.)nytimes.com/.*\.html(\\?|$)');
|
if(searchResults) {
|
||||||
|
var items = Zotero.Utilities.getItemArray(doc, searchResults, '^http://(?:select\.|www\.)nytimes.com/.*\.html(\\?|$)');
|
||||||
|
|
||||||
items = Zotero.selectItems(items);
|
items = Zotero.selectItems(items);
|
||||||
|
if(!items) return true;
|
||||||
|
|
||||||
if(!items) {
|
var urls = [];
|
||||||
return true;
|
for(var i in items) urls.push(i);
|
||||||
}
|
|
||||||
|
|
||||||
var urls = new Array();
|
|
||||||
for(var i in items) {
|
|
||||||
urls.push(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Utilities.HTTP.doGet(urls, function(text, response, url) { scrape(text, url) }, function() { Zotero.done(); }, null);
|
Zotero.Utilities.HTTP.doGet(urls, function(text, response, url) { scrape(text, url) }, function() { Zotero.done(); }, null);
|
||||||
|
|
||||||
Zotero.wait();
|
Zotero.wait();
|
||||||
} else {
|
} else {
|
||||||
scrape(doc);
|
scrape(doc);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user