if(typeof browser === 'undefined') {
  window.browser = window.chrome;
}

const STORE_NAME = 'pptw_settings';
const SETTINGS_LIST = [
  {
    id: 'update_check',
    value: 'checked',
  },
  {
    id: 'update_check_interval',
    value: 'value',
  },
  {
    id: 'mute_by_key',
    value: 'checked',
  },
  {
    id: 'block_by_key',
    value: 'checked',
  },
];

const configUI = {

  extractSettings : () => {
    const ret = [];
    SETTINGS_LIST.forEach((setting) => {
      const inpElm = document.getElementById(setting.id);
      ret.push({
        id: setting.id,
        value: setting.id === 'update_check_interval' ? parseInt(inpElm[setting.value]) : inpElm[setting.value],
      });
    });
    console.log(`${JSON.stringify(ret)}`);
    return ret;
  },

  restoreEntries : () => {
    browser.storage.local.get(STORE_NAME, (store_obj) => {
      const result = store_obj[STORE_NAME];
      if(!result || !Array.isArray(result) || result.length === 0) {
        console.log('nothing');
        return;
      }
      console.log(`restore ${JSON.stringify(result)}`);
      result.forEach((setting) => {
        const inpElm = document.getElementById(setting.id);
        if(typeof setting.value === 'boolean') {
          inpElm.checked = setting.value;
        }
        else {
          inpElm.value = setting.value;
        }
      });
    });
  },

  saveEntries : () => {
    browser.storage.local.set({
      [STORE_NAME]: configUI.extractSettings(),
    });
  }

};

document.addEventListener('DOMContentLoaded', configUI.restoreEntries);
document.getElementById('save').addEventListener('click', configUI.saveEntries);

document.getElementById('update_check_interval').addEventListener("input", (e) => {
  if (e.target.validity.valid) {
    document.getElementById('save').disabled = false;
  } else {
    document.getElementById('save').disabled = true;
  }
});

// vim:expandtab ff=dos fenc=utf-8 sw=2

@@ -735,52 +735,8 @@
 );%0D%0A
-    console.log(%60$%7BJSON.stringify(ret)%7D%60);%0D%0A
     
@@ -971,114 +971,24 @@
     
-console.log('nothing');%0D%0A        return;%0D%0A      %7D%0D%0A      console.log(%60restore $%7BJSON.stringify(result)%7D%60);
+return;%0D%0A      %7D
 %0D%0A  
@@ -1639,15 +1639,15 @@
 ner(
-%22
+'
 input
-%22
+'
 , (e
@@ -1654,16 +1654,71 @@
 ) =%3E %7B%0D%0A
+  const saveButton = document.getElementById('save');%0D%0A
   if (e.
@@ -1751,39 +1751,18 @@
     
-document.getElementById('save')
+saveButton
 .dis
@@ -1797,39 +1797,18 @@
     
-document.getElementById('save')
+saveButton
 .dis

settings page