<commit_before>// This callback function is called when the content script has been
// injected and returned its results
function onPageInfo(o)  {
    console.log(o);
    document.getElementById('title').value = o.title;
    document.getElementById('url').value = o.url;
    document.getElementById('tags').value = o.tags;
}

// Global reference to the status display SPAN
var statusDisplay = null;

// function navigate(url){
//     console.log('navigate to ' + url);
//     location.href = "login.html";
// }

// POST the data to the server using XMLHttpRequest
function addBookmark() {
    // Cancel the form submit
    event.preventDefault();

    var user = "";
    var password = "";
    var token = "";
     // The URL to POST our data to
    var postUrl = 'http://api.dotmarks.net/dotmarks';


    // chrome.storage.local.get({
    //     username: '',
    //     token: ''
    //   }, function(items) {
    //     user = items.username;
    //     token = items.token;
    //     // postUrl = items.url;
    //   });

    // Set up an asynchronous AJAX POST request
    var xhr = new XMLHttpRequest();
    xhr.open('POST', postUrl, true);

    // console.log(decode64(token));
    // console.log(token);

    // if(token === ''){
    //     console.log("empty")
    //     chrome.storage.local.set({
    //         location: 'popup.html'
    //     },
    //         navigate(location)
    //     );
    // }

    // Prepare the data to be POSTed
    var title = document.getElementById('title').value.trim();
    var url = document.getElementById('url').value.trim();
    var tags = document.getElementById('tags').value.trim();


    // Set correct header for form data
    xhr.setRequestHeader('Content-type', 'application/json');
    // xhr.setRequestHeader('Authorization', 'Basic ' + token);

    // Handle request state change events
    xhr.onreadystatechange = function() {
        // If the request completed
        var timeOut = 0;
        if (xhr.readyState == 4) {
            statusDisplay.innerHTML = '';
            console.log(xhr.status);
            if (xhr.status === 201) {
                // If it was a success, close the popup after a short delay
                statusDisplay.innerHTML = 'Saved!';
                timeOut = 1000;
            } else if(xhr.status === 0){
              statusDisplay.innerHTML = 'Error: dotMarks is unreachable!';
              timeOut = 2500;
            }
            // else if(xhr.status === 401){
            //     chrome.storage.local.set({
            //         location: 'popup.html'
            //     },
            //         navigate('login.html')
            //     );
            }else {// Show what went wrong
                var res = JSON.parse(xhr.response);
                var errorMsg = res._issues.url;
                if( errorMsg !== undefined){
                  if(errorMsg.indexOf("is not unique") > 0){
                    statusDisplay.innerHTML = 'Error saving: url already saved!';
                  }else{
                    statusDisplay.innerHTML = 'Error saving: ' + res._issues.url;
                  }
                }else{
                  statusDisplay.innerHTML = 'Error saving: ' + xhr.statusText;
                }
                timeOut= 2500;
            }
            window.setTimeout(window.close, timeOut);
        }
    };

    xhr.send(serializeObject(title, url, tags));
    statusDisplay.innerHTML = 'Saving...';
}

 function serializeObject(title, url, tags){<commit_msg>issue with }<commit_after>// This callback function is called when the content script has been
// injected and returned its results
function onPageInfo(o)  {
    console.log(o);
    document.getElementById('title').value = o.title;
    document.getElementById('url').value = o.url;
    document.getElementById('tags').value = o.tags;
}

// Global reference to the status display SPAN
var statusDisplay = null;

// function navigate(url){
//     console.log('navigate to ' + url);
//     location.href = "login.html";
// }

// POST the data to the server using XMLHttpRequest
function addBookmark() {
    // Cancel the form submit
    event.preventDefault();

    var user = "";
    var password = "";
    var token = "";
     // The URL to POST our data to
    var postUrl = 'http://api.dotmarks.net/dotmarks';

    // Set up an asynchronous AJAX POST request
    var xhr = new XMLHttpRequest();
    xhr.open('POST', postUrl, true);

    // Prepare the data to be POSTed
    var title = document.getElementById('title').value.trim();
    var url = document.getElementById('url').value.trim();
    var tags = document.getElementById('tags').value.trim();


    // Set correct header for form data
    xhr.setRequestHeader('Content-type', 'application/json');
    // xhr.setRequestHeader('Authorization', 'Basic ' + token);

    // Handle request state change events
    xhr.onreadystatechange = function() {
        // If the request completed
        var timeOut = 0;
        if (xhr.readyState == 4) {
            statusDisplay.innerHTML = '';
            console.log(xhr.status);
            if (xhr.status === 201) {
                // If it was a success, close the popup after a short delay
                statusDisplay.innerHTML = 'Saved!';
                timeOut = 1000;
            } else if(xhr.status === 0){
              statusDisplay.innerHTML = 'Error: dotMarks is unreachable!';
              timeOut = 2500;
            // }
            // else if(xhr.status === 401){
            //     chrome.storage.local.set({
            //         location: 'popup.html'
            //     },
            //         navigate('login.html')
            //     );
            }else {// Show what went wrong
                var res = JSON.parse(xhr.response);
                var errorMsg = res._issues.url;
                if( errorMsg !== undefined){
                  if(errorMsg.indexOf("is not unique") > 0){
                    statusDisplay.innerHTML = 'Error saving: url already saved!';
                  }else{
                    statusDisplay.innerHTML = 'Error saving: ' + res._issues.url;
                  }
                }else{
                  statusDisplay.innerHTML = 'Error saving: ' + xhr.statusText;
                }
                timeOut= 2500;
            }
            window.setTimeout(window.close, timeOut);
        }
    };

    xhr.send(serializeObject(title, url, tags));
    statusDisplay.innerHTML = 'Saving...';
};

 function serializeObject(title, url, tags){
{'fraction_non_alphanumeric': 0.13167205045377633, 'fraction_numerical': 0.007075834487002, 'mean_word_length': 1.7774455360956856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5644837', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1723, 'n_words': 451}