Changeset 621

Show
Ignore:
Timestamp:
01/19/08 12:29:43 (11 months ago)
Author:
oyasu..@gmail.com
Message:

Refactoring: moving code duplication into a common utils.js::GM_scriptMatchesUrl(script, url).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/jhs1/chrome/chromeFiles/content/browser.js

    r617 r621  
    449449  // build the new list of scripts 
    450450  for (var i = 0, script = null; script = config.scripts[i]; i++) { 
    451     incloop: for (var j = 0; j < script.includes.length; j++) { 
    452       var pattern = convert2RegExp(script.includes[j]); 
    453       if (pattern.test(url)) { 
    454         for (var k = 0; k < script.excludes.length; k++) { 
    455           pattern = convert2RegExp(script.excludes[k]); 
    456           if (pattern.test(url)) { 
    457             break incloop; 
    458           } 
    459         } 
    460  
    461         foundInjectedScript = true; 
    462  
    463         var mi = document.createElement('menuitem'); 
    464         mi.setAttribute('label', script.name); 
    465         mi.setAttribute('value', i); 
    466         mi.setAttribute('type', 'checkbox'); 
    467         mi.setAttribute('checked', script.enabled.toString()); 
    468  
    469         popup.insertBefore(mi, document.getElementById("gm-status-no-scripts-sep")); 
    470  
    471         break incloop; 
    472       } 
     451    if (GM_scriptMatchesUrl(script, url)) { 
     452      foundInjectedScript = true; 
     453 
     454      var mi = document.createElement("menuitem"); 
     455      mi.setAttribute("label", script.name); 
     456      mi.setAttribute("value", i); 
     457      mi.setAttribute("type", "checkbox"); 
     458      mi.setAttribute("checked", script.enabled.toString()); 
     459 
     460      popup.insertBefore(mi, document.getElementById("gm-status-no-scripts-sep")); 
    473461    } 
    474462  } 
  • branches/jhs1/chrome/chromeFiles/content/utils.js

    r611 r621  
    473473  } 
    474474}; 
     475 
     476function GM_scriptMatchesUrl(script, url) { 
     477  for (var i = 0, glob; glob = script.includes[i]; i++) { 
     478    var re = convert2RegExp(glob); 
     479    if (re.test(url)) { 
     480      for (var j = 0; glob = script.excludes[j]; j++) { 
     481        re = convert2RegExp(glob); 
     482        if (re.test(url)) 
     483          return false; 
     484      } 
     485      return true; 
     486    } 
     487  } 
     488  return false; 
     489} 
  • branches/jhs1/components/greasemonkey.js

    r605 r621  
    189189  initScripts: function(url) { 
    190190    var config = new Config(); 
    191     var scripts = []
     191    var scripts = [], script
    192192    config.load(); 
    193193 
    194     outer: 
    195     for (var i = 0; i < config.scripts.length; i++) { 
    196       var script = config.scripts[i]; 
    197       if (script.enabled) { 
    198         for (var j = 0; j < script.includes.length; j++) { 
    199           var pattern = convert2RegExp(script.includes[j]); 
    200  
    201           if (pattern.test(url)) { 
    202             for (var k = 0; k < script.excludes.length; k++) { 
    203               pattern = convert2RegExp(script.excludes[k]); 
    204  
    205               if (pattern.test(url)) { 
    206                 continue outer; 
    207               } 
    208             } 
    209  
    210             scripts.push(script); 
    211  
    212             continue outer; 
    213           } 
    214         } 
     194    for (var i = 0; script = config.scripts[i]; i++) {  
     195      if (script.enabled && GM_scriptMatchesUrl(script, url)) { 
     196        scripts.push(script); 
    215197      } 
    216198    }