<commit_before>var HISTORY_LENGTH = 10;

var sendCommand = function sendCommand(commandName, responseHandler) {
        (function (commandName, responseHandler) {
            chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
              console.assert(tabs.length == 1);
              var tab  = tabs[0];
              if (typeof responseHandler === "undefined") {
                  responseHandler = null;
              }
              chrome.tabs.sendMessage(tab.id, { command: commandName }, responseHandler);
            });
        })(commandName, responseHandler);
    }

var BackgroundInterface;
(function (BackgroundInterface) {
    function getTabStateManager() {
        return chrome.extension.getBackgroundPage()["BackgroundScript"].getTabStateManager();
    }
    BackgroundInterface.getTabStateManager = getTabStateManager;
})(BackgroundInterface || (BackgroundInterface = {}));

var SearchHistory = (function(){
    function SearchHistory(){
      var persistentHistory = JSON.parse(localStorage.getItem("searchHistory"));
      if(persistentHistory === null){
        this.history = [];
        this.position = 0;
      } else {
        this.history = persistentHistory;
        this.position = this.history.length - 1;
      }
      this.newQuery = false;
    };

    SearchHistory.prototype.push = function(query){
      while(this.history.length >= HISTORY_LENGTH){
        this.history.shift();
      }
      console.log("current history" + JSON.stringify(this.history));
      if(query != this.history[this.history.length - 1]) {
        this.history.push(query);
      }
      console.log("new history" + JSON.stringify(this.history));
      this.position = this.history.length - 1;
      this.newQuery = true;
      localStorage.setItem("searchHistory", JSON.stringify(this.history));
    };

    SearchHistory.prototype.prev = function() {
        console.log("prev was requested");
      if(this.newQuery){
        this.newQuery = false;
        --this.position;
        return this.history[this.position];
      }
      if(this.history.length == 0){
          return "";
      }
      if(this.position != 0) {
        --this.position;
      }
      return this.history[this.position];
    };

    SearchHistory.prototype.next = function() {
        console.log("next was requested")
      if((this.history.length == 0) || (this.position >= this.history.length - 1)){
          return "";
          this.position = this.history.length;
      }
      ++this.position;
      return this.history[this.position];
    };

    SearchHistory.prototype.getLast = function() {
      if(this.history.length == 0) {
        return "";
      }
      this.position = this.history.length - 1;
      return this.history[this.position];
    };

    return SearchHistory;
})();

