Changeset 678

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

merge in trunk r652:677

Files:

Legend:

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

    r677 r678  
    421421 
    422422function GM_showPopup(aEvent) { 
     423  function urlsOfAllFrames(contentWindow) { 
     424    function collect(contentWindow) { 
     425      urls = urls.concat(urlsOfAllFrames(contentWindow)); 
     426    } 
     427    var urls = [contentWindow.location.href]; 
     428    Array.prototype.slice.call(contentWindow.frames).forEach(collect); 
     429    return urls; 
     430  } 
     431 
     432  function uniq(a) { 
     433    var seen = {}, list = [], item; 
     434    for (var i = 0; i < a.length; i++) { 
     435      item = a[i]; 
     436      if (!seen.hasOwnProperty(item)) 
     437        seen[item] = list.push(item); 
     438    } 
     439    return list; 
     440  } 
     441 
     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  } 
     457 
     458  function appendScriptToPopup(script) { 
     459    var mi = document.createElement("menuitem"); 
     460    mi.setAttribute("label", script.name); 
     461    mi.script = script; 
     462    mi.setAttribute("type", "checkbox"); 
     463    mi.setAttribute("checked", script.enabled.toString()); 
     464    popup.insertBefore(mi, tail); 
     465  } 
     466 
    423467  var popup = aEvent.target; 
    424   var url = getBrowser().contentWindow.document.location.href; 
     468  //***var url = getBrowser().contentWindow.document.location.href; 
     469  var tail = document.getElementById("gm-status-no-scripts-sep"); 
    425470 
    426471  // set the enabled/disabled state 
     
    434479  } 
    435480 
     481  var urls = uniq( urlsOfAllFrames( getBrowser().contentWindow )); 
     482  var runsOnTop = scriptsMatching( [urls.shift()] ); // first url = top window 
     483  var runsFramed = scriptsMatching( urls ); // remainder are all its subframes 
     484 
     485  // drop all runsFramed scripts already present in runsOnTop 
     486  for (var i = 0; i < runsOnTop.length; i++) { 
     487    var j = 0, item = runsOnTop[i]; 
     488    while (j < runsFramed.length) { 
     489      if (item === runsFramed[j]) { 
     490        runsFramed.splice(j, 1); 
     491      } else { 
     492        j++; 
     493      } 
     494    } 
     495  } 
     496 
    436497  // build the new list of scripts 
    437   var scripts = GM_getConfig().getScriptsForUrl(url, true); 
    438   for (var i = 0, script = null; script = scripts[i]; i++) { 
    439         var mi = document.createElement('menuitem'); 
    440         mi.setAttribute('label', script.name); 
    441         mi.script = script; 
    442         mi.setAttribute('type', 'checkbox'); 
    443         mi.setAttribute('checked', script.enabled.toString()); 
    444  
    445         popup.insertBefore(mi, document.getElementById("gm-status-no-scripts-sep")); 
    446   } 
    447  
    448   document.getElementById("gm-status-no-scripts").collapsed = scripts.length; 
     498  if (runsFramed.length) { 
     499    runsFramed.forEach(appendScriptToPopup); 
     500    var separator = document.createElement("menuseparator"); 
     501    separator.setAttribute("value", "hack"); // to get removed in the loop above 
     502    popup.insertBefore(separator, tail); 
     503  } 
     504  runsOnTop.forEach(appendScriptToPopup); 
     505 
     506  var foundInjectedScript = !!(runsFramed.length + runsOnTop.length); 
     507  document.getElementById("gm-status-no-scripts").collapsed = foundInjectedScript; 
    449508}; 
    450509 
  • branches/config-service/src/chrome/chromeFiles/content/config.js

    r677 r678  
    374374  get scripts() { 
    375375    return this._scripts.concat(); 
    376   }, 
    377  
    378   getScriptsForUrl: function(url, includeDisabled) { 
    379     var scripts = []; 
    380  
    381     scriptLoop: 
    382     for (var i = 0, script; script = this._scripts[i]; i++) { 
    383       if (script.enabled || includeDisabled) { 
    384         for (var j = 0, include; include = script._includes[j]; j++) { 
    385           if (convert2RegExp(include).test(url)) { 
    386             for (var k = 0, exclude; exclude = script._excludes[k]; k++) { 
    387               if (convert2RegExp(exclude).test(url)) { 
    388                 continue scriptLoop; 
    389               } 
    390             } 
    391             scripts.push(script); 
    392             continue scriptLoop; 
    393           } 
    394         } 
    395       } 
    396     } 
    397  
    398     return scripts; 
    399376  } 
    400377}; 
     
    424401 
    425402Script.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; 
     418  }, 
     419 
    426420  _changed: function(event, data) { this._config._changed(this, event, data); }, 
    427421 
  • branches/config-service/src/chrome/chromeFiles/locale/en-US/greasemonkey.dtd

    r410 r678  
    2222<!ENTITY menu.manage.accesskey "M"> 
    2323 
    24 <!ENTITY statusbar.noscripts "No scripts installed!"> 
     24<!ENTITY statusbar.noscripts "No installed scripts match this page"> 
    2525<!ENTITY statusbar.enabled "Enabled"> 
    2626<!ENTITY statusbar.enabled.accesskey "E"> 
  • branches/config-service/src/chrome/chromeFiles/locale/fa-IR/greasemonkey.dtd

    r632 r678  
    2020<!ENTITY menu.manage "Manage User Scripts..."> 
    2121<!ENTITY menu.manage.accesskey "M"> 
    22 <!ENTITY statusbar.noscripts "No scripts installed!"> 
     22<!ENTITY statusbar.noscripts "No installed scripts match this page"> 
    2323<!ENTITY statusbar.enabled "Enabled"> 
    2424<!ENTITY statusbar.enabled.accesskey "E"> 
  • branches/config-service/src/components/greasemonkey.js

    r668 r678  
    231231 
    232232  initScripts: function(url) { 
    233     var scripts = GM_getConfig().getScriptsForUrl(url, false); 
     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 
    234242    log("* number of matching scripts: " + scripts.length); 
    235243    return scripts; 
  • branches/config-service/src/foo/foo.user.js

    r542 r678  
    11// ==UserScript== 
    22// @name          Foo 
    3 // @namespace     localhost 
     3// @namespace     http://www.greasespot.net/ 
    44// @description   Foo'in around 
    55// @include       http://wiki.greasespot.net/*