Changeset 678
- Timestamp:
- 03/14/08 04:56:26 (9 months ago)
- Files:
-
- branches/config-service/src/chrome/chromeFiles/content/browser.js (modified) (2 diffs)
- branches/config-service/src/chrome/chromeFiles/content/config.js (modified) (2 diffs)
- branches/config-service/src/chrome/chromeFiles/locale/en-US/greasemonkey.dtd (modified) (1 diff)
- branches/config-service/src/chrome/chromeFiles/locale/fa-IR/greasemonkey.dtd (modified) (1 diff)
- branches/config-service/src/components/greasemonkey.js (modified) (1 diff)
- branches/config-service/src/foo/foo.user.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/config-service/src/chrome/chromeFiles/content/browser.js
r677 r678 421 421 422 422 function 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 423 467 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"); 425 470 426 471 // set the enabled/disabled state … … 434 479 } 435 480 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 436 497 // 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; 449 508 }; 450 509 branches/config-service/src/chrome/chromeFiles/content/config.js
r677 r678 374 374 get scripts() { 375 375 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;399 376 } 400 377 }; … … 424 401 425 402 Script.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 426 420 _changed: function(event, data) { this._config._changed(this, event, data); }, 427 421 branches/config-service/src/chrome/chromeFiles/locale/en-US/greasemonkey.dtd
r410 r678 22 22 <!ENTITY menu.manage.accesskey "M"> 23 23 24 <!ENTITY statusbar.noscripts "No scripts installed!">24 <!ENTITY statusbar.noscripts "No installed scripts match this page"> 25 25 <!ENTITY statusbar.enabled "Enabled"> 26 26 <!ENTITY statusbar.enabled.accesskey "E"> branches/config-service/src/chrome/chromeFiles/locale/fa-IR/greasemonkey.dtd
r632 r678 20 20 <!ENTITY menu.manage "Manage User Scripts..."> 21 21 <!ENTITY menu.manage.accesskey "M"> 22 <!ENTITY statusbar.noscripts "No scripts installed!">22 <!ENTITY statusbar.noscripts "No installed scripts match this page"> 23 23 <!ENTITY statusbar.enabled "Enabled"> 24 24 <!ENTITY statusbar.enabled.accesskey "E"> branches/config-service/src/components/greasemonkey.js
r668 r678 231 231 232 232 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 234 242 log("* number of matching scripts: " + scripts.length); 235 243 return scripts; branches/config-service/src/foo/foo.user.js
r542 r678 1 1 // ==UserScript== 2 2 // @name Foo 3 // @namespace localhost3 // @namespace http://www.greasespot.net/ 4 4 // @description Foo'in around 5 5 // @include http://wiki.greasespot.net/*