var Popup;
(function (Popup) {
    var prevButton = document.getElementById("prev");
    var nextButton = document.getElementById("next");
    var copyButton = document.getElementById("copy");
    var queryInput = document.getElementById("query");
    var caseInsensitiveCheckbox = document.getElementById("case-insensitive");
    var searchHistory = new SearchHistory();

    var chromeStoreURL = "https://chrome.google.com/webstore/";

    chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
      console.assert(tabs.length == 1);
      var tab = tabs[0];
      var id = tab.id;
      var tabStates = BackgroundInterface.getTabStateManager();

      if (!tabStates.exists(id)) {
          tabStates.resetState(id);
          var tabState = tabStates.get(id);
      }

      addListeners(id, tabStates);
      restoreState(id, tabStates);

      setNextButtonState(id, tabStates);
      setPrevButtonState(id, tabStates);
      setCopyButtonState(id, tabStates);

      if (tab.url.indexOf(chromeStoreURL) == 0) {
          document.getElementById("chrome-store-warning").style.display = "block";
      }
    });

    function setNextButtonState(tabId, tabStates) {
        if(tabStates !== undefined) {
            if (tabStates.isSearching(tabId)) {
                nextButton.disabled = false;
            } else {
                nextButton.disabled = true;
            }
        } else {
            nextButton.disabled = true;
        }
    }

    function setPrevButtonState(tabId, tabStates) {
        if(tabStates !== undefined) {
            if (tabStates.isSearching(tabId)) {
                prevButton.disabled = false;<commit_msg>sorry. forgot to push last night<commit_after>var HISTORY_LENGTH = 10;

var sendCommand = function sendCommand(commandName, responseHandler) {
        (function (commandName, responseHandler) {
            chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
              console.assert(tabs.length == 1);
              var tab  = tabs[0];
              if (typeof responseHandler === "undefined") {
                  responseHandler = null;
              }
              chrome.tabs.sendMessage(tab.id, { command: commandName }, responseHandler);
            });
        })(commandName, responseHandler);
    }

var BackgroundInterface;
(function (BackgroundInterface) {
    function getTabStateManager() {
        if(chrome.extension.getBackgroundPage() !== null) {
            return chrome.extension.getBackgroundPage()["BackgroundScript"].getTabStateManager();
        }
    }
    BackgroundInterface.getTabStateManager = getTabStateManager;
})(BackgroundInterface || (BackgroundInterface = {}));

var SearchHistory = (function(){
    function SearchHistory(){
      var persistentHistory = JSON.parse(localStorage.getItem("searchHistory"));
      if(persistentHistory === null){
        this.history = [];
        this.position = 0;
      } else {
        this.history = persistentHistory;
        this.position = this.history.length;
      }
      this.newQuery = false;
    };

    SearchHistory.prototype.push = function(query){
      while(this.history.length >= HISTORY_LENGTH){
        this.history.shift();
      }
      var addTheElement = true;
      for(h = 0; h < this.history.length; h++) {
        if(query == this.history[h]) {
            addTheElement = false;
            break;
        }
      }
      if(addTheElement) {
        this.history.push(query);
      }

      this.position = this.history.length - 1;
      this.newQuery = true;
      localStorage.setItem("searchHistory", JSON.stringify(this.history));
    };

    SearchHistory.prototype.prev = function() {
      if(this.newQuery){
        this.newQuery = false;
        --this.position;
        return this.history[this.position];
      }
      if(this.history.length == 0){
          return "";
      }
      if(this.position != 0) {
        --this.position;
      }
      return this.history[this.position];
    };

    SearchHistory.prototype.next = function() {
      if((this.history.length == 0) || (this.position >= this.history.length - 1)){
          this.position = this.history.length;
          return "";
      }
      ++this.position;
      return this.history[this.position];
    };

    SearchHistory.prototype.getLast = function() {
      if(this.history.length == 0) {
        return "";
      }
      this.position = this.history.length - 1;
      return this.history[this.position];
    };

    return SearchHistory;
})();

var Popup;
(function (Popup) {
    var prevButton = document.getElementById("prev");
    var nextButton = document.getElementById("next");
    var copyButton = document.getElementById("copy");
    var queryInput = document.getElementById("query");
    var caseInsensitiveCheckbox = document.getElementById("case-insensitive");
    var searchHistory = new SearchHistory();

    var chromeStoreURL = "https://chrome.google.com/webstore/";

    chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
      console.assert(tabs.length == 1);
      var tab = tabs[0];
      var id = tab.id;
      var tabStates = BackgroundInterface.getTabStateManager();

      if(tabStates !== null && tabStates.exists() !== undefined) {
          if (!tabStates.exists(id)) {
              tabStates.resetState(id);
              var tabState = tabStates.get(id);
          }
      }

      addListeners(id, tabStates);
      restoreState(id, tabStates);

      setNextButtonState(id, tabStates);
      setPrevButtonState(id, tabStates);
      setCopyButtonState(id, tabStates);

      if (tab.url.indexOf(chromeStoreURL) == 0) {
          document.getElementById("chrome-store-warning").style.display = "block";
      }
    });

    function setNextButtonState(tabId, tabStates) {
        if(tabStates !== undefined) {
            if (tabStates.isSearching(tabId)) {
                nextButton.disabled = false;
            } else {
                nextButton.disabled = true;
            }
        } else {
            nextButton.disabled = true;
        }
    }

    function setPrevButtonState(tabId, tabStates) {
        if(tabStates !== undefined) {
            if (tabStates.isSearching(tabId)) {
                prevButton.disabled = false;
{'fraction_non_alphanumeric': 0.12863891024936833, 'fraction_numerical': 0.003625178512578271, 'mean_word_length': 2.405910961466517, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5725095', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2443, 'n_words': 460}