<commit_before>
// Helpers 

// From http://stackoverflow.com/questions/3431512/javascript-equivalent-to-phps-urldecode
function urldecode (str) {
  return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}

// From http://stackoverflow.com/questions/12168909/blob-from-dataurl
function dataURItoBlob(dataURI) {
  // convert base64 to raw binary data held in a string
  // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  var byteString = atob(dataURI.split(',')[1]);

  // separate out the mime component
  var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]

  // write the bytes of the string to an ArrayBuffer
  var ab = new ArrayBuffer(byteString.length);
  var ia = new Uint8Array(ab);
  for (var i = 0; i < byteString.length; i++) {
      ia[i] = byteString.charCodeAt(i);
  }

  // write the ArrayBuffer to a blob, and you're done
  var blob = new Blob([ab], {type: mimeString});
  return blob;
}


	//from http://snipplr.com/view/14074/
 
 String.prototype.between = function(prefix, suffix) {
  s = this;
  var i = s.indexOf(prefix);
  if (i >= 0) {
    s = s.substring(i + prefix.length);
  }
  else {
    return '';
  }
  if (suffix) {
    i = s.indexOf(suffix);
    if (i >= 0) {
      s = s.substring(0, i);
    }
    else {
      return '';
    }
  }
  return s;
}


// State Vars

var api_key;
var localpatterns = [];

chrome.storage.sync.get('apikey', function (result) { 
    api_key = result.apikey; 
});

chrome.storage.sync.get('localpatterns', function (result) { 
    if (result.localpatterns == undefined)
    {
        return;
    }
    
    localpatterns = result.localpatterns; 
    
    url_patterns = url_patterns.concat(localpatterns);
});

// Actions

function send_form(url, formData, sendResponse)
{
    console.log("Uploading " + formData + " to JSIT...");
    
    var http = new XMLHttpRequest();    
    http.open("POST", url, true);

    http.onreadystatechange = function() {
        if(http.readyState == 4) 
        {
            resp = http.responseXML;
            s = resp.getElementsByTagName("status")[0].innerHTML;
            
            if ( s != "SUCCESS" )
            {
                m = urldecode(resp.getElementsByTagName("message")[0].innerHTML);
                alert("Torrent upload failed!\n"+ m);
                sendResponse("failure");
            }
            else
            {
                sendResponse("success");          
            }
        }
    };
  
    http.send(formData);
}<commit_msg>Refactor Success/Fail on Upload Detect 200 success response code to accomdate when API goes down or there is some other issue with connection<commit_after>
// Helpers 

// From http://stackoverflow.com/questions/3431512/javascript-equivalent-to-phps-urldecode
function urldecode (str) {
  return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}

// From http://stackoverflow.com/questions/12168909/blob-from-dataurl
function dataURItoBlob(dataURI) {
  // convert base64 to raw binary data held in a string
  // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  var byteString = atob(dataURI.split(',')[1]);

  // separate out the mime component
  var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]

  // write the bytes of the string to an ArrayBuffer
  var ab = new ArrayBuffer(byteString.length);
  var ia = new Uint8Array(ab);
  for (var i = 0; i < byteString.length; i++) {
      ia[i] = byteString.charCodeAt(i);
  }

  // write the ArrayBuffer to a blob, and you're done
  var blob = new Blob([ab], {type: mimeString});
  return blob;
}


	//from http://snipplr.com/view/14074/
 
 String.prototype.between = function(prefix, suffix) {
  s = this;
  var i = s.indexOf(prefix);
  if (i >= 0) {
    s = s.substring(i + prefix.length);
  }
  else {
    return '';
  }
  if (suffix) {
    i = s.indexOf(suffix);
    if (i >= 0) {
      s = s.substring(0, i);
    }
    else {
      return '';
    }
  }
  return s;
}


// State Vars

var api_key;
var localpatterns = [];

chrome.storage.sync.get('apikey', function (result) { 
    api_key = result.apikey; 
});

chrome.storage.sync.get('localpatterns', function (result) { 
    if (result.localpatterns == undefined)
    {
        return;
    }
    
    localpatterns = result.localpatterns; 
    
    url_patterns = url_patterns.concat(localpatterns);
});

// Actions

function send_form(url, formData, sendResponse)
{
    console.log("Uploading " + formData + " to JSIT...");
    
    var http = new XMLHttpRequest();    
    http.open("POST", url, true);

    http.onreadystatechange = function() {
        if(http.readyState === XMLHttpRequest.DONE)
        {
            if(http.status === 200)
            {
                resp = http.responseXML;
                s = resp.getElementsByTagName("status")[0].innerHTML;
                
                if ( s != "SUCCESS" )
                {
                    m = urldecode(resp.getElementsByTagName("message")[0].innerHTML);
                    alert("Torrent upload failed!\n"+ m);
                    sendResponse("failure");
                }
                else
                {
                    sendResponse("success");          
                }
            }
            else
            {
                alert("Torrent upload failed!\nIssue with connection/server");
                sendResponse("failure");
            }
        }
    };

    http.send(formData);
}
{'fraction_non_alphanumeric': 0.14027397260273972, 'fraction_numerical': 0.016621004566210046, 'mean_word_length': 2.2042129900526626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '630852', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1719, 'n_words': 397}