// popup.js


var $ = {
    query: document.querySelector.bind(document),
    toggleClass: function(el, className) {
        if (el.classList.contains(className))
            el.classList.remove(className);
        else
            el.classList.add(className);
    },
    addClass: function(el, className) {
        if (!(el.classList.contains(className)))
            el.classList.add(className);
    },
    removeClass: function(el, className) {
        if (el.classList.contains(className))
            el.classList.remove(className);
    }
};


var options = {
  els: {
    imgBlock: $.query('#imgBlock'),
    videoHide: $.query('#videoHide'),
    flashHide: $.query('#flashHide'),
    svgHide: $.query('#svgHide'),
    canvasHide: $.query('#canvasHide')
  },

  set: function(e) {
    var data = {};
    data[e.target.id] = !e.target.classList.contains('active');
    $.toggleClass(e.target, 'active');

    chrome.storage.local.set(data);
  },

  update: function() {
    var self = this;
    chrome.storage.local.get(function(data) {
      for (var el in self.els) {
        if (data[self.els[el].id]) {
          $.addClass(self.els[el], "active");
        } else {
          $.removeClass(self.els[el], "active");
        }
      }
    });
  },

  init: function() {
    var self = this;
    chrome.storage.local.get(function(data) {
      Object.keys(self.els).forEach(function(key) {
        if (data[key]) self.els[key].classList.add('active');
      });
    });

    for (var el in this.els)
      this.els[el].addEventListener('click', this.set);

    chrome.storage.onChanged.addListener(this.update.bind(this));
  }
};


// Init
options.init();

@@ -17,18 +17,16 @@
 r $ = %7B%0A
-  
   query:
@@ -65,18 +65,16 @@
 ument),%0A
-  
   toggle
@@ -106,32 +106,24 @@
 Name) %7B%0A    
-    if (
 el.classList
@@ -127,114 +127,14 @@
 ist.
-contains(className))%0A            el.classList.remove(className);%0A        else%0A            el.classList.add
+toggle
 (cla
@@ -142,27 +142,23 @@
 sName);%0A
-  
   %7D,%0A  
- 
- 
 addClass
@@ -189,65 +189,8 @@
 ) %7B%0A
-        if (!(el.classList.contains(className)))%0A        
     
@@ -220,23 +220,19 @@
 ame);%0A  
- 
- 
 %7D,%0A
-  
   remove
@@ -268,62 +268,8 @@
 ) %7B%0A
-        if (el.classList.contains(className))%0A        
     
@@ -300,18 +300,16 @@
 sName);%0A
-  
   %7D%0A%7D;%0A%0A
@@ -902,32 +902,32 @@
 lf.els%5Bel%5D, 
-%22
+'
 active
-%22
+'
 );%0A        %7D
@@ -976,16 +976,16 @@
 l%5D, 
-%22
+'
 active
-%22
+'
 );%0A 

popup.js