URL matching moved from helper to auto-type

This commit is contained in:
Dennis Ploeger 2019-01-03 08:43:22 +01:00
parent 0aa029a495
commit 7055c9421f
2 changed files with 9 additions and 7 deletions

View File

@ -42,13 +42,7 @@ AutoTypeHelper.prototype.getActiveWindowTitle = function(callback) {
// special cases are not available. this method may ask the user about assistive access
AutoTypeHelper.exec(OtherAppsScript.replace(/\{}/g, appName), (err, out) => {
if (err) { return callback(err); }
// try to find a URL in the title
const urlMatcher = new RegExp(
'https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'
);
const urlMatches = urlMatcher.exec(out);
const url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null;
return callback(null, out.trim(), url);
return callback(null, out.trim());
});
}
});

View File

@ -164,6 +164,14 @@ const AutoType = {
if (err) {
logger.error('Error get window title', err);
} else {
if (!url) {
// try to find a URL in the title
const urlMatcher = new RegExp(
'https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'
);
const urlMatches = urlMatcher.exec(title);
url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null;
}
logger.debug('Window title', title, url);
}
return callback(err, title, url);