<commit_before>
const browserapi = require('./browserapi')
    , random = require('./random')
    , requests = require('./requests')


class Settings {

    constructor(storage, callback) {
        this.db = storage.local
        this.callback = callback

        this.default_active_tables = [
            'abecadlo',
            'jirecek',
            'kmu_2010',
            'lucuk',
            'melnyk',
            'nova_latynka',
            'iso9_1995',
            'tkpn_combo',
        ]

        this.storage_keys = {
            enabled: 'latynka:enabled',
            whitelist_enabled: 'latynka:whitelist_enabled',
            blacklist_enabled: 'latynka:blacklist_enabled',
            site_whitelist: 'latynka:site_whitelist',
            site_blacklist: 'latynka:site_blacklist',
            selected_table_id: 'latynka:selected_table_id',
            active_table_ids: 'latynka:active_table_ids',
            bundled_tables: 'latynka:bundled_tables',
            user_tables: 'latynka:user_tables',
            preview_text: 'latynka:preview_text',
            default_preview_text: 'latynka:default_preview_text',
        }

        this.cache = {}
        this.blacklist = new Set()
        this.whitelist = new Set()

        storage.onChanged.addListener((changes, area) => { this.onStorageChange(changes, area) })

        this._reload_cache()
    }

    onStorageChange(changes, area) {
        let has_changes = false
        Object.values(this.storage_keys).forEach((key) => {
            const change = changes[key]
            if (change) {
                this.cache[key] = change.newValue
                has_changes = true

                if (key === this.storage_keys.site_blacklist) {
                    this.blacklist = new Set(this.site_blacklist)
                }
                else if (key === this.storage_keys.site_whitelist) {
                    this.whitelist = new Set(this.site_whitelist)
                }
            }
        })
        if (has_changes) {
            this.callback()
        }
    }

    _reload_cache() {
        this.db.get((stored) => {
            const cache = {}
            Object.values(this.storage_keys).forEach((key) => {
                cache[key] = stored[key]
            })

            this.cache = cache

            this.blacklist = new Set(this.site_blacklist)
            this.whitelist = new Set(this.site_whitelist)

            this.callback()
        })
    }

    _store(key, value) {
        const obj = {}
        obj[key] = value
        this.db.set(obj)
    }

    save(items) {
        const obj = {}
        for (let key in items) {
            obj[this.storage_keys[key]] = items[key]
        }
        this.db.set(obj)
    }

    _get_bool(key, default_value) {
        const value = this.cache[key]
        return value === false ? value : value === true ? value : default_value
    }

    _get_int(key) {
        const value = this.cache[key]
        return Number.isInteger(value) ? value : 0
    }

    _get_string(key, default_value) {
        const value = this.cache[key]
        return ['', value].join('') || default_value
    }

    _get_array(key, default_value) {
        const value = this.cache[key]
        return Array.isArray(value) ? value.slice() : (default_value || [])
    }

    get enabled() {
        return this._get_bool(this.storage_keys.enabled, true)
    }
    set enabled(value) {
        this._store(this.storage_keys.enabled, value)
    }

    get whitelist_enabled() {
        return this._get_bool(this.storage_keys.whitelist_enabled, false)
    }
    set whitelist_enabled(value) {
        this._store(this.storage_keys.whitelist_enabled, value)
    }

    get blacklist_enabled() {
        return this._get_bool(this.storage_keys.blacklist_enabled, false)
    }
    set blacklist_enabled(value) {
        this._store(this.storage_keys.blacklist_enabled, value)
    }

    get selected_table_id() {
        return this._get_string(this.storage_keys.selected_table_id, 'nova_latynka')
    }

    set selected_table_id(value) {
        this._store(this.storage_keys.selected_table_id, value)
    }

    get selected_translit_table() {
        const tables = this.active_tables
        const selected_id = this.selected_table_id
        return tables.find((tbl) => tbl.id === selected_id) || tables[0]
    }

    bundled_tables() {
        const all_tables = this._get_array(this.storage_keys.bundled_tables)
        return all_tables
            .sort((a,b) => (a.title || '').localeCompare(b.title))
    }
<commit_msg>:see_no_evil: blacklist on by default<commit_after>
const browserapi = require('./browserapi')
    , random = require('./random')
    , requests = require('./requests')


class Settings {

