<commit_before>var items;
var json;

function updateJSON(){
    var is_multiline = $('#json_multiline').prop('checked');
    json = '[';
    var first = true;
    items.forEach(function(item){
        if(!first){
            json += ',';
        }
        if(is_multiline) json += '\n  ';
        json += JSON.stringify(item);
        first = false;
    })
    if(is_multiline) json += '\n';
    json += ']';
    return json;
}

function updateUI(){
    $('#list_header').text('List: ' + items.length);
    $('#json').val(json);
}

function update(){
    var text = $('#text').val();
    var id = items.length;
    var when = new Date().toISOString();
    var item = {
        'text': text,
        'when': when,
        'id': id};

    $('input[type=text]').each(function(i, x){
        if(x.value != ''){
            item[x.id] = x.value;
        }
    })
    items.push(item);

    // clear
    $('#text').val('');
    $('#pages').val('');
    $('#original_text').val('');

    // update JSON
    updateJSON();

    updateUI();
    localStorage.setItem('collecting_ideas', json);
}

$(function(){
    items = localStorage.getItem('collecting_ideas');
    try{
        if(items == null){
            items = [];
        }else{
            items = JSON.parse(items);
        }
    }catch(e){
        console.log(items);
        console.log('cannot understand as JSON')
        items = [];
    }

    $('input[type=text]').keypress(function(e) {
        if (e.keyCode == 13) update();
    });
    $('#text').keypress(function(e) {
        if (e.keyCode == 13){
            update();
            return false;
        }
    });

    $('#json_multiline').click(function(){
        updateJSON();
        updateUI();
    })

    // update AppCache
    window.applicationCache.addEventListener(
        "updateready", function() {
            window.applicationCache.swapCache();
            location.reload();
        }
    );
    $('#updateAppCache').click(function(){<commit_msg>goog-ify<commit_after>/**
 * grouping
 * (c) 2013, Cybozu.
 */
goog.provide('main.main');

var items;
var json;

function updateJSON(){
    var is_multiline = $('#json_multiline').prop('checked');
    json = '[';
    var first = true;
    items.forEach(function(item){
        if(!first){
            json += ',';
        }
        if(is_multiline) json += '\n  ';
        json += JSON.stringify(item);
        first = false;
    })
    if(is_multiline) json += '\n';
    json += ']';
    return json;
}

function updateUI(){
    $('#list_header').text('List: ' + items.length);
    $('#json').val(json);
}

function update(){
    var text = $('#text').val();
    var id = items.length;
    var when = new Date().toISOString();
    var item = {
        'text': text,
        'when': when,
        'id': id};

    $('input[type=text]').each(function(i, x){
        if(x.value != ''){
            item[x.id] = x.value;
        }
    })
    items.push(item);

    // clear
    $('#text').val('');
    $('#pages').val('');
    $('#original_text').val('');

    // update JSON
    updateJSON();

    updateUI();
    localStorage.setItem('collecting_ideas', json);
}

var realtimeOptions = {};
var realtimeLoader;
function startRealtime(){
    realtimeLoader = new rtclient.RealtimeLoader(realtimeOptions);
    realtimeLoader.start();
    setInterval(function() {
        console.log('re-authorizing' + new Date());
        realtimeLoader.authorizer.authorize();
        console.log('re-authorized' + new Date());
    }, 1000 * 60 * 5);  // do auth each 5 minute

}

$(function(){
    items = localStorage.getItem('collecting_ideas');
    try{
        if(items == null){
            items = [];
        }else{
            items = JSON.parse(items);
        }
    }catch(e){
        console.log(items);
        console.log('cannot understand as JSON')
        items = [];
    }

    $('input[type=text]').keypress(function(e) {
        if (e.keyCode == 13) update();
    });
    $('#text').keypress(function(e) {
        if (e.keyCode == 13){
            update();
            return false;
        }
    });

    $('#json_multiline').click(function(){
        updateJSON();
        updateUI();
    })

    // update AppCache
    window.applicationCache.addEventListener(
        "updateready", function() {
            window.applicationCache.swapCache();
            location.reload();
        },
        false
    );
    $('#updateAppCache').click(function(){
{'fraction_non_alphanumeric': 0.19065884476534295, 'fraction_numerical': 0.004512635379061372, 'mean_word_length': 2.11963406052076, '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': '3267128', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1369, 'n_words': 252}