Don't run detectWeb/doWeb in Scaffold if target doesn't match
Closes #1728
This commit is contained in:
parent
8f00fa2603
commit
0bd04877bf
2 changed files with 31 additions and 19 deletions
|
@ -506,13 +506,14 @@ var Scaffold = new function() {
|
|||
if (functionToRun == "detectWeb" || functionToRun == "doWeb") {
|
||||
var translate = new Zotero.Translate.Web();
|
||||
var utilities = new Zotero.Utilities.Translate(translate);
|
||||
// If this is a string, assume it's a URL
|
||||
if (typeof input == 'string') {
|
||||
var doc = await new Promise(r => utilities.processDocuments(input, (doc) => r(doc)));
|
||||
translate.setDocument(doc);
|
||||
} else {
|
||||
translate.setDocument(input);
|
||||
if (!_testTargetRegex(input)) {
|
||||
_logOutput("Target did not match " + _getDocumentURL(input));
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
return;
|
||||
}
|
||||
translate.setDocument(input);
|
||||
} else if (functionToRun == "detectImport" || functionToRun == "doImport") {
|
||||
var translate = new Zotero.Translate.Import();
|
||||
translate.setString(input);
|
||||
|
@ -586,23 +587,30 @@ var Scaffold = new function() {
|
|||
this.generateTranslatorID = function() {
|
||||
document.getElementById("textbox-translatorID").value = _generateGUID();
|
||||
}
|
||||
|
||||
/*
|
||||
* test target regular expression against document URL
|
||||
|
||||
/**
|
||||
* Test target regular expression against document URL and log the result
|
||||
*/
|
||||
this.testTargetRegex = function() {
|
||||
var testDoc = _getDocument();
|
||||
var url = Zotero.Proxies.proxyToProper(testDoc.location.href);
|
||||
|
||||
this.logTargetRegex = function () {
|
||||
_logOutput(_testTargetRegex(_getDocument()));
|
||||
};
|
||||
|
||||
/**
|
||||
* Test target regular expression against document URL and return the result
|
||||
*/
|
||||
function _testTargetRegex(doc) {
|
||||
var url = _getDocumentURL(doc);
|
||||
|
||||
try {
|
||||
var targetRe = new RegExp(document.getElementById('textbox-target').value, "i");
|
||||
} catch(e) {
|
||||
_logOutput("Regex parse error:\n"+JSON.stringify(e, null, "\t"));
|
||||
}
|
||||
|
||||
_logOutput(targetRe.test(url));
|
||||
catch (e) {
|
||||
_logOutput("Regex parse error:\n" + JSON.stringify(e, null, "\t"));
|
||||
}
|
||||
|
||||
return targetRe.test(url);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* called to select items
|
||||
*/
|
||||
|
@ -1371,6 +1379,10 @@ var Scaffold = new function() {
|
|||
function _getDocument() {
|
||||
return _frames[_document.getElementById("menulist-testFrame").selectedIndex];
|
||||
}
|
||||
|
||||
function _getDocumentURL(doc) {
|
||||
return Zotero.Proxies.proxyToProper(doc.location.href);
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("load", function(e) { Scaffold.onLoad(e); }, false);
|
||||
|
|
|
@ -123,7 +123,7 @@
|
|||
<hbox>
|
||||
<label class="label-metadata" value="&scaffold.metadata.target.label;" control="textbox-target"/>
|
||||
<textbox id="textbox-target" flex="1"/>
|
||||
<button label="&scaffold.metadata.target.testRegex;" oncommand="Scaffold.testTargetRegex()"/>
|
||||
<button label="&scaffold.metadata.target.testRegex;" oncommand="Scaffold.logTargetRegex()"/>
|
||||
</hbox>
|
||||
<hbox style="display:none">
|
||||
<label class="label-metadata" value="&scaffold.metadata.targetAll.label;" control="textbox-target-all"/>
|
||||
|
|
Loading…
Reference in a new issue