Changeset 679

Show
Ignore:
Timestamp:
03/14/08 07:29:03 (9 months ago)
Author:
ma..@jesperkristensen.dk
Message:

rename matchUrl and try to make some loops look prettier.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/config-service/src/chrome/chromeFiles/content/browser.js

    r678 r679  
    440440  } 
    441441 
    442   function scriptsMatching(urls) { 
    443     var allScripts = GM_getConfig().scripts; 
    444     var scripts = []; 
    445  
    446     for (var i = 0, script; script = allScripts[i]; i++) { 
    447       for (var j = 0; j < urls.length; j++) { 
    448         if (script.matchUrl(urls[j])) { 
    449           scripts.push(script); 
    450           break; 
    451         } 
    452       } 
    453     } 
    454  
    455     return scripts; 
    456   } 
     442  function scriptsMatching(urls) 
     443    GM_getConfig().getMatchingScripts( 
     444      function(script) urls.some(function(url) script.matchesURL(url)) 
     445    ); 
    457446 
    458447  function appendScriptToPopup(script) { 
  • branches/config-service/src/chrome/chromeFiles/content/config.js

    r678 r679  
    372372  }, 
    373373 
    374   get scripts() { 
    375     return this._scripts.concat(); 
    376   } 
     374  get scripts() this._scripts.concat(), 
     375  getMatchingScripts: function(testFunc) this._scripts.filter(testFunc) 
    377376}; 
    378377 
     
    401400 
    402401Script.prototype = { 
    403   matchUrl: function(url) { 
    404     var scripts = []; 
    405  
    406     for (var j = 0, include; include = this._includes[j]; j++) { 
    407       if (convert2RegExp(include).test(url)) { 
    408         for (var k = 0, exclude; exclude = this._excludes[k]; k++) { 
    409           if (convert2RegExp(exclude).test(url)) { 
    410             return false; 
    411           } 
    412         } 
    413         return true; 
    414       } 
    415     } 
    416  
    417     return false; 
     402  matchesURL: function(url) { 
     403    function test(page) convert2RegExp(page).test(url); 
     404    return this._includes.some(test) && !this._excludes.some(test); 
    418405  }, 
    419406 
  • branches/config-service/src/components/greasemonkey.js

    r678 r679  
    231231 
    232232  initScripts: function(url) { 
    233     var allScripts = GM_getConfig().scripts; 
    234     var scripts = []; 
    235  
    236     for (var i = 0, script; script = allScripts[i]; i++) { 
    237       if (script.enabled && script.matchUrl(url)) { 
    238         scripts.push(script); 
    239       } 
    240     } 
    241  
    242     log("* number of matching scripts: " + scripts.length); 
    243     return scripts; 
     233    return GM_getConfig().getMatchingScripts( 
     234      function (script) script.enabled && script.matchesURL(url) 
     235    ); 
    244236  }, 
    245237