Tweaks to support translation in connector (detection works now, but processDocuments() is still not implemented and no import/export/search translators are Safari/Chrome-compatible, so I haven't tested anything)
This commit is contained in:
parent
38e25d4756
commit
250e193645
2 changed files with 26 additions and 6 deletions
|
@ -295,10 +295,13 @@ Zotero.Translator = function(info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(info.code) {
|
if(info.code) {
|
||||||
this.code = info.code;
|
this.code = preprocessCode(info.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves code for this translator
|
||||||
|
*/
|
||||||
Zotero.Translator.prototype.getCode = function(callback) {
|
Zotero.Translator.prototype.getCode = function(callback) {
|
||||||
if(this.code) {
|
if(this.code) {
|
||||||
callback(true);
|
callback(true);
|
||||||
|
@ -309,7 +312,7 @@ Zotero.Translator.prototype.getCode = function(callback) {
|
||||||
if(!code) {
|
if(!code) {
|
||||||
callback(false);
|
callback(false);
|
||||||
} else {
|
} else {
|
||||||
me.code = code;
|
me.code = me.preprocessCode(code);
|
||||||
callback(true);
|
callback(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,6 +320,20 @@ Zotero.Translator.prototype.getCode = function(callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preprocesses code for this translator
|
||||||
|
*/
|
||||||
|
Zotero.Translator.prototype.preprocessCode = function(code) {
|
||||||
|
if(!Zotero.isFx) {
|
||||||
|
const foreach = /^(\s*)for each\s*\((var )?([^ ]+) in (.*?)\)(\s*){/m;
|
||||||
|
code = code.replace(foreach, "$1var $3_zForEachSubject = $4; "+
|
||||||
|
"for(var $3_zForEachIndex in $4_zForEachSubject)$5{ "+
|
||||||
|
"$2$3 = $3_zForEachSubject[$3_zForEachIndex];", code);
|
||||||
|
Zotero.debug(code);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
Zotero.Translator.prototype.__defineGetter__("displayOptions", function() {
|
Zotero.Translator.prototype.__defineGetter__("displayOptions", function() {
|
||||||
return Zotero.Utilities.deepCopy(this._displayOptions);
|
return Zotero.Utilities.deepCopy(this._displayOptions);
|
||||||
});
|
});
|
||||||
|
|
|
@ -744,8 +744,7 @@ Zotero.Translate.Base.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO maybe this should only be in the web translator
|
if(this._waitingForRPC && this instanceof Zotero.Translate.Web) {
|
||||||
if(this._waitingForRPC) {
|
|
||||||
var me = this;
|
var me = this;
|
||||||
Zotero.Connector.callMethod("detect", {"uri":this.location.toString(),
|
Zotero.Connector.callMethod("detect", {"uri":this.location.toString(),
|
||||||
"cookie":this.document.cookie,
|
"cookie":this.document.cookie,
|
||||||
|
@ -956,7 +955,8 @@ Zotero.Translate.Base.prototype = {
|
||||||
Zotero.debug("Translate: Parsing code for "+translator.label, 4);
|
Zotero.debug("Translate: Parsing code for "+translator.label, 4);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this._sandboxManager.eval("var translatorInfo = "+translator.code, this._sandbox);
|
this._sandboxManager.eval("var translatorInfo = "+translator.code,
|
||||||
|
["detect"+this._entryFunctionSuffix, "do"+this._entryFunctionSuffix]);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if(translator.logError) {
|
if(translator.logError) {
|
||||||
translator.logError(e.toString());
|
translator.logError(e.toString());
|
||||||
|
@ -1030,7 +1030,10 @@ Zotero.Translate.Base.prototype = {
|
||||||
* @param {Integer} level Log level (1-5, higher numbers are higher priority)
|
* @param {Integer} level Log level (1-5, higher numbers are higher priority)
|
||||||
*/
|
*/
|
||||||
"_debug":function(string, level) {
|
"_debug":function(string, level) {
|
||||||
if(typeof string === "object") string = new XPCSafeJSObjectWrapper(string);
|
if(typeof string === "object" && Zotero.isFx36) {
|
||||||
|
string = new XPCSafeJSObjectWrapper(string);
|
||||||
|
}
|
||||||
|
|
||||||
if(level !== undefined && typeof level !== "number") {
|
if(level !== undefined && typeof level !== "number") {
|
||||||
Zotero.debug("debug: level must be an integer");
|
Zotero.debug("debug: level must be an integer");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue