<commit_before>(function() {
  'use strict';

  /* global app, chrome */

  var Config = app.Config;
  var Keymap = app.Keymap;

  var self = {

    /** Cached properties */
    keymap: Keymap.empty(),

    /** Cached user script */
    script: '',

    /**
     * Initialize data
     */
    init: function() {

      // config
      var req = { func: 'load' };

      chrome.runtime.sendMessage(req, function(res) {
        if (res.error) {
          console.error(res.error);
          return;
        }

        var config = new Config(res.data.config);
        self.keymap = config.keymap;
        self.script = self.convert(config.script);
      });

      // handler
      window.addEventListener('keydown', function(ev) {
        if (!self.keymap.match(new Keymap(ev))) {
          return;
        }

        ev.preventDefault();
        ev.stopPropagation();

        var el = document.createElement('script');
        el.textContent = self.script;
        document.body.appendChild(el);
        document.body.removeChild(el);
      });
    },

    /**
     * Convert bookmarklet script into runnable javascript
     *
     * @param {string} script
     */
    convert: function(script) {

      //
      // validate
      //
      if (!/^javascript:/.test(script)) {
        console.error('Bookmarklet script must starts with string "javascript:"');
        return '';
      }

      //
      // convert
      //
      var prev = [
        'var entry = document.querySelector(".selectedEntry");',
        'var entryObject = entry ? entry.querySelector("a.title") : null;',
        'var entryTitle  = entryObject ? entryObject.textContent : "";',
        'var entryLocation = entryObject ? entryObject.href : "";'
      ].join('');

      var body = script.trim()
        .replace(/javascript:\(function\(\)\{(.*)\}\)\(\)/, '$1')<commit_msg>Do not run script when expected values not found<commit_after>(function() {
  'use strict';

  /* global app, chrome */

  var Config = app.Config;
  var Keymap = app.Keymap;

  var self = {

    /** Cached properties */
    keymap: Keymap.empty(),

    /** Cached user script */
    script: '',

    /**
     * Initialize data
     */
    init: function() {

      // config
      var req = { func: 'load' };

      chrome.runtime.sendMessage(req, function(res) {
        if (res.error) {
          console.error(res.error);
          return;
        }

        var config = new Config(res.data.config);
        self.keymap = config.keymap;
        self.script = self.convert(config.script);
      });

      // handler
      window.addEventListener('keydown', function(ev) {
        if (!self.keymap.match(new Keymap(ev))) {
          return;
        }

        ev.preventDefault();
        ev.stopPropagation();

        var el = document.createElement('script');
        el.textContent = self.script;
        document.body.appendChild(el);
        document.body.removeChild(el);
      });
    },

    /**
     * Convert bookmarklet script into runnable javascript
     *
     * @param {string} script
     */
    convert: function(script) {

      //
      // validate
      //
      if (!/^javascript:/.test(script)) {
        console.error('Bookmarklet script must starts with string "javascript:"');
        return '';
      }

      //
      // convert
      //
      var prev = [
        'var entry = document.querySelector(".selectedEntry");',
        'if (!entry) { return; } ',
        'var entryObject = entry.querySelector("a.title");',
        'if (!entryObject) { return; } ',
        'var entryTitle  = entryObject.textContent;',
        'var entryLocation = entryObject.href;',
        'if (!entryTitle || !entryLocation) { return ; } '
      ].join('');

      var body = script.trim()
        .replace(/javascript:\(function\(\)\{(.*)\}\)\(\)/, '$1')
{'fraction_non_alphanumeric': 0.1581151832460733, 'fraction_numerical': 0.0005235602094240838, 'mean_word_length': 1.8903177004538578, 'pattern_counts': {'":': 0, '<': 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': '6859354', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1101, 'n_words': 229}