| | 431 | function urlsOfAllFrames(contentWindow) { |
|---|
| | 432 | function collect(contentWindow) { |
|---|
| | 433 | urls = urls.concat(urlsOfAllFrames(contentWindow)); |
|---|
| | 434 | } |
|---|
| | 435 | var urls = [contentWindow.location.href]; |
|---|
| | 436 | Array.prototype.slice.call(contentWindow.frames).forEach(collect); |
|---|
| | 437 | return urls; |
|---|
| | 438 | } |
|---|
| | 439 | |
|---|
| | 440 | function uniq(a) { |
|---|
| | 441 | var seen = {}, list = [], item; |
|---|
| | 442 | for (var i = 0; i < a.length; i++) { |
|---|
| | 443 | item = a[i]; |
|---|
| | 444 | if (!seen.hasOwnProperty(item)) |
|---|
| | 445 | seen[item] = list.push(item); |
|---|
| | 446 | } |
|---|
| | 447 | return list; |
|---|
| | 448 | } |
|---|
| | 449 | |
|---|
| | 450 | function scriptsMatching(urls) { |
|---|
| | 451 | var matching = []; |
|---|
| | 452 | for (var i = 0, script = null; script = config.scripts[i]; i++) |
|---|
| | 453 | for (var j = 0; j < urls.length; j++) |
|---|
| | 454 | if (GM_scriptMatchesUrl(script, urls[j])) { |
|---|
| | 455 | matching.push(script); |
|---|
| | 456 | break; |
|---|
| | 457 | } |
|---|
| | 458 | return matching; |
|---|
| | 459 | } |
|---|
| | 460 | |
|---|
| | 461 | function appendScriptToPopup(script) { |
|---|
| | 462 | var mi = document.createElement("menuitem"); |
|---|
| | 463 | mi.setAttribute("label", script.name); |
|---|
| | 464 | mi.setAttribute("value", i); |
|---|
| | 465 | mi.setAttribute("type", "checkbox"); |
|---|
| | 466 | mi.setAttribute("checked", script.enabled.toString()); |
|---|
| | 467 | popup.insertBefore(mi, tail); |
|---|
| | 468 | } |
|---|
| | 469 | |
|---|
| 446 | | var foundInjectedScript = false; |
|---|
| | 485 | var urls = uniq( urlsOfAllFrames( getBrowser().contentWindow )); |
|---|
| | 486 | var runsOnTop = scriptsMatching( [urls.shift()] ); // first url = top window |
|---|
| | 487 | var runsFramed = scriptsMatching( urls ); // remainder are all its subframes |
|---|
| | 488 | |
|---|
| | 489 | // drop all runsFramed scripts already present in runsOnTop |
|---|
| | 490 | for (var i = 0; i < runsOnTop.length; i++) { |
|---|
| | 491 | var j = 0, item = runsOnTop[i]; |
|---|
| | 492 | while (j < runsFramed.length) |
|---|
| | 493 | if (item === runsFramed[j]) |
|---|
| | 494 | runsFramed.splice(j, 1); |
|---|
| | 495 | else |
|---|
| | 496 | j++; |
|---|
| | 497 | } |
|---|
| 449 | | for (var i = 0, script = null; script = config.scripts[i]; i++) { |
|---|
| 450 | | incloop: for (var j = 0; j < script.includes.length; j++) { |
|---|
| 451 | | var pattern = convert2RegExp(script.includes[j]); |
|---|
| 452 | | if (pattern.test(url)) { |
|---|
| 453 | | for (var k = 0; k < script.excludes.length; k++) { |
|---|
| 454 | | pattern = convert2RegExp(script.excludes[k]); |
|---|
| 455 | | if (pattern.test(url)) { |
|---|
| 456 | | break incloop; |
|---|
| 457 | | } |
|---|
| 458 | | } |
|---|
| 459 | | |
|---|
| 460 | | foundInjectedScript = true; |
|---|
| 461 | | |
|---|
| 462 | | var mi = document.createElement('menuitem'); |
|---|
| 463 | | mi.setAttribute('label', script.name); |
|---|
| 464 | | mi.setAttribute('value', i); |
|---|
| 465 | | mi.setAttribute('type', 'checkbox'); |
|---|
| 466 | | mi.setAttribute('checked', script.enabled.toString()); |
|---|
| 467 | | |
|---|
| 468 | | popup.insertBefore(mi, document.getElementById("gm-status-no-scripts-sep")); |
|---|
| 469 | | |
|---|
| 470 | | break incloop; |
|---|
| 471 | | } |
|---|
| 472 | | } |
|---|
| 473 | | } |
|---|
| 474 | | |
|---|
| | 500 | if (runsFramed.length) { |
|---|
| | 501 | runsFramed.forEach(appendScriptToPopup); |
|---|
| | 502 | var separator = document.createElement("menuseparator"); |
|---|
| | 503 | separator.setAttribute("value", "hack"); // to get removed in the loop above |
|---|
| | 504 | popup.insertBefore(separator, tail); |
|---|
| | 505 | } |
|---|
| | 506 | runsOnTop.forEach(appendScriptToPopup); |
|---|
| | 507 | |
|---|
| | 508 | var foundInjectedScript = !!(runsFramed.length + runsOnTop.length); |
|---|