It's Not Important

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

  1. // ==UserScript==
  2. // @name It's Not Important
  3. // @namespace lainscripts_it_is_not_important
  4. // @version 1.5
  5. // @description At least part of the world will became a bit less important now.
  6. // @author lainverse
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11. /* jshint esnext: true */
  12.  
  13. (function(){
  14. 'use strict';
  15.  
  16. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  17. rplsf = function(str,grp){return grp;};
  18.  
  19. function unimportanter(el, si) {
  20. if (!imptt.test(si) || el.style.display == 'none')
  21. return 0; // get out if we have nothing to do here
  22. if (el.nodeName === 'IFRAME' && el.src &&
  23. el.src.slice(0,17) === 'chrome-extension:')
  24. return 0; // Web of Trust uses this method to add their frame
  25. var so = si.replace(imptt, rplsf), ret = 0;
  26. if (si != so) {
  27. ret = 1;
  28. el.setAttribute('style', so);
  29. }
  30. return ret;
  31. }
  32.  
  33. function logger(c) {
  34. if (c) console.log('Some page elements became a bit less important.');
  35. }
  36.  
  37. function checkTarget(m, c) {
  38. var si = m.getAttribute ? m.getAttribute('style') : null;
  39. if (si && si.indexOf('!') > -1)
  40. c+=unimportanter(m, si);
  41. return c;
  42. }
  43.  
  44. function checkNodes(m, c) {
  45. var i = m.length;
  46. while(i--)
  47. c = checkTarget(m[i], c);
  48. return c;
  49. }
  50.  
  51. var observer = new MutationObserver(function(mutations) {
  52. setTimeout(function(m) {
  53. var i = m.length, c = 0;
  54. while(i--) {
  55. if (m[i].target)
  56. c = checkTarget(m[i].target, c);
  57. if (m[i].addedNodes.length)
  58. c = checkNodes(m[i].addedNodes, c);
  59. }
  60. logger(c);
  61. },0,mutations);
  62. });
  63.  
  64. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  65.  
  66. window.addEventListener ("load", function(){
  67. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  68. while(i--) {
  69. c+= checkTarget(imp[i], c);
  70. }
  71. logger(c);
  72. }, false);
  73. })();