Advertisement
Guest User

Untitled

a guest
Sep 8th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ************************************************************************** //
  2. // XPCOM
  3.  
  4. var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
  5.  
  6. // https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm
  7. Cu.import("resource://gre/modules/Services.jsm");
  8.  
  9.  
  10. function install(data, reason) {
  11. }
  12.  
  13. function startup(data, reason) {
  14.     let windows = Services.wm.getEnumerator("navigator:browser");
  15.     while (windows.hasMoreElements()) {
  16.         let aWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
  17.         aWindow.addEventListener("click", clicker, true);
  18.     }
  19.  
  20.     Services.wm.addListener(windowListener);
  21. }
  22.  
  23. function shutdown(data, reason) {
  24.     let windows = Services.wm.getEnumerator("navigator:browser");
  25.     while (windows.hasMoreElements()) {
  26.         let aWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
  27.         aWindow.removeEventListener("click", clicker, true);
  28.     }
  29. }
  30.  
  31. function uninstall(data, reason) {
  32. }
  33.  
  34.  
  35. var clicker = function(e) {
  36.     let aWindow = Services.wm.getMostRecentWindow("navigator:browser");
  37.     Services.console.logStringMessage("hello_instanceof [target]: " + e.target);
  38.     Services.console.logStringMessage("hello_instanceof [match with]: " + aWindow.HTMLElement);
  39.     Services.console.logStringMessage("hello_instanceof [result window]: " + (e.target instanceof aWindow.HTMLElement) );
  40.     Services.console.logStringMessage("hello_instanceof [result nsIDOM]: " + (e.target instanceof Components.interfaces.nsIDOMHTMLElement) );
  41. };
  42.  
  43.  
  44. var windowListener = {
  45.     onOpenWindow: function(aWindow) {
  46.         // Wait for the window to finish loading
  47.         let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
  48.         domWindow.addEventListener("load", function() {
  49.             domWindow.removeEventListener("load", arguments.callee, false);
  50.             domWindow.addEventListener("click", clicker, true);
  51.         }, false);
  52.     },
  53.  
  54.     onCloseWindow: function(aWindow) {},
  55.     onWindowTitleChange: function(aWindow, aTitle) {}
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement