const storage = chrome.storage.local; const submitButton = document.querySelector('#save_btn'); const addButton = document.querySelector('#add_btn'); const clearAllButton = document.querySelector('#clear_all_btn'); const new_domain = document.querySelector('#new_domain'); var settings = null; loadChanges(); submitButton.addEventListener('click', saveChanges); addButton.addEventListener('click', addDomainClick); clearAllButton.addEventListener('click', clearAllClick); async function saveChanges() { if(settings) { let domain_filter =[]; $("#block_domain_list a").each(function () { domain_filter.push($(this).attr('data-domain')); }); //console.log(domain_filter); settings.domain_filter = domain_filter; let bundle = { action: 'update_role', data: { 'settings': settings } }; const return_answer = await chrome.runtime.sendMessage(bundle); console.log(return_answer); await storage.set( { settings: settings } ); } message('Settings saved'); } function loadChanges() { storage.get('settings', function (items) { //console.log(items); if (items.settings) { settings = items.settings //message('Loaded saved settings.'); if(!settings.hasOwnProperty("domain_filter")) { settings.domain_filter = []; } for (let i = 0; i < settings.domain_filter.length; i++) { addDomainRow(settings.domain_filter[i]); } bind_remove_onclick_event(); } else { console.log('no settings found'); settings = {}; settings.domain_filter = []; } } ); } function format_domain_to_tr(user_input_domain) { let domain_item = ""; domain_item += '