<commit_before>/**
 * Created by <NAME>
 * <EMAIL>
 * on 29/08/2015
 */

var hosts = [];
var observe;
var bg = chrome.extension.getBackgroundPage();
var ls = bg.localStorage;

function createHost(hostname, name) {
    hosts.unshift({
        name: name,
        hostname: hostname,
        lastMod: Date.now()
    });
}

function refreshView(hosts) {
    $('#hostsList').html(hosts.map(mkRow).join(''));
    $('.killBtn').each(function () {
        $(this).click(_.partial(rmHost, $(this).attr('hostname'), $(this).attr('name')));
    });

    $('.clickHost').each(function () {
        $(this).click(_.partial(bg.openHost, $(this).attr('hostname')));
    });

    $('.clickName').each(function () {
        $(this).click(_.partial(renameHost, $(this).attr('hostname'), $(this).attr('name')));

    });
}

function rmHost(hostname, name) {
    var idx = _.findIndex(hosts, {hostname: hostname, name: name});
    if (idx > -1) hosts.splice(idx, 1);
}

function renameHost(hostname, name) {
    console.log('rename');
    var idx = _.findIndex(hosts, {hostname: hostname, name: name});
    var newname = prompt('Rename host `' + hosts[idx].name + '`', hosts[idx].name) || name;
    hosts.splice(idx, 1, _.extend(hosts[idx], {name: newname, lastMod: Date.now()}));
}

function mkClickableName(host) {
    return '<a class="clickName" hostname="' + host.hostname + '" name="' + host.name + '">' + host.name + '</a>';
}

function mkClickableHost(host) {
    return '<a href="#" class="clickHost" hostname="' + host.hostname + '">' + host.hostname + '</a>';
}

function mkExitButton(host) {
    return '<a class= "killBtn" hostname="' + host.hostname + '" name="' + host.name + '"></a>';
}

function mkRow(host) {
    return '' +
        '<tr><td>' + mkClickableHost(host) +
        '</td><td>' + mkClickableName(host) +
        '</td><td>' + moment(host.lastMod).fromNow().replace('a few ', '') +
        '</td><td class="x">' + mkExitButton(host) +
        '</td></tr>';

}

function onUpdate() {
    refreshView(hosts);
    bg.lsWrite(hosts);
}

function launch(skipLaunch) {
    var hostname = $('#mainput').val();
    createHost(hostname, $('#mainame').val());
    if (skipLaunch === true) return;
    bg.openHost(hostname);
}

function init() {
    // Initialize functions and register click on hostname area:
    $('#mainput').focus().keyup(function (event) {
        if (event.keyCode == 13) {
            $("#open").click();
        }
    });
    // Register click on name area:
    $("#mainame").keyup(function (event) {
        if (event.keyCode == 13) {
            $("#open").click();
        }
    });

    $('#open').click(launch);
    $('#add').click(_.partial(launch, true));


    hosts = bg.lsRead();
    observe = Array.observe(hosts, onUpdate);

    refreshView(hosts);
}<commit_msg>Eliminated usage of (obsolete) method Array.observe<commit_after>/**
 * Created by <NAME>
 * <EMAIL>
 * on 29/08/2015
 */

var hosts = [];
var bg = chrome.extension.getBackgroundPage();

function createHost(hostname, name) {
    hosts.unshift({
        name: name,
        hostname: hostname,
        lastMod: Date.now()
    });
    onUpdate();
}

function refreshView(hosts) {
    $('#hostsList').html(hosts.map(mkRow).join(''));
    $('.killBtn').each(function () {
        $(this).click(_.partial(rmHost, $(this).attr('hostname'), $(this).attr('name')));
    });

    $('.clickHost').each(function () {
        $(this).click(_.partial(bg.openHost, $(this).attr('hostname')));
    });

    $('.clickName').each(function () {
        $(this).click(_.partial(renameHost, $(this).attr('hostname'), $(this).attr('name')));

    });
}

function rmHost(hostname, name) {
    var idx = _.findIndex(hosts, {hostname: hostname, name: name});
    if (idx > -1) hosts.splice(idx, 1);
    onUpdate();
}

function renameHost(hostname, name) {
    console.log('rename');
    var idx = _.findIndex(hosts, {hostname: hostname, name: name});
    var newname = prompt('Rename host `' + hosts[idx].name + '`', hosts[idx].name) || name;
    hosts.splice(idx, 1, _.extend(hosts[idx], {name: newname, lastMod: Date.now()}));
    onUpdate();
}

function mkClickableName(host) {
    return '<a class="clickName" hostname="' + host.hostname + '" name="' + host.name + '">' + host.name + '</a>';
}

function mkClickableHost(host) {
    return '<a href="#" class="clickHost" hostname="' + host.hostname + '">' + host.hostname + '</a>';
}

function mkExitButton(host) {
    return '<a class= "killBtn" hostname="' + host.hostname + '" name="' + host.name + '"></a>';
}

function mkRow(host) {
    return '' +
        '<tr><td>' + mkClickableHost(host) +
        '</td><td>' + mkClickableName(host) +
        '</td><td>' + moment(host.lastMod).fromNow().replace('a few ', '') +
        '</td><td class="x">' + mkExitButton(host) +
        '</td></tr>';

}

function onUpdate() {
    refreshView(hosts);
    bg.lsWrite(hosts);
}

function launch(skipLaunch) {
    var hostname = $('#mainput').val();
    createHost(hostname, $('#mainame').val());
    if (skipLaunch === true) return;
    bg.openHost(hostname);
}

function init() {
    // Initialize functions and register click on hostname area:
    $('#mainput').focus().keyup(function (event) {
        if (event.keyCode == 13) {
            $("#open").click();
        }
    });
    // Register click on name area:
    $("#mainame").keyup(function (event) {
        if (event.keyCode == 13) {
            $("#open").click();
        }
    });

    $('#open').click(launch);
    $('#add').click(_.partial(launch, true));
    
    hosts = bg.lsRead();
    refreshView(hosts);
}
{'fraction_non_alphanumeric': 0.21932487944275764, 'fraction_numerical': 0.005358099660653688, 'mean_word_length': 3.1979010494752624, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, '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': '5814564', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1865, 'n_words': 358}