<commit_before>// this file is the JavaScript backing for the UI wrangling which happens in
// browser.xul. It also initializes the Greasemonkey singleton which contains
// all the main injection logic, though that should probably be a proper XPCOM
// service and wouldn't need to be initialized in that case.

function GM_BrowserUI() {};

/**
 * nsISupports.QueryInterface
 */
GM_BrowserUI.QueryInterface = function(aIID) {
  if (!aIID.equals(Components.interfaces.nsISupports) &&
      !aIID.equals(Components.interfaces.nsIObserver) &&
      !aIID.equals(Components.interfaces.nsISupportsWeakReference))
    throw Components.results.NS_ERROR_NO_INTERFACE;

  return GM_BrowserUI;
};


GM_BrowserUI.init = function() {
  window.addEventListener("load", GM_BrowserUI.chromeLoad, false);
  window.addEventListener("unload", GM_BrowserUI.chromeUnload, false);

  window.addEventListener('DOMNodeInserted', GM_BrowserUI.nodeInserted, false);
};

GM_BrowserUI.progressListener = {
  onLocationChange:function(aProgress, aRequest, aURI) {
    GM_BrowserUI.gmSvc.runScripts(
        'document-start', aProgress.DOMWindow, window);
  },
  onStateChange:function() { },
  onProgressChange:function() { },
  onStatusChange:function() { },
  onSecurityChange:function() { },
  onLinkIconAvailable:function() { }
};

/**
 * The browser XUL has loaded. Find the elements we need and set up our
 * listeners and wrapper objects.
 */
