<commit_before>var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var tabs = require("sdk/tabs");
var self = require("sdk/self");

var data = require("sdk/self").data;
var contentScriptFile = data.url("get-action.js");

var button = ToggleButton({
  id: "my-button",
  label: "my button",
  icon: {
    "16": "./icon-16.png",
    "32": "./icon-32.png",
    "64": "./icon-64.png"
  },
  onChange: handleChange
});

var panel = panels.Panel({
  contentURL: self.data.url("panel.html"),
  onHide: handleHide,
  contentScriptFile: contentScriptFile
});

function handleChange(state) {
  if (state.checked) {
    panel.show({
      position: button
    });
  }
}

function handleHide() {
  button.state('window', {checked: false});
}

panel.port.on("goingHome", function() {
  console.log('In index.js - going home');
  panel.hide();
});

panel.port.on("bookmarkPage", function() {
  console.log('In index.js - bookmarking: ' + tabs.activeTab.url);
  panel.hide();
});<commit_msg>We can now get the auth token from the bookmarkly cookie<commit_after>var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var tabs = require("sdk/tabs");
var self = require("sdk/self");

var {Cc, Ci} = require("chrome");
// var cookieSvc = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);

var cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);

var data = require("sdk/self").data;
var contentScriptFile = data.url("get-action.js");

var button = ToggleButton({
  id: "my-button",
  label: "my button",
  icon: {
    "16": "./icon-16.png",
    "32": "./icon-32.png",
    "64": "./icon-64.png"
  },
  onChange: handleChange
});

var panel = panels.Panel({
  contentURL: self.data.url("panel.html"),
  onHide: handleHide,
  contentScriptFile: contentScriptFile
});

function handleChange(state) {
  if (state.checked) {
    panel.show({
      position: button
    });
  }
}

function handleHide() {
  button.state('window', {checked: false});
}

panel.port.on("goingHome", function() {
  console.log('In index.js - going home');
  panel.hide();
});

panel.port.on("bookmarkPage", function() {

  var cookies = cookieManager.getCookiesFromHost("leonieknox.com");
  // var cookies = cookieManager.enumerator

  while (cookies.hasMoreElements()) {
    var cookie = cookies.getNext().QueryInterface(Ci.nsICookie2);

    if (cookie.name === 'bookmarklyLogin') {
        dump(cookie.host + ";" + cookie.name + "=" + cookie.value + "\n");
        var cookieValue = JSON.parse(unescape(cookie.value));
        // console.log(JSON.stringify(cookieValue));
        // console.log('Screen name: ' + cookieValue['screenName']);
        console.log('Token: ' + cookieValue.token);
    }
  }

  panel.hide();
});
{'fraction_non_alphanumeric': 0.18865905848787445, 'fraction_numerical': 0.009985734664764621, 'mean_word_length': 3.8867595818815333, 'pattern_counts': {'":': 6, '<': 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': '2285875', 'n_tokens_mistral': 958, 'n_tokens_neox': 937, 'n_words': 183}