    constructor(storage, callback) {
        this.db = storage.local
        this.callback = callback

        this.default_active_tables = [
            'abecadlo',
            'jirecek',
            'kmu_2010',
            'lucuk',
            'melnyk',
            'nova_latynka',
            'iso9_1995',
            'tkpn_combo',
        ]

        this.storage_keys = {
            enabled: 'latynka:enabled',
            whitelist_enabled: 'latynka:whitelist_enabled',
            blacklist_enabled: 'latynka:blacklist_enabled',
            site_whitelist: 'latynka:site_whitelist',
            site_blacklist: 'latynka:site_blacklist',
            selected_table_id: 'latynka:selected_table_id',
            active_table_ids: 'latynka:active_table_ids',
            bundled_tables: 'latynka:bundled_tables',
            user_tables: 'latynka:user_tables',
            preview_text: 'latynka:preview_text',
            default_preview_text: 'latynka:default_preview_text',
        }

        this.cache = {}
        this.blacklist = new Set()
        this.whitelist = new Set()

        storage.onChanged.addListener((changes, area) => { this.onStorageChange(changes, area) })

        this._reload_cache()
    }

    onStorageChange(changes, area) {
        let has_changes = false
        Object.values(this.storage_keys).forEach((key) => {
            const change = changes[key]
            if (change) {
                this.cache[key] = change.newValue
                has_changes = true

                if (key === this.storage_keys.site_blacklist) {
                    this.blacklist = new Set(this.site_blacklist)
                }
                else if (key === this.storage_keys.site_whitelist) {
                    this.whitelist = new Set(this.site_whitelist)
                }
            }
        })
        if (has_changes) {
            this.callback()
        }
    }

    _reload_cache() {
        this.db.get((stored) => {
            const cache = {}
            Object.values(this.storage_keys).forEach((key) => {
                cache[key] = stored[key]
            })

            this.cache = cache

            this.blacklist = new Set(this.site_blacklist)
            this.whitelist = new Set(this.site_whitelist)

            this.callback()
        })
    }

    _store(key, value) {
        const obj = {}
        obj[key] = value
        this.db.set(obj)
    }

    save(items) {
        const obj = {}
        for (let key in items) {
            obj[this.storage_keys[key]] = items[key]
        }
        this.db.set(obj)
    }

    _get_bool(key, default_value) {
        const value = this.cache[key]
        return value === false ? value : value === true ? value : default_value
    }

    _get_int(key) {
        const value = this.cache[key]
        return Number.isInteger(value) ? value : 0
    }

    _get_string(key, default_value) {
        const value = this.cache[key]
        return ['', value].join('') || default_value
    }

    _get_array(key, default_value) {
        const value = this.cache[key]
        return Array.isArray(value) ? value.slice() : (default_value || [])
    }

    get enabled() {
        return this._get_bool(this.storage_keys.enabled, true)
    }
    set enabled(value) {
        this._store(this.storage_keys.enabled, value)
    }

    get whitelist_enabled() {
        return this._get_bool(this.storage_keys.whitelist_enabled, false)
    }
    set whitelist_enabled(value) {
        this._store(this.storage_keys.whitelist_enabled, value)
    }

    get blacklist_enabled() {
        return this._get_bool(this.storage_keys.blacklist_enabled, true)
    }
    set blacklist_enabled(value) {
        this._store(this.storage_keys.blacklist_enabled, value)
    }

    get selected_table_id() {
        return this._get_string(this.storage_keys.selected_table_id, 'nova_latynka')
    }

    set selected_table_id(value) {
        this._store(this.storage_keys.selected_table_id, value)
    }

    get selected_translit_table() {
        const tables = this.active_tables
        const selected_id = this.selected_table_id
        return tables.find((tbl) => tbl.id === selected_id) || tables[0]
    }

    bundled_tables() {
        const all_tables = this._get_array(this.storage_keys.bundled_tables)
        return all_tables
            .sort((a,b) => (a.title || '').localeCompare(b.title))
    }

{'fraction_non_alphanumeric': 0.11389771109407514, 'fraction_numerical': 0.0024093746577592817, 'mean_word_length': 1.985289310232102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '722761', 'n_tokens_mistral': 2838, 'n_tokens_neox': 2746, 'n_words': 446}