It's Not Important

At least part of the world will became less important now.

当前为 2016-01-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name It's Not Important
  3. // @namespace lainscripts_it_is_not_important
  4. // @version 0.7
  5. // @description At least part of the world will became less important now.
  6. // @author lainverse
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10. /* jshint -W097 */
  11. 'use strict';
  12.  
  13. function unimportanter(el) {
  14. var si = el.getAttribute('style'), so = si.replace(/((display|(margin|padding)(-top|-bottom)?):[^;!]*)!important/g,function(str,grp){return grp});
  15. el.setAttribute('style',so);
  16. return (si != so)?1:0;
  17. }
  18.  
  19. function logger(c) {
  20. if (c) console.log('Now '+c.toString()+' element'+(c>1?'s':'')+' on the page '+(c>1?'are':'is')+' less important!');
  21. }
  22.  
  23. var c = 0, imp = document.querySelectorAll('[style*="!important"]');
  24.  
  25. for (var i = 0; i < imp.length; i++)
  26. c+= unimportanter(imp[i]);
  27. logger(c);
  28.  
  29. var observer = new MutationObserver(function(mutations) {
  30. setTimeout(function(m){
  31. var i = m.length, c = 0;
  32. while(i--) if (m[i].target.style.cssText.indexOf('!') > -1)
  33. c+=unimportanter(m[i].target);
  34. logger(c);
  35. },0,mutations);
  36. });
  37.  
  38. var everything = document.querySelectorAll('*'), i = everything.length;
  39. while(i--) observer.observe(everything[i], { attributes : true, attributeFilter : ['style'] });