<commit_before>"use strict";

const {Cu} = require("chrome");
const self = require("sdk/self");
const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});

const FRAME_SCRIPT_URL = self.data.url("recorder-frame-script.js");

function PageRecorderPanel(win, toolbox) {
  this.win = win;
  this.doc = this.win.document;
  this.toolbox = toolbox;

  this.onRecord = this.onRecord.bind(this);
  this.onScreenshot = this.onScreenshot.bind(this);
  this.toggle = this.toggle.bind(this);
  this.search = this.search.bind(this);

  this.mm = toolbox.target.tab.linkedBrowser.messageManager;
  this.loadFrameScript();

  this.initUI();
}

exports.PageRecorderPanel = PageRecorderPanel;

PageRecorderPanel.prototype = {
  destroy() {
    this.win = this.doc = this.toolbox = this.mm = null;
  },

  loadFrameScript() {
    this.mm.loadFrameScript(FRAME_SCRIPT_URL, false);
    this.mm.addMessageListener("PageRecorder:OnChange", this.onRecord);
    this.mm.addMessageListener("PageRecorder:OnScreenshot", this.onScreenshot);

    // Make sure this is only called once on this instance
    this.loadFrameScript = () => {
      console.warn("Frame script " + FRAME_SCRIPT_URL + " has already been loaded");
    };
  },

  initUI() {
    this.recordsEl = this.doc.querySelector(".records");
    this.screenshotEl = this.doc.querySelector(".screenshots img");
    this.toggleEl = this.doc.querySelector("#toggle");
    this.searchBoxEl = this.doc.querySelector("#search-input");

    this.toggleEl.addEventListener("click", this.toggle);
    this.searchBoxEl.addEventListener("input", this.search);
  },

  toggle() {
    if (!this.isStarted) {
      this.start();
    } else {
      this.stop();
    }
  },

  start() {
    if (this.isStarted) {
      return;
    }
    this.isStarted = true;

    this.toggleEl.setAttribute("checked", "true")
    this.recordsEl.innerHTML = "";
    this.mm.sendAsyncMessage("PageRecorder:Start");
  },

  stop() {
    if (!this.isStarted) {
      return;
    }
    this.isStarted = false;

    this.toggleEl.removeAttribute("checked");
    this.searchBoxEl.removeAttribute("disabled");
    this.mm.sendAsyncMessage("PageRecorder:Stop");
  },

  matchesSearchQuery(recordEl) {
    let query = this.searchBoxEl.value.toLowerCase();
    if (query === "") {
      return true;
    }

    return recordEl.textContent.toLowerCase().indexOf(query) > -1;
  },

  search() {
    if (!this.recordsEl.children.length) {
      return;
    }

    for (let el of this.recordsEl.querySelectorAll("li")) {
      if (this.matchesSearchQuery(el)) {
        el.style.removeProperty("display");
      } else {
        el.style.display = "none";
      }
    }
  },<commit_msg>Removed useless code now that searchbox works live<commit_after>"use strict";

const {Cu} = require("chrome");
const self = require("sdk/self");
const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});

const FRAME_SCRIPT_URL = self.data.url("recorder-frame-script.js");

function PageRecorderPanel(win, toolbox) {
  this.win = win;
  this.doc = this.win.document;
  this.toolbox = toolbox;

  this.onRecord = this.onRecord.bind(this);
  this.onScreenshot = this.onScreenshot.bind(this);
  this.toggle = this.toggle.bind(this);
  this.search = this.search.bind(this);

  this.mm = toolbox.target.tab.linkedBrowser.messageManager;
  this.loadFrameScript();

  this.initUI();
}

exports.PageRecorderPanel = PageRecorderPanel;

PageRecorderPanel.prototype = {
  destroy() {
    this.win = this.doc = this.toolbox = this.mm = null;
  },

  loadFrameScript() {
    this.mm.loadFrameScript(FRAME_SCRIPT_URL, false);
    this.mm.addMessageListener("PageRecorder:OnChange", this.onRecord);
    this.mm.addMessageListener("PageRecorder:OnScreenshot", this.onScreenshot);

    // Make sure this is only called once on this instance
    this.loadFrameScript = () => {
      console.warn("Frame script " + FRAME_SCRIPT_URL + " has already been loaded");
    };
  },

  initUI() {
    this.recordsEl = this.doc.querySelector(".records");
    this.screenshotEl = this.doc.querySelector(".screenshots img");
    this.toggleEl = this.doc.querySelector("#toggle");
    this.searchBoxEl = this.doc.querySelector("#search-input");

    this.toggleEl.addEventListener("click", this.toggle);
    this.searchBoxEl.addEventListener("input", this.search);
  },

  toggle() {
    if (!this.isStarted) {
      this.start();
    } else {
      this.stop();
    }
  },

  start() {
    if (this.isStarted) {
      return;
    }
    this.isStarted = true;

    this.toggleEl.setAttribute("checked", "true")
    this.recordsEl.innerHTML = "";
    this.mm.sendAsyncMessage("PageRecorder:Start");
  },

  stop() {
    if (!this.isStarted) {
      return;
    }
    this.isStarted = false;

    this.toggleEl.removeAttribute("checked");
    this.mm.sendAsyncMessage("PageRecorder:Stop");
  },

  matchesSearchQuery(recordEl) {
    let query = this.searchBoxEl.value.toLowerCase();
    if (query === "") {
      return true;
    }

    return recordEl.textContent.toLowerCase().indexOf(query) > -1;
  },

  search() {
    if (!this.recordsEl.children.length) {
      return;
    }

    for (let el of this.recordsEl.querySelectorAll("li")) {
      if (this.matchesSearchQuery(el)) {
        el.style.removeProperty("display");
      } else {
        el.style.display = "none";
      }
    }
  },
{'fraction_non_alphanumeric': 0.15492431321248365, 'fraction_numerical': 0.00037376191366099795, 'mean_word_length': 3.340632603406326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4840968', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1740, 'n_words': 274}