Permalink
Browse files

Add wildcard and regex support to 'use with sites' option. Regex must…

… be enclosed in //, e.g. /https?.*/.


Add RDF import of site list strings.
  • Loading branch information...
wadetb committed Jul 28, 2011
1 parent 1290899 commit c5a6c0bbd5f0d3710bb5bc70e852f38f8d5b111f
Showing with 55 additions and 3 deletions.
  1. +30 −0 javascript/import.js
  2. +25 −3 javascript/popup.js
View
@@ -97,6 +97,36 @@ RdfImporter.loadDoc = function(rdf) {
prof[opts.name] = opts.convert ? opts.convert(val) : val;
}
}
// store site patterns
var patterns = [],
patternType = [],
patternEnabled = [],
siteList = '';
for(var i=0;i<this.attributes.length;i++){
var attrName = this.attributes[i].name.replace(/.*:/g,'');
var m = attrName.match(/pattern(|type|enabled)(\d+)/);
if(m){
if (m[1] == '') {
patterns[m[2]] = this.attributes[i].value;
} else if (m[1] == 'type') {
patternType[m[2]] = this.attributes[i].value;
} else if (m[1] == 'enabled') {
patternEnabled[m[2]] = this.attributes[i].value;
}
}
}
for(var i=0;i<patterns.length;i++){
if(patternEnabled[i] == 'true'){
if(patternType[i]=='regex'){
siteList += '/'+patterns[i]+'/ ';
}else{
siteList += patterns[i]+' ';
}
}
}
prof['siteList'] = siteList;
if(prof.rdf_about == 'http://passwordmaker.mozdev.org/globalSettings'){
settings = prof;
}else if(prof.selectedCharset){
View
@@ -14,10 +14,32 @@ function getAutoProfileIdForUrl(url) {
for (var i in profiles) {
var profile = profiles[i];
if (profile.siteList) {
var profileUrl = profile.getUrl(url);
var usedText = profile.getUrl(url);
var sites = profile.siteList.split(' ');
if (sites.indexOf(profileUrl) != -1) {
return profile.id;
for (var j = 0; j < sites.length; j++) {
var pat = sites[j];
if (pat[0] == '/' && pat[pat.length-1] == '/') {
pat = pat.substr(1, pat.length-2);
} else {
pat = pat.replace(/[$.+()^\[\]\\|{},]/g, '');
pat = pat.replace(/\?/g, '.');
pat = pat.replace(/\*/g, '.*');
}
if (pat[0] != '^') pat = '^' + pat;
if (pat[pat.length-1] != '$') pat = pat + '$';
var re;
try {
re = new RegExp(pat);
} catch(e) {
console.log(e + "\n");
}
if (re.test(usedText) || re.test(url)) {
return profile.id;
}
}
}
}

0 comments on commit c5a6c0b

Please sign in to comment.