GM_BrowserUI.chromeLoad = function(e) {
  // Store DOM element references in this object, also for use elsewhere.
  GM_BrowserUI.tabBrowser = document.getElementById("content");
  GM_BrowserUI.bundle = document.getElementById("gm-browser-bundle");

  // Update visual status when enabled state changes.
  GM_prefRoot.watch("enabled", GM_BrowserUI.refreshStatus);
  GM_BrowserUI.refreshStatus();

  // Use the appcontent element specifically, see #1344.
  document.getElementById("appcontent")
      .addEventListener("DOMContentLoaded", GM_BrowserUI.contentLoad, true);
  gBrowser.addEventListener("pagehide", GM_BrowserUI.pagehide, true);
  gBrowser.addEventListener("pageshow", GM_BrowserUI.pageshow, true);

  var sidebar = document.getElementById("sidebar");
  sidebar.addEventListener("DOMContentLoaded", GM_BrowserUI.contentLoad, true);
  sidebar.addEventListener("pagehide", GM_BrowserUI.pagehide, true);
  sidebar.addEventListener("pageshow", GM_BrowserUI.pageshow, true);

  document.getElementById("contentAreaContextMenu")
    .addEventListener("popupshowing", GM_BrowserUI.contextMenuShowing, false);

  var observerService = Components.classes["@mozilla.org/observer-service;1"]
     .getService(Components.interfaces.nsIObserverService);
  observerService.addObserver(GM_BrowserUI, "install-userscript", true);

  // Since Firefox 3 does not give us inner-window-destroyed, which is exactly
  // what we want, instead we listen for dom-window-destroyed, which comes
  // pretty close (at least it doesn't leak memory).  But: listening for dom-
  // in Firefox 4 causes breakage, so we just do either-or.
  if (GM_compareFirefoxVersion("4.0") >= 0) {
    observerService.addObserver(GM_BrowserUI, "inner-window-destroyed", true);
  } else {
    observerService.addObserver(GM_BrowserUI, "dom-window-destroyed", true);
  }

  // we use this to determine if we are the active window sometimes
  GM_BrowserUI.winWat = Components
      .classes["@mozilla.org/embedcomp/window-watcher;1"]
      .getService(Components.interfaces.nsIWindowWatcher);

  // register for notifications from greasemonkey-service about ui type things
  GM_BrowserUI.gmSvc = Components
      .classes["@greasemonkey.mozdev.org/greasemonkey-service;1"]
      .getService(Components.interfaces.gmIGreasemonkeyService)
      .wrappedJSObject;
  // reference this once, so that the getter is called at least once, and the
  // initialization routines will run, no matter what
  GM_BrowserUI.gmSvc.config;

  GM_BrowserUI.showToolbarButton();

  gBrowser.addProgressListener(GM_BrowserUI.progressListener,
      Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
};

GM_BrowserUI.contentLoad = function(event) {<commit_msg>Do not run document-start scripts every time the tab is focused.<commit_after>// this file is the JavaScript backing for the UI wrangling which happens in
// browser.xul. It also initializes the Greasemonkey singleton which contains
// all the main injection logic, though that should probably be a proper XPCOM
// service and wouldn't need to be initialized in that case.

function GM_BrowserUI() {};

/**
 * nsISupports.QueryInterface
 */
GM_BrowserUI.QueryInterface = function(aIID) {
  if (!aIID.equals(Components.interfaces.nsISupports) &&
      !aIID.equals(Components.interfaces.nsIObserver) &&
      !aIID.equals(Components.interfaces.nsISupportsWeakReference))
    throw Components.results.NS_ERROR_NO_INTERFACE;

  return GM_BrowserUI;
};


GM_BrowserUI.init = function() {
  window.addEventListener("load", GM_BrowserUI.chromeLoad, false);
  window.addEventListener("unload", GM_BrowserUI.chromeUnload, false);

  window.addEventListener('DOMNodeInserted', GM_BrowserUI.nodeInserted, false);
};

GM_BrowserUI.progressListener = {
  onLocationChange:function(aBrowser, aProgress, aRequest, aURI) {
    GM_BrowserUI.gmSvc.runScripts(
        'document-start', aProgress.DOMWindow, window);
  },
  onStateChange:function() { },
  onProgressChange:function() { },
  onStatusChange:function() { },
  onSecurityChange:function() { },
  onLinkIconAvailable:function() { }
};

/**
 * The browser XUL has loaded. Find the elements we need and set up our
 * listeners and wrapper objects.
 */
GM_BrowserUI.chromeLoad = function(e) {
  // Store DOM element references in this object, also for use elsewhere.
  GM_BrowserUI.tabBrowser = document.getElementById("content");
  GM_BrowserUI.bundle = document.getElementById("gm-browser-bundle");

  // Update visual status when enabled state changes.
  GM_prefRoot.watch("enabled", GM_BrowserUI.refreshStatus);
  GM_BrowserUI.refreshStatus();

  // Use the appcontent element specifically, see #1344.
  document.getElementById("appcontent")
      .addEventListener("DOMContentLoaded", GM_BrowserUI.contentLoad, true);
  gBrowser.addEventListener("pagehide", GM_BrowserUI.pagehide, true);
  gBrowser.addEventListener("pageshow", GM_BrowserUI.pageshow, true);

  var sidebar = document.getElementById("sidebar");
  sidebar.addEventListener("DOMContentLoaded", GM_BrowserUI.contentLoad, true);
  sidebar.addEventListener("pagehide", GM_BrowserUI.pagehide, true);
  sidebar.addEventListener("pageshow", GM_BrowserUI.pageshow, true);

  document.getElementById("contentAreaContextMenu")
    .addEventListener("popupshowing", GM_BrowserUI.contextMenuShowing, false);

  var observerService = Components.classes["@mozilla.org/observer-service;1"]
     .getService(Components.interfaces.nsIObserverService);
  observerService.addObserver(GM_BrowserUI, "install-userscript", true);

  // Since Firefox 3 does not give us inner-window-destroyed, which is exactly
  // what we want, instead we listen for dom-window-destroyed, which comes
  // pretty close (at least it doesn't leak memory).  But: listening for dom-
  // in Firefox 4 causes breakage, so we just do either-or.
  if (GM_compareFirefoxVersion("4.0") >= 0) {
    observerService.addObserver(GM_BrowserUI, "inner-window-destroyed", true);
  } else {
    observerService.addObserver(GM_BrowserUI, "dom-window-destroyed", true);
  }

  // we use this to determine if we are the active window sometimes
  GM_BrowserUI.winWat = Components
      .classes["@mozilla.org/embedcomp/window-watcher;1"]
      .getService(Components.interfaces.nsIWindowWatcher);

  // register for notifications from greasemonkey-service about ui type things
  GM_BrowserUI.gmSvc = Components
      .classes["@greasemonkey.mozdev.org/greasemonkey-service;1"]
      .getService(Components.interfaces.gmIGreasemonkeyService)
      .wrappedJSObject;
  // reference this once, so that the getter is called at least once, and the
  // initialization routines will run, no matter what
  GM_BrowserUI.gmSvc.config;

  GM_BrowserUI.showToolbarButton();

  gBrowser.addTabsProgressListener(GM_BrowserUI.progressListener);
};

GM_BrowserUI.contentLoad = function(event) {
{'fraction_non_alphanumeric': 0.10715583000363241, 'fraction_numerical': 0.002905920813657828, 'mean_word_length': 4.994194484760523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3172593', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2339, 'n_words': 566}