Greasy Fork 还支持 简体中文。

It's Not Important

Исправление проблем с невозможностью скрытия некоторых рекламных блоков в Google Chrome. Fix for inability to hide some adverts in Google Chrome.

目前為 2016-03-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name It's Not Important
  3. // @namespace lainscripts_it_is_not_important
  4. // @version 1.2
  5. // @description Исправление проблем с невозможностью скрытия некоторых рекламных блоков в Google Chrome. Fix for inability to hide some adverts in Google Chrome.
  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*important/ig;
  17.  
  18. function unimportanter(el) {
  19. var si = el.getAttribute('style'), so = si.replace(imptt, function(str,grp){return grp;});
  20. el.setAttribute('style',so);
  21. return (si != so)?1:0;
  22. }
  23.  
  24. function logger(c) {
  25. if (c) console.log(`Decreased importance of ${c} element${c>1?'s':''}`);
  26. }
  27.  
  28. document.addEventListener ("DOMContentLoaded", function(){
  29. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  30. while(i--)
  31. c+= unimportanter(imp[i]);
  32. logger(c);
  33. });
  34.  
  35. function checkTarget(m, c) {
  36. if (m.style && m.style.cssText.indexOf('!') > -1)
  37. c+=unimportanter(m);
  38. return c;
  39. }
  40.  
  41. function checkNodes(m, c) {
  42. var i = m.length;
  43. while(i--)
  44. c = checkTarget(m[i], c);
  45. return c;
  46. }
  47.  
  48. var observer = new MutationObserver(function(mutations) {
  49. setTimeout(function(m) {
  50. var i = m.length, c = 0;
  51. while(i--) {
  52. if (m[i].target)
  53. c = checkTarget(m[i].target, c);
  54. if (m[i].addedNodes.length)
  55. c = checkNodes(m[i].addedNodes, c);
  56. }
  57. logger(c);
  58. },0,mutations);
  59. });
  60.  
  61. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  62. })();