Ticket #5: scratchpad.js

File scratchpad.js, 974 bytes (added by saroyanm, on 04/07/2014 at 10:33:32 AM)

Observer registration for inspector-opened topic

Line 
1/*
2 * This is a JavaScript Scratchpad.
3 *
4 * Enter some JavaScript, then Right Click or choose from the Execute Menu:
5 * 1. Run to evaluate the selected text (Ctrl+r),
6 * 2. Inspect to bring up an Object Inspector on the result (Ctrl+i), or,
7 * 3. Display to insert the result in a comment after the selection. (Ctrl+l)
8 */
9
10function myObserver()
11{
12  this.register();
13}
14myObserver.prototype = {
15  observe: function(subject, topic, data) {
16     console.log("observe called for topic", topic);
17  },
18  register: function() {
19    var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
20    observerService.addObserver(this, "inspector-opened", false);
21  },
22  unregister: function() {
23    var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
24    observerService.removeObserver(this, "inspector-opened");
25  }
26}
27
28new myObserver();