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.9
  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. var imptt = /((display|(margin|padding)(-top|-bottom)?):[^;!]*)!important/g;
  14.  
  15. function unimportanter(el) {
  16. var si = el.getAttribute('style'), so = si.replace(imptt, function(str,grp){return grp});
  17. el.setAttribute('style',so);
  18. return (si != so)?1:0;
  19. }
  20.  
  21. function logger(c) {
  22. if (c) console.log('Now '+c.toString()+' element'+(c>1?'s':'')+' on the page '+(c>1?'are':'is')+' less important!');
  23. }
  24.  
  25. (function(){
  26. var c = 0, imp = document.querySelectorAll('[style*="!important"]'), i = imp.length;
  27. while(i--)
  28. c+= unimportanter(imp[i]);
  29. logger(c);
  30. })();
  31.  
  32. (function(){
  33. var observer = new MutationObserver(function(mutations) {
  34. setTimeout(function(m){
  35. var i = m.length, c = 0;
  36. while(i--) if (m[i].target.style.cssText.indexOf('!') > -1)
  37. c+=unimportanter(m[i].target);
  38. logger(c);
  39. },0,mutations);
  40. });
  41. observer.observe(document.body, { attributes : true, attributeFilter : ['style'], subtree : true });
  42. })();