<commit_before>var CopyAsMarkdown = new (function() {
  var resultContainer = document.getElementById("result-markdown");

  var getCurrentTab = function (callback) {
    chrome.tabs.query({
      windowId: chrome.windows.WINDOW_ID_CURRENT,
      active: true
    }, function(tabs) {
      callback(tabs[0]);
    });
  };

  var getAllTabsOfCurrentWindow = function (callback) {
    chrome.tabs.query({
      windowId: chrome.windows.WINDOW_ID_CURRENT
    }, callback);
  };

  var defaultTitle = "(No Title)";

  var copyToClipboard = function(text) {
    resultContainer.value = text;
    resultContainer.select();
    document.execCommand('Copy');
    resultContainer.value = "";
  };

  this.getDefaultTitle = function() {
    return defaultTitle;
  };

  this.copyLink = function(title, url, options) {
    copyToClipboard(Markdown.linkTo(title, url, options));
  };

  this.copyListOfLinks = function(links, options) {
    var md_list = [];
    for(var i in links) {
      var md = Markdown.linkTo(links[i].title, links[i].url, options);
      md_list.push("* " + md);
    }

    copyToClipboard(md_list.join("\n"));
  };

  this.copyImage = function(title, url) {
    copyToClipboard(Markdown.imageFor(title, url));
  };

  this.copyCurrentTab = function(options, callback) {
    getCurrentTab(function(tab) {
      // XXX: Bad namespacing! (CoffeeScript's binding can resolve this issue)
      CopyAsMarkdown.copyLink(tab.title, tab.url, options);
      callback();
    });
  };

  this.copyAllTabs = function(options, callback) {
    getAllTabsOfCurrentWindow(function(tabs) {
      var links = [];
      for (var i in tabs) {
        var tab = tabs[i];
        links.push({
          title: tab.title,
          url: tab.url
        });
      }

      // XXX: Bad namespacing! (CoffeeScript's binding can resolve this issue)
      CopyAsMarkdown.copyListOfLinks(links, options);
      callback();
    });
  };
})();<commit_msg>flash "success" badge after copied. (1s)<commit_after>var CopyAsMarkdown = new (function() {
  var resultContainer = document.getElementById("result-markdown");

  var getCurrentTab = function (callback) {
    chrome.tabs.query({
      windowId: chrome.windows.WINDOW_ID_CURRENT,
      active: true
    }, function(tabs) {
      callback(tabs[0]);
    });
  };

  var getAllTabsOfCurrentWindow = function (callback) {
    chrome.tabs.query({
      windowId: chrome.windows.WINDOW_ID_CURRENT
    }, callback);
  };

  var defaultTitle = "(No Title)";

  var copyToClipboard = function(text) {
    resultContainer.value = text;
    resultContainer.select();
    document.execCommand('Copy');
    resultContainer.value = "";

    flashBadge("success");
  };

  this.getDefaultTitle = function() {
    return defaultTitle;
  };

  this.copyLink = function(title, url, options) {
    copyToClipboard(Markdown.linkTo(title, url, options));
  };

  this.copyListOfLinks = function(links, options) {
    var md_list = [];
    for(var i in links) {
      var md = Markdown.linkTo(links[i].title, links[i].url, options);
      md_list.push("* " + md);
    }

    copyToClipboard(md_list.join("\n"));
  };

  this.copyImage = function(title, url) {
    copyToClipboard(Markdown.imageFor(title, url));
  };

  this.copyCurrentTab = function(options, callback) {
    getCurrentTab(function(tab) {
      // XXX: Bad namespacing! (CoffeeScript's binding can resolve this issue)
      CopyAsMarkdown.copyLink(tab.title, tab.url, options);
      callback();
    });
  };

  this.copyAllTabs = function(options, callback) {
    getAllTabsOfCurrentWindow(function(tabs) {
      var links = [];
      for (var i in tabs) {
        var tab = tabs[i];
        links.push({
          title: tab.title,
          url: tab.url
        });
      }

      // XXX: Bad namespacing! (CoffeeScript's binding can resolve this issue)
      CopyAsMarkdown.copyListOfLinks(links, options);
      callback();
    });
  };

  var flashBadge = function(type) {
    var color, text;

    switch (type) {
      case "success":
        color = "#408000";
        text = "\u2713"; // Check mark
        break;
      case "fail":
        color = "#800000";
        text = "\u2717"; // Ballout X
        break;
      default:
        return; // don't know what it is. quit.
    }

    chrome.browserAction.setBadgeText({
      "text": text
    });

    chrome.browserAction.setBadgeBackgroundColor({
      "color": color
    });

    setTimeout(clearBadge, 3000);
  };

  var clearBadge = function(type, text) {
    chrome.browserAction.setBadgeText({
      text: ""
    });

    chrome.browserAction.setBadgeBackgroundColor({
      color: [0, 0, 0, 255] // opaque
    });
  };
})();
{'fraction_non_alphanumeric': 0.13961941415437246, 'fraction_numerical': 0.007055805003207184, 'mean_word_length': 2.7970779220779223, 'pattern_counts': {'":': 4, '<': 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': '4788352', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1447, 'n_words': 299}