main.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. var self = require("sdk/self");
  5. var panels = require("sdk/panel");
  6. var widgets = require("sdk/widget");
  7. function replaceMom(html) {
  8. return html.replace("World", "Mom");
  9. }
  10. exports.replaceMom = replaceMom;
  11. exports.main = function(options, callbacks) {
  12. console.log("My ID is " + self.id);
  13. // Load the sample HTML into a string.
  14. var helloHTML = self.data.load("sample.html");
  15. // Let's now modify it...
  16. helloHTML = replaceMom(helloHTML);
  17. // ... and then create a panel that displays it.
  18. var myPanel = panels.Panel({
  19. contentURL: "data:text/html," + helloHTML
  20. });
  21. // Load the URL of the sample image.
  22. var iconURL = self.data.url("mom.png");
  23. // Create a widget that displays the image. We'll attach the panel to it.
  24. // When you click the widget, the panel will pop up.
  25. widgets.Widget({
  26. id: "test-widget",
  27. label: "Mom",
  28. contentURL: iconURL,
  29. panel: myPanel
  30. });
  31. // If you run cfx with --static-args='{"quitWhenDone":true}' this program
  32. // will automatically quit Firefox when it's done.
  33. if (options.staticArgs.quitWhenDone)
  34. callbacks.quit();
  35. }