|
| 1 | +/******************************************************************************* |
| 2 | +
|
| 3 | + uBlock - a browser extension to block requests. |
| 4 | + Copyright (C) 2015 Raymond Hill |
| 5 | +
|
| 6 | + This program is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation, either version 3 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with this program. If not, see {http://www.gnu.org/licenses/}. |
| 18 | +
|
| 19 | + Home: https://github.com/gorhill/uBlock |
| 20 | +*/ |
| 21 | + |
| 22 | +/* global vAPI, HTMLDocument */ |
| 23 | + |
| 24 | +/******************************************************************************/ |
| 25 | + |
| 26 | +(function() { |
| 27 | + |
| 28 | +'use strict'; |
| 29 | + |
| 30 | +/******************************************************************************/ |
| 31 | + |
| 32 | +// https://github.com/gorhill/uBlock/issues/464 |
| 33 | +if ( document instanceof HTMLDocument === false ) { |
| 34 | + //console.debug('cosmetic-off.js > not a HTLMDocument'); |
| 35 | + return; |
| 36 | +} |
| 37 | + |
| 38 | +// Because in case |
| 39 | +if ( !vAPI ) { |
| 40 | + //console.debug('cosmetic-off.js > vAPI not found'); |
| 41 | + return; |
| 42 | +} |
| 43 | + |
| 44 | +/******************************************************************************/ |
| 45 | + |
| 46 | +var styles = vAPI.styles; |
| 47 | + |
| 48 | +if ( Array.isArray(styles) === false ) { |
| 49 | + return; |
| 50 | +} |
| 51 | + |
| 52 | +/******************************************************************************/ |
| 53 | + |
| 54 | +// Remove all cosmetic filtering-related styles from the DOM |
| 55 | + |
| 56 | +var selectors = []; |
| 57 | +var reProperties = /\s*\{[^}]+\}\s*/; |
| 58 | +var style, i; |
| 59 | + |
| 60 | +i = styles.length; |
| 61 | +while ( i-- ) { |
| 62 | + style = styles[i]; |
| 63 | + if ( style.parentElement === null ) { |
| 64 | + continue; |
| 65 | + } |
| 66 | + style.parentElement.removeChild(style); |
| 67 | + selectors.push(style.textContent.replace(reProperties, '')); |
| 68 | +} |
| 69 | + |
| 70 | +// Remove `display: none !important` attribute |
| 71 | + |
| 72 | +if ( selectors.length === 0 ) { |
| 73 | + return; |
| 74 | +} |
| 75 | + |
| 76 | +var elems = []; |
| 77 | +try { |
| 78 | + elems = document.querySelectorAll(selectors.join(',')); |
| 79 | +} catch (e) { |
| 80 | +} |
| 81 | + |
| 82 | +i = elems.length; |
| 83 | +while ( i-- ) { |
| 84 | + style = elems[i].style; |
| 85 | + if ( typeof style === 'object' || typeof style.removeProperty === 'function' ) { |
| 86 | + style.removeProperty('display'); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +/******************************************************************************/ |
| 91 | + |
| 92 | +})(); |
| 93 | + |
| 94 | +/******************************************************************************/ |
0 commit comments