Merge pull request #93 from aurimasv/recognizePDF
[PDF Metadata Retrieval] Call detectWeb before trying to call doWeb for Google Scholar
This commit is contained in:
commit
d3bc2b4046
2 changed files with 41 additions and 7 deletions
|
@ -363,7 +363,7 @@ Zotero_RecognizePDF.Recognizer.prototype._queryGoogle = function() {
|
|||
var me = this;
|
||||
if(this._DOI) {
|
||||
// use CrossRef to look for DOI
|
||||
var translate = new Zotero.Translate("search");
|
||||
var translate = new Zotero.Translate.Search();
|
||||
translate.setTranslator("11645bd1-0420-45c1-badb-53fb41eeb753");
|
||||
var item = {"itemType":"journalArticle", "DOI":this._DOI};
|
||||
translate.setSearch(item);
|
||||
|
@ -411,7 +411,7 @@ Zotero_RecognizePDF.Recognizer.prototype._queryGoogle = function() {
|
|||
this._hiddenBrowser.docShell.allowImages = false;
|
||||
}
|
||||
|
||||
var translate = new Zotero.Translate("web");
|
||||
var translate = new Zotero.Translate.Web();
|
||||
var savedItem = false;
|
||||
translate.setTranslator("57a00950-f0d1-4b41-b6ba-44ff0fc30289");
|
||||
translate.setHandler("itemDone", function(translate, item) {
|
||||
|
@ -425,6 +425,13 @@ Zotero_RecognizePDF.Recognizer.prototype._queryGoogle = function() {
|
|||
translate.setHandler("done", function(translate, success) {
|
||||
if(!success || !savedItem) me._queryGoogle();
|
||||
});
|
||||
translate.setHandler("translators", function(translate, detected) {
|
||||
if(detected.length) {
|
||||
translate.translate(me._libraryID, false);
|
||||
} else {
|
||||
me._queryGoogle();
|
||||
}
|
||||
});
|
||||
|
||||
this._hiddenBrowser.addEventListener("pageshow", function() { me._scrape(translate) }, true);
|
||||
|
||||
|
@ -459,10 +466,11 @@ Zotero_RecognizePDF.Recognizer.prototype._scrape = function(/**Zotero.Translate*
|
|||
this._callback(false, "recognizePDF.limit");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this._hiddenBrowser.removeEventListener("pageshow", this._scrape.caller, true);
|
||||
translate.setDocument(this._hiddenBrowser.contentDocument);
|
||||
translate.translate(this._libraryID, false);
|
||||
|
||||
translate.getTranslators(false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -892,15 +892,41 @@ Zotero.Translate.Base.prototype = {
|
|||
*
|
||||
* @param {Boolean} [getAllTranslators] Whether all applicable translators should be returned,
|
||||
* rather than just the first available.
|
||||
* @param {Boolean} [checkSetTranslator] If true, the appropriate detect function is run on the
|
||||
* set document/text/etc. using the translator set by setTranslator.
|
||||
* getAllTranslators parameter is meaningless in this context.
|
||||
* @return {Zotero.Translator[]} An array of {@link Zotero.Translator} objects
|
||||
*/
|
||||
"getTranslators":function(getAllTranslators) {
|
||||
"getTranslators":function(getAllTranslators, checkSetTranslator) {
|
||||
// do not allow simultaneous instances of getTranslators
|
||||
if(this._currentState === "detect") throw new Error("getTranslators: detection is already running");
|
||||
this._currentState = "detect";
|
||||
this._getAllTranslators = getAllTranslators;
|
||||
this._getTranslatorsGetPotentialTranslators();
|
||||
|
||||
|
||||
if(checkSetTranslator) {
|
||||
// setTranslator must be called beforehand if checkSetTranslator is set
|
||||
if( !this.translator || !this.translator[0] ) {
|
||||
throw new Error("getTranslators: translator must be set via setTranslator before calling" +
|
||||
" getTranslators with the checkSetTranslator flag");
|
||||
}
|
||||
var translators = new Array();
|
||||
var t;
|
||||
for(var i=0, n=this.translator.length; i<n; i++) {
|
||||
if(typeof(this.translator[i]) == 'string') {
|
||||
t = Zotero.Translators.get(this.translator[i]);
|
||||
if(!t) Zotero.debug("getTranslators: could not retrieve translator '" + this.translator[i] + "'");
|
||||
} else {
|
||||
t = this.translator[i];
|
||||
}
|
||||
/**TODO: check that the translator is of appropriate type?*/
|
||||
if(t) translators.push(t);
|
||||
}
|
||||
if(!translators.length) throw new Error("getTranslators: no valid translators were set.");
|
||||
this._getTranslatorsTranslatorsReceived(translators);
|
||||
} else {
|
||||
this._getTranslatorsGetPotentialTranslators();
|
||||
}
|
||||
|
||||
// if detection returns immediately, return found translators
|
||||
if(!this._currentState) return this._foundTranslators;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue