<commit_before>/**
 * 设置页面保存与回复设置相关的js
 *@user Joseph
 */
// Saves options to localStorage.
function save_options() {
    localStorage["etym"] = $("input[name=etym]:checked").val();
    localStorage["click2s"] = $("input[name=click2s]:checked").val();
    localStorage["exchanges"] = $("input[name=exchanges]:checked").val();
    localStorage["phrases"] = $("input[name=phrases]:checked").val();
    localStorage["root2note"] = $("input[name=root2note]:checked").val();
    localStorage["afx2note"] = $("input[name=afx2note]:checked").val();
    localStorage["hide_cn"] = $("input[name=hide_cn]:checked").val();
    localStorage["web_en"] = $("input[name=web_en]:checked").val();
    localStorage["not_pop"] = $("input[name=not_pop]:checked").val();
    localStorage["ctx_menu"] = $("input[name=ctx_menu]:checked").val();
    localStorage["dict"] = $("input[name=dict]:checked").val();
    localStorage["skip_easy"] = $("input[name=skip_easy]:checked").val();
    localStorage["show_syllabe"] = $("input[name=show_syllabe]:checked").val();
    localStorage["hider"] = $("input[name=hider]:checkbox:checked").map(function (i, e) {
        return $(e).val()
    }).toArray();
    localStorage["web_key"] = $('textarea[name=web_key]').val().trim().split('\n');


    // Update status to let user know options were saved.
    var status = document.getElementById("status");
    status.innerHTML = "保存成功";
    setTimeout(function () {
        status.innerHTML = "";
    }, 750);
    chrome.runtime.sendMessage({method: "setLocalStorage", data: localStorage});

}

// Restores select box state to saved value from localStorage.
function restore_options() {
    $("input[name=etym][value=" + localStorage["etym"] + "]").attr("checked", true);
    $("input[name=click2s][value=" + localStorage["click2s"] + "]").attr("checked", true);
    $("input[name=exchanges][value=" + localStorage["exchanges"] + "]").attr("checked", true);
    $("input[name=phrases][value=" + localStorage["phrases"] + "]").attr("checked", true);
    $("input[name=root2note][value=" + localStorage["root2note"] + "]").attr("checked", true);
    $("input[name=afx2note][value=" + localStorage["afx2note"] + "]").attr("checked", true);
    $("input[name=hide_cn][value=" + localStorage["hide_cn"] + "]").attr("checked", true);
    $("input[name=web_en][value=" + localStorage["web_en"] + "]").attr("checked", true);
    $("input[name=not_pop][value=" + localStorage["not_pop"] + "]").attr("checked", true);
    $("input[name=ctx_menu][value=" + localStorage["ctx_menu"] + "]").attr("checked", true);
    $("input[name=dict][value=" + localStorage["dict"] + "]").attr("checked", true);
    $("input[name=skip_easy][value=" + localStorage["skip_easy"] + "]").attr("checked", true);
    $("input[name=show_syllabe][value=" + localStorage["show_syllabe"] + "]").attr("checked", true);
//    $('textarea[name=web_key]').val(localStorage["web_key"])
    var hider = localStorage["hider"];
    if (undefined == hider) hider = [];
    else hider = hider.split(',');
    $("input[name=hider]:checkbox").val(hider);
    var keys = localStorage["web_key"];
    if (undefined == keys) keys = '';
    else keys = keys.replace(/,/g, '\n');
    $("textarea[name=web_key]").val(keys)
}

function test_keys() {<commit_msg>简化配置存取<commit_after>/**
 * 设置页面保存与回复设置相关的js
 *@user Joseph
 */
// Saves options to localStorage.
function save_options() {
    $('input[type=radio]').each(function (index) {
        var name = $(this).name();
        localStorage[name] = $("input[name=" + name + "]:checked").val();
    });
    localStorage["hider"] = $("input[name=hider]:checkbox:checked").map(function (i, e) {
        return $(e).val()
    }).toArray();
    localStorage["web_key"] = $('textarea[name=web_key]').val().trim().split('\n');


    // Update status to let user know options were saved.
    var status = document.getElementById("status");
    status.innerHTML = "保存成功";
    setTimeout(function () {
        status.innerHTML = "";
    }, 750);
    chrome.runtime.sendMessage({method: "setLocalStorage", data: localStorage});

}

// Restores select box state to saved value from localStorage.
function restore_options() {
    $('input[type=radio]').each(function (index) {
       var name = $(this).name();
       $("input[name=" + name+ "][value=" + localStorage[name] + "]").attr("checked", true);
    });
//    $('textarea[name=web_key]').val(localStorage["web_key"])
    var hider = localStorage["hider"];
    if (undefined == hider) hider = [];
    else hider = hider.split(',');
    $("input[name=hider]:checkbox").val(hider);
    var keys = localStorage["web_key"];
    if (undefined == keys) keys = '';
    else keys = keys.replace(/,/g, '\n');
    $("textarea[name=web_key]").val(keys)
}

function test_keys() {
{'fraction_non_alphanumeric': 0.23060796645702306, 'fraction_numerical': 0.0037735849056603774, 'mean_word_length': 4.948877805486284, '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': '2168754', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1590, 'n_words': 252}