<commit_before>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

let InspectorObserver =
{
  init: function()
  {
    Services.obs.addObserver(this, "inspector-opened", true);
    onShutdown.add((function() Services.obs.removeObserver(this, "inspector-opened")).bind(this));
  },

  get inspectorButton()
  {
    // Randomize URI to work around bug 719376
    let stringBundle = Services.strings.createBundle("chrome://removetemporarily/locale/global.properties?" + Math.random());
    let result = [stringBundle.GetStringFromName("inspector.button.label"), stringBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetStringFromName("inspector.button.tooltiptext")];

    delete this.inspectorButton;
    this.__defineGetter__("inspectorButton", function() result);
    return this.inspectorButton;
  },

  observe: function(subject, topic, data)
  {
    if (topic != "inspector-opened")
      return;

    let InspectorUI = subject.wrappedJSObject;

    let [label, accesskey, tooltiptext] = this.inspectorButton;
    let tool = {
      id: "remove-temporarily",
      label: label,
      accesskey: accesskey,
      tooltiptext: tooltiptext,
      get isOpen() false,
      show: function(selection)
      {
        if (selection && selection.parentNode && selection.parentNode.nodeType == Ci.nsIDOMNode.ELEMENT_NODE)
        {
          let parent = selection.parentNode;
          InspectorUI.highlighter.highlight(parent);
          parent.removeChild(selection);
        }
        InspectorUI.toolHide(tool);
      },
      hide: function() {}
    };
    InspectorUI.registerTool(tool);
  },

  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
};

InspectorObserver.init();
<commit_msg>InspectorUI.registerTool API disappeared in Firefox 14 (bug 707809), add inspector button manually<commit_after>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

let InspectorObserver =
{
  init: function()
  {
    Services.obs.addObserver(this, "inspector-opened", true);
    onShutdown.add(function()
    {
      Services.obs.removeObserver(this, "inspector-opened")

      let e = Services.ww.getWindowEnumerator();
      while (e.hasMoreElements())
      {
        let window = e.getNext().QueryInterface(Ci.nsIDOMWindow);
        let button = window.document.getElementById("inspector-remove-temporarily-toolbutton");
        if (button)
          button.parentNode.removeChild(button);
      }
    }.bind(this));
  },

  get inspectorButton()
  {
    // Randomize URI to work around bug 719376
    let stringBundle = Services.strings.createBundle("chrome://removetemporarily/locale/global.properties?" + Math.random());
    let result = [stringBundle.GetStringFromName("inspector.button.label"), stringBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetStringFromName("inspector.button.tooltiptext")];

    delete this.inspectorButton;
    this.__defineGetter__("inspectorButton", function() result);
    return this.inspectorButton;
  },

  observe: function(subject, topic, data)
  {
    if (topic != "inspector-opened")
      return;

    let InspectorUI = subject.wrappedJSObject;
    let window = InspectorUI.chromeWin;
    let button = window.document.getElementById("inspector-remove-temporarily-toolbutton");
    if (button)
      button.parentNode.removeChild(button);

    let parent = window.document.getElementById("inspector-tools");
    if (!parent)
      return;

    let [label, accesskey, tooltiptext] = this.inspectorButton;
    button = window.document.createElement("toolbarbutton");
    button.setAttribute("id", "inspector-remove-temporarily-toolbutton");
    button.setAttribute("label", label);
    button.setAttribute("class", "devtools-toolbarbutton");
    button.setAttribute("accesskey", accesskey);
    button.setAttribute("tooltiptext", tooltiptext);
    button.setAttribute("tabindex", "0");
    button.addEventListener("command", function()
    {
      let selection = InspectorUI.selection;
      if (selection && selection.parentNode && selection.parentNode.nodeType == Ci.nsIDOMNode.ELEMENT_NODE)
      {
        let parent = selection.parentNode;
        InspectorUI.highlighter.highlight(parent);
        parent.removeChild(selection);
      }
    }, false);
    parent.appendChild(button);
  },

  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
};

InspectorObserver.init();

{'fraction_non_alphanumeric': 0.12933496532027744, 'fraction_numerical': 0.005915952672378621, 'mean_word_length': 3.8163064833005893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6831622', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1418, 'n_words': 271}