<commit_before>function toggle_instructions() {
    var element = document.getElementById('instructions');
    if(element.style.display == 'block') {
        element.style.display = 'none';
    } else {
        element.style.display = 'block';
    }
}

function toggle_user_specific() {
    var element = document.getElementById('user-specific-options');
    if (element.style.display == 'block') {
        element.style.display = 'none';
    } else {
        element.style.display = 'block';
    }
}

function save_options() {
  var bgURL = document.getElementById('bgURL').value;
  var bgTile = document.getElementById('bgTile').checked;
  var bgColour = document.getElementById('bgColour').value;
  var bgType = document.getElementById('bgType').value;

  var userBgOptions = new Array();

  $('#user-options .user-option').each(function() {
      username = $(this).find('input.username').val().trim();
      if(username != '') {
          uname = username;
          userImage = $(this).find('input.userimage').val().trim();
          userTile = $(this).find('input.usertile').is(':checked');
          userColour = $(this).find('input.usercolour').val().trim();
          userType = $(this).find('select.userbgtype').val().trim();

          var usrImage = new Image();
          usrImage.crossOrigin = 'Anonymous';
          usrImage.onload = function(){
            var canvas = document.createElement('CANVAS');
            var context = canvas.getContext('2d');

            canvas.height = this.height;
            canvas.width = this.width;
            context.drawImage(this, 0, 0);
            var userBase64 = canvas.toDataURL();
            canvas = null;
            userBgOptions.push([uname, userImage, userBase64, userTile, userColour, userType]);
          };
          usrImage.src = userImage;
      }
  });

  var image = new Image();
  image.crossOrigin = 'Anonymous';
  image.onload = function(){

    var canvas = document.createElement('CANVAS');
    var context = canvas.getContext('2d');

    canvas.height = this.height;
    canvas.width = this.width;
    context.drawImage(this, 0, 0);
    var bgBase64 = canvas.toDataURL();
    canvas = null;

    chrome.storage.local.set({
      backgroundBase64: bgBase64,
      userOptions: userBgOptions
    }, function() { });

    chrome.storage.sync.set({
      backgroundURL: bgURL,
      backgroundTile: bgTile,
      backgroundColour: bgColour,
      backgroundType: bgType
    }, function() {
      var status = document.getElementById('status');
      status.textContent = 'Options saved.';
      setTimeout(function() {
        status.textContent = '';
      }, 750);
    });
  };
  image.src = bgURL;
}<commit_msg>Fixed bug where large images were not being saved in time for user options<commit_after>function toggle_instructions() {
    var element = document.getElementById('instructions');
    if(element.style.display == 'block') {
        element.style.display = 'none';
    } else {
        element.style.display = 'block';
    }
}

function toggle_user_specific() {
    var element = document.getElementById('user-specific-options');
    if (element.style.display == 'block') {
        element.style.display = 'none';
    } else {
        element.style.display = 'block';
    }
}

function save_options() {
  var bgURL = document.getElementById('bgURL').value;
  var bgTile = document.getElementById('bgTile').checked;
  var bgColour = document.getElementById('bgColour').value;
  var bgType = document.getElementById('bgType').value;

  var userBgOptions = new Array();

  var status = document.getElementById('status');
  status.textContent = 'Saving...';

  $('#user-options .user-option').each(function() {
      username = $(this).find('input.username').val().trim();
      if(username != '') {
          uname = username;
          userImage = $(this).find('input.userimage').val().trim();
          userTile = $(this).find('input.usertile').is(':checked');
          userColour = $(this).find('input.usercolour').val().trim();
          userType = $(this).find('select.userbgtype').val().trim();

          var usrImage = new Image();
          usrImage.crossOrigin = 'Anonymous';
          usrImage.onload = function(){
            var canvas = document.createElement('CANVAS');
            var context = canvas.getContext('2d');

            canvas.height = this.height;
            canvas.width = this.width;
            context.drawImage(this, 0, 0);
            var userBase64 = canvas.toDataURL();
            canvas = null;
            userBgOptions.push([uname, userImage, userBase64, userTile, userColour, userType]);
            chrome.storage.local.set({
              userOptions: userBgOptions
            }, function() { });
          };
          usrImage.src = userImage;
      }
  });

  var image = new Image();
  image.crossOrigin = 'Anonymous';
  image.onload = function(){

    var canvas = document.createElement('CANVAS');
    var context = canvas.getContext('2d');

    canvas.height = this.height;
    canvas.width = this.width;
    context.drawImage(this, 0, 0);
    var bgBase64 = canvas.toDataURL();
    canvas = null;

    chrome.storage.local.set({
      backgroundBase64: bgBase64
    }, function() { });

    chrome.storage.sync.set({
      backgroundURL: bgURL,
      backgroundTile: bgTile,
      backgroundColour: bgColour,
      backgroundType: bgType
    }, function() {
      var status = document.getElementById('status');
      status.textContent = 'Options saved.';
      setTimeout(function() {
        status.textContent = '';
      }, 750);
    });
  };
  image.src = bgURL;
}
{'fraction_non_alphanumeric': 0.1501068376068376, 'fraction_numerical': 0.006766381766381766, 'mean_word_length': 2.6881155613919896, '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': '6913142', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1569, 'n_words': 310}