RU AdList JS Fixes

try to take over the world!

当前为 2016-11-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20161112.2
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var win = (unsafeWindow || window),
  16. isFirefox = /firefox/i.test(navigator.userAgent);
  17.  
  18. // NodeList iterator polyfill (mostly for Safari)
  19. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  20. if (!NodeList.prototype[Symbol.iterator]) {
  21. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  22. }
  23.  
  24. // Create fake shadow root and style element as a bait for those who want to break ABP functionality
  25. (function() {
  26. // skip Firefox since ABP doesn't use shadowRoot there
  27. // also, skip browsers which doesn't support createShadowRoot (Safari)
  28. if (isFirefox || !document.documentElement.createShadowRoot) {
  29. return;
  30. }
  31. function createShadowTrap() {
  32. var sr = document.documentElement.createShadowRoot();
  33. // create 'shadow' element similar to ABP
  34. sr.appendChild(document.createElement('shadow'));
  35. // create empty 'style' bait
  36. var st = document.createElement('style');
  37. sr.appendChild(st);
  38. var o = new MutationObserver(function(ms){
  39. var m, node;
  40. for (m of ms) {
  41. for (node of m.removedNodes) {
  42. if (node === st) {
  43. st = document.createElement('style');
  44. sr.appendChild(st);
  45. console.log('Site took the bait and attempted to remove it.');
  46. }
  47. }
  48. }
  49. });
  50. o.observe(sr, {childList: true});
  51. }
  52. var tooLate = false;
  53. document.addEventListener('DOMContentLoaded', function(){
  54. tooLate = true;
  55. });
  56. (function checker(){
  57. if (document.documentElement.shadowRoot === null && !tooLate) {
  58. setTimeout(checker, 1);
  59. } else {
  60. createShadowTrap();
  61. }
  62. })();
  63. })();
  64.  
  65. // Creates and return protected style (unless protection is manually disabled).
  66. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  67. function createStyle(rules, props, skip_protect) {
  68. var root = document.documentElement;
  69.  
  70. function _protect(style) {
  71. Object.defineProperty(style, 'sheet', {
  72. value: style.sheet,
  73. enumerable: true
  74. });
  75. Object.defineProperty(style, 'disabled', {
  76. get: function() {return true;}, //pretend to be disabled
  77. set: function() {},
  78. enumerable: true
  79. });
  80. }
  81.  
  82. function _create() {
  83. var style = root.appendChild(document.createElement('style')),
  84. prop, rule;
  85. style.type = 'text/css';
  86. for (prop in props) {
  87. if (style[prop] !== undefined) {
  88. style[prop] = props[prop];
  89. }
  90. }
  91. for (rule of rules) {
  92. try {
  93. style.sheet.insertRule(rule, 0);
  94. } catch (e) {
  95. console.error(e);
  96. }
  97. }
  98. if (!skip_protect) {
  99. _protect(style);
  100. }
  101. return style;
  102. }
  103.  
  104. var style = _create();
  105. if (skip_protect) {
  106. return style;
  107. }
  108.  
  109. var o = new MutationObserver(function(ms){
  110. var m, node, rule;
  111. for (m of ms) {
  112. for (node of m.removedNodes) {
  113. if (node === style) {
  114. (new Promise(function(resolve){
  115. setTimeout(function(resolve){
  116. resolve(_create());
  117. }, 0, resolve);
  118. })).then(function(st){
  119. style = st;
  120. });
  121. }
  122. }
  123. }
  124. });
  125. o.observe(root, {childList:true});
  126.  
  127. return style;
  128. }
  129.  
  130. // https://greasyfork.org/scripts/19144-websuckit/
  131. (function() {
  132. // check does browser support Proxy and WebSocket
  133. if (typeof Proxy !== 'function' ||
  134. typeof WebSocket !== 'function') {
  135. return;
  136. }
  137.  
  138. function getWrappedCode(removeSelf) {
  139. var text = getWrappedCode.toString()+WSI.toString();
  140. text = (
  141. '(function(){"use strict";'+
  142. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  143. '(new WSI(self||window)).init();'+
  144. '})();\n'+
  145. (removeSelf?'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')
  146. );
  147. return text;
  148. }
  149.  
  150. function WSI(win, safeWin) {
  151. safeWin = safeWin || win;
  152. var masks = [], filter;
  153. for (filter of [// blacklist
  154. '||10root25.website^', '||24video.xxx^',
  155. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  156. '||bgrndi.com^', '||brokeloy.com^',
  157. '||cnamerutor.ru^',
  158. '||docfilms.info^', '||dreadfula.ru^',
  159. '||et-code.ru^',
  160. '||film-doma.ru^',
  161. '||free-torrent.org^', '||free-torrent.pw^',
  162. '||free-torrents.org^', '||free-torrents.pw^',
  163. '||game-torrent.info^', '||gocdn.ru^',
  164. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  165. '||kiev.ua^', '||kinotochka.net^',
  166. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  167. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  168. '||mail.ru^', '||marketgid.com^', '||mxtads.com^',
  169. '||nickhel.com^',
  170. '||oconner.biz^',
  171. '||pkpojhc.com^',
  172. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  173. '||recreativ.ru^', '||regpole.com^', '||ruttwind.com^',
  174. '||skidl.ru^',
  175. '||torvind.com^', '||trafmag.com^',
  176. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  177. '||xxuhter.ru^',
  178. '||yuiout.online^',
  179. '||zoom-film.ru^'
  180. ]) {
  181. masks.push(new RegExp(
  182. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  183. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  184. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  185. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  186. 'i'));
  187. }
  188.  
  189. function isBlocked(url) {
  190. for (var mask of masks) {
  191. if (mask.test(url)) {
  192. return true;
  193. }
  194. }
  195. return false;
  196. }
  197.  
  198. var realWebSocket = win.WebSocket;
  199. function wsGetter (target, name) {
  200. try {
  201. if (typeof realWebSocket.prototype[name] === 'function') {
  202. if (name === 'close' || name === 'send') { // send also closes connection
  203. target.readyState = realWebSocket.CLOSED;
  204. }
  205. return (
  206. function fake() {
  207. console.log('[WSI] Invoked function "'+name+'"', '| Tracing', (new Error()));
  208. return;
  209. }
  210. );
  211. }
  212. if (typeof realWebSocket.prototype[name] === 'number') {
  213. return realWebSocket[name];
  214. }
  215. } catch(ignore) {}
  216. return target[name];
  217. }
  218.  
  219. function createWebSocketWrapper(target) {
  220. return new Proxy(realWebSocket, {
  221. construct: function (target, args) {
  222. var url = args[0];
  223. console.log('[WSI] Opening socket on ' + url + ' \u2026');
  224. if (isBlocked(url)) {
  225. console.log("[WSI] Blocked.");
  226. return new Proxy({
  227. url: url,
  228. readyState: realWebSocket.OPEN
  229. }, {
  230. get: wsGetter
  231. });
  232. }
  233. return new target(args[0], args[1]);
  234. }
  235. });
  236. }
  237.  
  238. function WorkerWrapper() {
  239. var realWorker = win.Worker;
  240. function wrappedWorker(resourceURI) {
  241. var isBlobURL = /^blob:/i,
  242. xhr = null,
  243. _callbacks = new WeakMap(),
  244. _worker = null,
  245. _terminate = false,
  246. _onerror = null,
  247. _onmessage = null,
  248. _messages = [],
  249. _events = [],
  250. /*jshint validthis:true */
  251. _self = this;
  252.  
  253. function callbackWrapper(func) {
  254. if (typeof func !== 'function') {
  255. return undefined;
  256. }
  257. return (
  258. function callback() {
  259. func.apply(_self, arguments);
  260. }
  261. );
  262. }
  263.  
  264. _self.terminate = function(){
  265. _terminate = true;
  266. if (_worker) {
  267. _worker.terminate();
  268. }
  269. };
  270. Object.defineProperty(_self, 'onmessage', {
  271. get: function() {
  272. return _onmessage;
  273. },
  274. set: function(val) {
  275. _onmessage = val;
  276. if (_worker) {
  277. _worker.onmessage = callbackWrapper(val);
  278. }
  279. }
  280. });
  281. Object.defineProperty(_self, 'onerror', {
  282. get: function() {
  283. return _onerror;
  284. },
  285. set: function(val) {
  286. _onerror = val;
  287. if (_worker) {
  288. _worker.onerror = callbackWrapper(val);
  289. }
  290. }
  291. });
  292. _self.postMessage = function(message){
  293. if (_worker) {
  294. _worker.postMessage(message);
  295. } else {
  296. _messages.push(message);
  297. }
  298. };
  299. _self.terminate = function() {
  300. _terminate = true;
  301. if (_worker) {
  302. _worker.terminate();
  303. }
  304. };
  305. _self.addEventListener = function(){
  306. if (typeof arguments[1] !== 'function') {
  307. return;
  308. }
  309. if (!_callbacks.has(arguments[1])) {
  310. _callbacks.set(arguments[1], callbackWrapper(arguments[1]));
  311. }
  312. arguments[1] = _callbacks.get(arguments[1]);
  313. if (_worker) {
  314. _worker.addEventListener.apply(_worker, arguments);
  315. } else {
  316. _events.push(['addEventListener', arguments]);
  317. }
  318. };
  319. _self.removeEventListener = function(){
  320. if (typeof arguments[1] !== 'function' || !_callbacks.has(arguments[1])) {
  321. return;
  322. }
  323. arguments[1] = _callbacks.get(arguments[1]);
  324. _callbacks.delete(arguments[1]);
  325. if (_worker) {
  326. _worker.removeEventListener.apply(_worker, arguments);
  327. } else {
  328. _events.push(['removeEventListener', arguments]);
  329. }
  330. };
  331.  
  332. if (!isBlobURL.test(resourceURI)) {
  333. _worker = new realWorker(resourceURI);
  334. return; // not a blob, no need to wrap
  335. }
  336.  
  337. xhr = new XMLHttpRequest();
  338. xhr.responseType = 'blob';
  339. try {
  340. xhr.open('GET', resourceURI, true);
  341. } catch(ignore) {
  342. _worker = new realWorker(resourceURI);
  343. return; // failed to open connection, unable to continue wrapping procedure
  344. }
  345. (new Promise(function(resolve, reject){
  346. if (xhr.readyState !== XMLHttpRequest.OPENED) {
  347. // connection wasn't opened, unable to continue wrapping procedure
  348. return reject();
  349. }
  350. xhr.onload = function(){
  351. if (this.status === 200) {
  352. var reader = new FileReader();
  353. reader.addEventListener("loadend", function() {
  354. resolve(new realWorker(URL.createObjectURL(
  355. new Blob([getWrappedCode(false)+this.result])
  356. )));
  357. });
  358. reader.readAsText(this.response);
  359. }
  360. };
  361. xhr.send();
  362. })).then(function(val) {
  363. _worker = val;
  364. _worker.onerror = callbackWrapper(_onerror);
  365. _worker.onmessage = callbackWrapper(_onmessage);
  366. var _e;
  367. while(_events.length) {
  368. _e = _events.shift();
  369. _worker[_e[0]].apply(_worker, _e[1]);
  370. }
  371. while(_messages.length) {
  372. _worker.postMessage(_messages.shift());
  373. }
  374. if (_terminate) {
  375. _worker.terminate();
  376. }
  377. }).catch(function(){});
  378.  
  379. }
  380. win.Worker = wrappedWorker.bind(safeWin);
  381. }
  382.  
  383. function CreateElementWrapper() {
  384. var realCreateElement = Document.prototype.createElement,
  385. code = encodeURIComponent('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>\n'),
  386. isDataURL = /^data:/i,
  387. isBlobURL = /^blob:/i;
  388.  
  389. function frameRewrite(e) {
  390. var f = e.target,
  391. w = f.contentWindow;
  392. if (!f.src || (w && isBlobURL.test(f.src))) {
  393. w.WebSocket = createWebSocketWrapper();
  394. }
  395. if (isDataURL.test(f.src) && f.src.indexOf(code) < 0) {
  396. f.src = f.src.replace(',',',' + code);
  397. }
  398. }
  399.  
  400. function wrappedCreateElement(name) {
  401. var el = realCreateElement.apply(this, arguments);
  402. if (el.tagName === 'IFRAME') {
  403. el.addEventListener('load', frameRewrite, false);
  404. }
  405. return el;
  406. }
  407. Document.prototype.createElement = wrappedCreateElement;
  408.  
  409. document.addEventListener('DOMContentLoaded', function(){
  410. for (var ifr of document.querySelectorAll('IFRAME')) {
  411. ifr.addEventListener('load', frameRewrite, false);
  412. }
  413. }, false);
  414. }
  415.  
  416. this.init = function() {
  417. win.WebSocket = createWebSocketWrapper();
  418. WorkerWrapper();
  419. if (typeof document !== 'undefined') {
  420. CreateElementWrapper();
  421. }
  422. };
  423. }
  424.  
  425. if (isFirefox) {
  426. var script = document.createElement('script');
  427. script.appendChild(document.createTextNode(getWrappedCode()));
  428. document.head.insertBefore(script, document.head.firstChild);
  429. return; //we don't want to call functions on page from here in Fx, so exit
  430. }
  431.  
  432. (new WSI((unsafeWindow||self||window),(self||window))).init();
  433. })();
  434.  
  435. if (!isFirefox) { // scripts for non-Firefox browsers
  436.  
  437. // https://greasyfork.org/scripts/14720-it-s-not-important
  438. (function(){
  439. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  440.  
  441. function unimportanter(el, si) {
  442. if (!imptt.test(si) || el.style.display === 'none') {
  443. return 0; // get out if we have nothing to do here
  444. }
  445. if (el.nodeName === 'IFRAME' && el.src &&
  446. el.src.slice(0,17) === 'chrome-extension:') {
  447. return 0; // Web of Trust uses this method to add their frame
  448. }
  449. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  450. if (si !== so) {
  451. ret = 1;
  452. el.setAttribute('style', so);
  453. }
  454. return ret;
  455. }
  456.  
  457. function logger(c) {
  458. if (c) {
  459. console.log('Some page elements became a bit less important.');
  460. }
  461. }
  462.  
  463. function checkTarget(node, cnt) {
  464. if (!(node && node.getAttribute)) {
  465. return 0;
  466. }
  467. var si = node.getAttribute('style');
  468. if (si && si.indexOf('!') > -1) {
  469. cnt += unimportanter(node, si);
  470. }
  471. return cnt;
  472. }
  473.  
  474. var observer = new MutationObserver(function(mutations) {
  475. setTimeout(function(ms) {
  476. var cnt = 0, m, node;
  477. for (m of ms) {
  478. cnt = checkTarget(m.target, cnt);
  479. for (node of m.addedNodes) {
  480. cnt += checkTarget(node, cnt);
  481. }
  482. }
  483. logger(cnt);
  484. }, 0, mutations);
  485. });
  486.  
  487. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  488.  
  489. win.addEventListener ("load", function(){
  490. var c = 0, imp;
  491. for (imp of document.querySelectorAll('[style*="!"]')) {
  492. c+= checkTarget(imp, c);
  493. }
  494. logger(c);
  495. }, false);
  496. })();
  497.  
  498. }
  499.  
  500. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  501. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  502. (function(){
  503. var adWords = ['Яндекс.Директ','Реклама','Ad'];
  504. function remove(node) {
  505. node.parentNode.removeChild(node);
  506. }
  507. // Generic ads removal and fixes
  508. function removeGenericAds() {
  509. var s, i;
  510. s = document.querySelector('.serp-header');
  511. if (s) {
  512. s.style.marginTop='0';
  513. }
  514. for (s of document.querySelectorAll('.serp-adv__head + .serp-item, #adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]')) {
  515. remove(s);
  516. }
  517. }
  518. // Search ads
  519. function removeSearchAds() {
  520. var s, item;
  521. for (s of document.querySelectorAll('.serp-block, .serp-item, .search-item')) {
  522. item = s.querySelector('.label, .serp-item__label, .document__provider-name');
  523. if (item && adWords.indexOf(item.textContent) > -1) {
  524. remove(s);
  525. console.log('Ads removed.');
  526. }
  527. }
  528. }
  529. // News ads
  530. function removeNewsAds() {
  531. for (var s of document.querySelectorAll(
  532. '.page-content__left > *,'+
  533. '.page-content__right > *:not(.page-content__col),'+
  534. '.page-content__right > .page-content__col > *'
  535. )) {
  536. if (s.textContent.indexOf(adWords[0]) > -1 ||
  537. (s.clientHeight < 15 && s.classList.contains('rubric'))) {
  538. remove(s);
  539. console.log('Ads removed.');
  540. }
  541. }
  542. }
  543. // Music ads
  544. function removeMusicAds() {
  545. for (var s of document.querySelectorAll('.ads-block')) {
  546. remove(s);
  547. }
  548. }
  549. // Mail ads
  550. function removeMailAds() {
  551. var slice = Array.prototype.slice,
  552. nodes = slice.call(document.querySelectorAll('.ns-view-folders')),
  553. node, len, classes, cls;
  554. for (node of nodes) {
  555. if (!len || len > node.classList.length) {
  556. len = node.classList.length;
  557. }
  558. }
  559. node = nodes.pop();
  560. while (node) {
  561. if (node.classList.length > len) {
  562. for (cls of slice.call(node.classList)) {
  563. if (cls.indexOf('-') === -1) {
  564. remove(node);
  565. break;
  566. }
  567. }
  568. }
  569. node = nodes.pop();
  570. }
  571. }
  572. // News fixes
  573. function removePageAdsClass() {
  574. if (document.body.classList.contains("b-page_ads_yes")){
  575. document.body.classList.remove("b-page_ads_yes");
  576. console.log('Page ads class removed.');
  577. }
  578. }
  579. // Function to attach an observer to monitor dynamic changes on the page
  580. function pageUpdateObserver(func, obj, params) {
  581. if (obj) {
  582. var o = new MutationObserver(func);
  583. o.observe(obj,(params || {childList:true, subtree:true}));
  584. }
  585. }
  586. // Cleaner
  587. document.addEventListener ('DOMContentLoaded', function() {
  588. removeGenericAds();
  589. if (win.location.hostname.search(/^mail\./i) === 0) {
  590. pageUpdateObserver(function(ms, o){
  591. var aside = document.querySelector('.mail-Layout-Aside');
  592. if (aside) {
  593. o.disconnect();
  594. pageUpdateObserver(removeMailAds, aside);
  595. }
  596. }, document.querySelector('BODY'));
  597. removeMailAds();
  598. } else if (win.location.hostname.search(/^music\./i) === 0) {
  599. pageUpdateObserver(removeMusicAds, document.querySelector('.sidebar'));
  600. removeMusicAds();
  601. } else if (win.location.hostname.search(/^news\./i) === 0) {
  602. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  603. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  604. removeNewsAds();
  605. removePageAdsClass();
  606. } else {
  607. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  608. removeSearchAds();
  609. }
  610. });
  611. })();
  612. return; //skip fixes for other sites
  613. }
  614.  
  615. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.7+ (adapted & fixed)
  616. document.addEventListener ('DOMContentLoaded', function() {
  617. var tmp, t;
  618. function log (e) {
  619. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  620. }
  621. if (win.adv_enabled !== undefined && win.condition_detected !== undefined) { // moonwalk
  622. log('Moonwalk');
  623. if (win.adv_enabled) {
  624. win.adv_enabled = false;
  625. }
  626. win.condition_detected = false;
  627. if (win.MXoverrollCallback) {
  628. document.addEventListener('click', function catcher(e){
  629. e.stopPropagation();
  630. win.MXoverrollCallback.call(window);
  631. document.removeEventListener('click', catcher, true);
  632. }, true);
  633. }
  634. } else if (win.banner_second !== undefined && win.$banner_ads !== undefined) { // hdgo
  635. log('HDGo');
  636. tmp = document.querySelector('#swtf');
  637. if (tmp) {
  638. tmp.style.display = 'none';
  639. }
  640. win.banner_second = 0;
  641. win.$banner_ads = false;
  642. if (win.$new_ads !== undefined) {
  643. win.$new_ads = false;
  644. }
  645. if (win.canRunAds !== undefined && win.canRunAds !== true) {
  646. win.canRunAds = true;
  647. }
  648. } else if (win.MXoverrollCallback && win.iframeSearch !== undefined) { // kodik
  649. log('Kodik');
  650. tmp = document.querySelector('.play_button');
  651. if (tmp) {
  652. tmp.onclick = win.MXoverrollCallback.bind(window);
  653. }
  654. win.IsAdBlock = false;
  655. }
  656. }, false);
  657.  
  658. // function to search and remove nodes by content
  659. // selector - standard CSS selector to define set of nodes to check
  660. // words - regular expression to check content of the suspicious nodes
  661. // params - object with multiple extra parameters:
  662. // .hide - set display to none instead of removing from the page
  663. // .parent - parent node to remove if content is found in the child node
  664. // .siblings - number of simling nodes to remove (excluding text nodes)
  665. function scRemove(e) {e.parentNode.removeChild(e);}
  666. function scHide(e) {
  667. var s = e.getAttribute('style')||'',
  668. h = ';display:none!important;';
  669. if (s.indexOf(h) < 0) {
  670. e.setAttribute('style', s+h);
  671. }
  672. }
  673. function scissors (selector, words, scope, params) {
  674. var remFunc = (params.hide ? scHide : scRemove),
  675. iterFunc = (params.siblings > 0 ?
  676. 'nextSibling' :
  677. 'previousSibling'),
  678. toRemove = [],
  679. siblings,
  680. node;
  681. for (node of scope.querySelectorAll(selector)) {
  682. if (words.test(node.innerHTML) || !node.childNodes.length) {
  683. // drill up to the specified parent node if required
  684. if (params.parent) {
  685. while(node !== scope && !(node.matches(params.parent))) {
  686. node = node.parentNode;
  687. }
  688. }
  689. if (node === scope) {
  690. break;
  691. }
  692. toRemove.push(node);
  693. // add multiple nodes if defined more than one sibling
  694. siblings = Math.abs(params.siblings) || 0;
  695. while (siblings) {
  696. node = node[iterFunc];
  697. toRemove.push(node);
  698. if (node.nodeType === Node.ELEMENT_NODE) {
  699. siblings -= 1; //count only element nodes
  700. }
  701. }
  702. }
  703. }
  704. for (node of toRemove) {
  705. remFunc(node);
  706. }
  707. return toRemove.length;
  708. }
  709.  
  710. // function to perform multiple checks if ads inserted with a delay
  711. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  712. // also does 1 extra check when a page completely loads
  713. // selector and words - passed dow to scissors
  714. // params - object with multiple extra parameters:
  715. // .root - selector to narrow down scope to scan;
  716. // .observe - if true then check will be performed continuously;
  717. // Other parameters passed down to scissors.
  718. function gardener(selector, words, params) {
  719. params = params || {};
  720. var scope = document.body,
  721. nonstop = false;
  722. // narrow down scope to a specific element
  723. if (params.root) {
  724. scope = scope.querySelector(params.root);
  725. if (!scope) {// exit if the root element is not present on the page
  726. return 0;
  727. }
  728. }
  729. // add observe mode if required
  730. if (params.observe) {
  731. if (typeof MutationObserver === 'function') {
  732. var o = new MutationObserver(function(ms){
  733. for (var m of ms) {
  734. if (m.addedNodes.length) {
  735. scissors(selector, words, scope, params);
  736. }
  737. }
  738. });
  739. o.observe(scope, {childList:true, subtree: true});
  740. } else {
  741. nonstop = true;
  742. }
  743. }
  744. // wait for a full page load to do one extra cut
  745. win.addEventListener('load',function(){
  746. scissors(selector, words, scope, params);
  747. });
  748. // do multiple cuts until ads removed
  749. function cut(sci, s, w, sc, p, i) {
  750. if (i > 0) {
  751. i -= 1;
  752. }
  753. if (i && !sci(s, w, sc, p)) {
  754. setTimeout(cut, 100, sci, s, w, sc, p, i);
  755. }
  756. }
  757. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  758. }
  759.  
  760. function preventBackgroundRedirect() {
  761. // create "cose_me" event to call high-level window.close()
  762. var key = Math.random().toString(36).substr(2);
  763. window.addEventListener('close_me_'+key, function(e) {
  764. window.close();
  765. });
  766.  
  767. // window.open wrapper
  768. function pbrLander() {
  769. var orgOpen = window.open.bind(window);
  770. function closeWindow(){
  771. // site went to a new tab and attempts to unload
  772. // call for high-level close through event
  773. var event = new CustomEvent("close_me_%key%", {});
  774. window.dispatchEvent(event);
  775. }
  776. function open(){
  777. var idx = String.prototype.indexOf;
  778. if (arguments[0] &&
  779. (idx.call(arguments[0], window.location.host) > -1 ||
  780. idx.call(arguments[0], '://') === -1)) {
  781. window.addEventListener('unload', closeWindow, true);
  782. }
  783. orgOpen.apply(window, arguments);
  784. }
  785. window.open = open.bind(window);
  786. var s = document.currentScript;
  787. if (s) {s.parentNode.removeChild(s);}
  788. }
  789.  
  790. // land wrapper on the page
  791. var script = document.createElement('script');
  792. script.appendChild(document.createTextNode('('+pbrLander.toString().replace(/%key%/g,key)+')();'));
  793. document.head.insertBefore(script,document.head.firstChild);
  794. console.log("Background redirect prevention enabled.");
  795. }
  796.  
  797. function forbidServiceWorker() {
  798. if (!("serviceWorker" in navigator)) {
  799. return;
  800. }
  801. var svr = navigator.serviceWorker.ready;
  802. Object.defineProperty(navigator, 'serviceWorker', {
  803. value: {
  804. register: function(){
  805. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  806. return new Promise(function(){});
  807. },
  808. ready: new Promise(function(){}),
  809. addEventListener:function(){}
  810. }
  811. });
  812. document.addEventListener('DOMContentLoaded', function() {
  813. if (!svr) {
  814. return;
  815. }
  816. svr.then(function(sw) {
  817. console.log('Found existing serviceWorker:', sw);
  818. console.log('Attempting to unregister...');
  819. sw.unregister().then(function() {
  820. console.log('Unregistered! :)');
  821. }).catch(function(err) {
  822. console.log('Unregistration failed. :(', err);
  823. console.log('Try to remove it manually:');
  824. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  825. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  826. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  827. });
  828. }).catch(function(err) {
  829. console.log("Lol, it failed on it's own. -_-", err);
  830. });
  831. }, false);
  832. }
  833.  
  834. var scripts = {};
  835. scripts['4pda.ru'] = {
  836. 'now': function() {
  837. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  838. var isForum = document.location.href.search('/forum/') !== -1,
  839. hStyle;
  840.  
  841. function remove(n) {
  842. if (n) {
  843. n.parentNode.removeChild(n);
  844. }
  845. }
  846.  
  847. function afterClean() {
  848. hStyle.disabled = true;
  849. remove(hStyle);
  850. }
  851.  
  852. function beforeClean() {
  853. // attach styles before document displayed
  854. hStyle = createStyle([
  855. 'html { overflow-y: scroll }',
  856. 'section[id] {'+(
  857. 'position: absolute;'+
  858. 'width: 100%'
  859. )+'}',
  860. 'article + aside * { display: none !important }',
  861. '#header + div:after {'+(
  862. 'content: "";'+
  863. 'position: fixed;'+
  864. 'top: 0;'+
  865. 'left: 0;'+
  866. 'width: 100%;'+
  867. 'height: 100%;'+
  868. 'background-color: #E6E7E9'
  869. )+'}',
  870. // http://codepen.io/Beaugust/pen/DByiE
  871. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  872. 'article + aside:after {'+(
  873. 'content: "";'+
  874. 'position: absolute;'+
  875. 'width: 150px;'+
  876. 'height: 150px;'+
  877. 'top: 150px;'+
  878. 'left: 50%;'+
  879. 'margin-top: -75px;'+
  880. 'margin-left: -75px;'+
  881. 'box-sizing: border-box;'+
  882. 'border-radius: 100%;'+
  883. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  884. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  885. 'animation: spin 2s infinite linear'
  886. )+'}'
  887. ], {id:'ubrHider'}, true);
  888.  
  889. // display content of a page if time to load a page is more than 2 seconds to avoid
  890. // blocking access to a page if it is loading for too long or stuck in a loading state
  891. setTimeout(2000, afterClean);
  892. }
  893.  
  894. createStyle([
  895. '#nav .use-ad { display: block !important }',
  896. 'article:not(.post) + article:not(#id), a[target="_blank"] img[height="90"] { display: none !important }'
  897. ]);
  898.  
  899. if (!isForum) {
  900. beforeClean();
  901. }
  902.  
  903. // save links to non-overridden functions to use later
  904. var oGA = Element.prototype.getAttribute,
  905. oSA = Element.prototype.setAttribute,
  906. protectedElems;
  907. // protect/hide changed attributes in case site attempt to restore them
  908. function styleProtector(eventMode) {
  909. var oRAN = Element.prototype.removeAttributeNode,
  910. isStyleText = function(t){ return t === 'style'; },
  911. isStyleAttr = function(a){ return a instanceof Attr && a.nodeName === 'style'; },
  912. returnUndefined = function(){},
  913. protectedElems = new WeakMap();
  914. function protoOverride(element, functionName, isStyleCheck, returnIfProtected) {
  915. var oF = element.prototype[functionName];
  916. element.prototype[functionName] = function(){
  917. if (protectedElems.get(this) !== undefined && isStyleCheck(arguments[0])) {
  918. return returnIfProtected(protectedElems.get(this), arguments, this);
  919. }
  920. return oF.apply(this, arguments);
  921. };
  922. }
  923. protoOverride(Element, 'removeAttribute', isStyleText, returnUndefined);
  924. protoOverride(Element, 'hasAttribute', isStyleText, function(o) {
  925. return o.oldStyle !== null;
  926. });
  927. protoOverride(Element, 'setAttribute', isStyleText, function(o, args) {
  928. o.oldStyle = args[1];
  929. });
  930. protoOverride(Element, 'getAttribute', isStyleText, function(o) {
  931. return o.oldStyle;
  932. });
  933. if (eventMode) {
  934. var e = document.createEvent('Event');
  935. e.initEvent('protoOverride', false, false);
  936. window.protectedElems = protectedElems;
  937. window.dispatchEvent(e);
  938. } else {
  939. return protectedElems;
  940. }
  941. }
  942. if (isFirefox) {
  943. var s = document.createElement('script');
  944. s.textContent = '(' + styleProtector.toString() + ')(true);' +
  945. 'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}';
  946. window.addEventListener('protoOverride', function protoOverrideCallback(e){
  947. if (win.protectedElems) {
  948. protectedElems = win.protectedElems;
  949. delete win.protectedElems;
  950. }
  951. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  952. }, true);
  953. document.documentElement.appendChild(s);
  954. } else {
  955. protectedElems = styleProtector(false);
  956. }
  957.  
  958. // clean a page
  959. window.addEventListener('DOMContentLoaded', function(){
  960. var rem, si, itm;
  961. function width(){ return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0; }
  962. function height(){ return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0; }
  963.  
  964.  
  965. if (isForum) {
  966. si = document.querySelector('#logostrip');
  967. if (si) {
  968. remove(si.parentNode.nextSibling);
  969. }
  970. }
  971.  
  972. if (document.location.href.search('/forum/dl/') !== -1) {
  973. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  974. ';background-color:black!important');
  975. for (itm of document.querySelectorAll('body>div')) {
  976. if (!itm.querySelector('.dw-fdwlink')) {
  977. remove(itm);
  978. }
  979. }
  980. }
  981.  
  982. if (isForum) { // Do not continue if it's a forum
  983. return;
  984. }
  985.  
  986. si = document.querySelector('#header');
  987. if (si) {
  988. rem = si.previousSibling;
  989. while (rem) {
  990. si = rem.previousSibling;
  991. remove(rem);
  992. rem = si;
  993. }
  994. }
  995.  
  996. for (itm of document.querySelectorAll('#nav li[class]')) {
  997. if (itm && itm.querySelector('a[href^="/tag/"]')) {
  998. remove(itm);
  999. }
  1000. }
  1001.  
  1002. var style, result;
  1003. for (itm of document.querySelectorAll('DIV, A')) {
  1004. if (itm.tagName ==='DIV' && itm.offsetWidth > 0.95 * width() && itm.offsetHeight > 0.85 * height()) {
  1005. style = window.getComputedStyle(itm, null);
  1006. result = [];
  1007. if (style.backgroundImage !== 'none') {
  1008. result.push('background-image:none!important');
  1009. }
  1010. if (style.backgroundColor !== 'transparent' &&
  1011. style.backgroundColor !== 'rgba(0, 0, 0, 0)') {
  1012. result.push('background-color:transparent!important');
  1013. }
  1014. if (result.length) {
  1015. if (itm.getAttribute('style')) {
  1016. result.unshift(itm.getAttribute('style'));
  1017. }
  1018. (function(){
  1019. var fakeStyle = {
  1020. 'backgroundImage': itm.style.backgroundImage,
  1021. 'backgroundColor': itm.style.backgroundColor
  1022. };
  1023. try {
  1024. Object.defineProperty(itm, 'style', {
  1025. value: new Proxy(itm.style, {
  1026. get: function(target, prop){
  1027. if (fakeStyle.hasOwnProperty(prop)) {
  1028. return fakeStyle[prop];
  1029. } else {
  1030. return target[prop];
  1031. }
  1032. },
  1033. set: function(target, prop, value){
  1034. if (fakeStyle.hasOwnProperty(prop)) {
  1035. fakeStyle[prop] = value;
  1036. } else {
  1037. target[prop] = value;
  1038. }
  1039. return value;
  1040. }
  1041. }),
  1042. enumerable: true
  1043. });
  1044. } catch (e) {
  1045. console.log('Unable to protect style property.', e);
  1046. }
  1047. })();
  1048. if (protectedElems) {
  1049. protectedElems.set(itm, {oldStyle: oGA.call(itm, 'style')});
  1050. }
  1051. oSA.call(itm, 'style', result.join(';'));
  1052. }
  1053. }
  1054. if (itm.tagName ==='A' && (itm.offsetWidth > 0.95 * width() || itm.offsetHeight > 0.85 * height())) {
  1055. if (protectedElems) {
  1056. protectedElems.set(itm, {oldStyle: oGA.call(itm, 'style')});
  1057. }
  1058. oSA.call(itm, 'style', 'display:none!important');
  1059. }
  1060. }
  1061.  
  1062. for (itm of document.querySelectorAll('ASIDE>DIV')) {
  1063. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  1064. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  1065. !itm.classList.contains('post') ) || !itm.childNodes.length ) {
  1066. remove(itm);
  1067. }
  1068. }
  1069.  
  1070. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  1071.  
  1072. // display content of the page
  1073. afterClean();
  1074. });
  1075. }
  1076. }
  1077.  
  1078. scripts['anidub-online.ru'] = function() {
  1079. var script = document.createElement('script');
  1080. script.type = "text/javascript";
  1081. script.innerHTML = "function ogonekstart1() {}";
  1082. document.getElementsByTagName('head')[0].appendChild(script);
  1083.  
  1084. var style = document.createElement('style');
  1085. style.type = 'text/css';
  1086. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  1087. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  1088. document.head.appendChild(style);
  1089. };
  1090. scripts['online.anidub.com'] = scripts['anidub-online.ru'];
  1091.  
  1092. scripts['fs.to'] = function() {
  1093. function skipClicker(i) {
  1094. if (!i) {
  1095. return;
  1096. }
  1097. var skip = document.querySelector('.b-aplayer-banners__close');
  1098. if (skip) {
  1099. skip.click();
  1100. } else {
  1101. setTimeout(skipClicker, 100, i-1);
  1102. }
  1103. }
  1104. setTimeout(skipClicker, 100, 30);
  1105.  
  1106. createStyle([
  1107. '.l-body-branding *,'+
  1108. '.b-styled__item-central,'+
  1109. '.b-styled__content-right,'+
  1110. '.b-styled__section-central,'+
  1111. 'div[id^="adsProxy-"]'+
  1112. '{display:none!important}',
  1113. 'body {background-image:url(data:image/png;base64,'+
  1114. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACX'+
  1115. 'BIWXMAAC4jAAAuIwF4pT92AAAADUlEQVR42mOQUdL5DwACMgFq'+
  1116. 'BC3ttwAAAABJRU5ErkJggg==)!important}'
  1117. ]);
  1118.  
  1119. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  1120. var p = document.querySelector('#player:not([preload="auto"])'),
  1121. m = document.querySelector('.main'),
  1122. adStepper = function(p) {
  1123. if (p.currentTime < p.duration) {
  1124. p.currentTime += 1;
  1125. }
  1126. },
  1127. adSkipper = function(f, p) {
  1128. f.click();
  1129. p.waitAfterSkip = false;
  1130. p.longerSkipper = false;
  1131. console.log('Пропустили.');
  1132. },
  1133. cl = function(p) {
  1134. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  1135. series = document.querySelector('.b-aplayer__actions-series');
  1136.  
  1137. function clickSelected() {
  1138. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  1139. if (s) {
  1140. s.click();
  1141. }
  1142. }
  1143.  
  1144. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  1145. series.click();
  1146. p.seriesClicked = true;
  1147. p.longerSkipper = true;
  1148. setTimeout(clickSelected, 1000);
  1149. p.pause();
  1150. }
  1151.  
  1152. function skipListener() {
  1153. if (p.waitAfterSkip) {
  1154. console.log('В процессе пропуска…');
  1155. return;
  1156. }
  1157. p.pause();
  1158. if (!p.classList.contains('m-hidden')) {
  1159. p.classList.add('m-hidden');
  1160. }
  1161. if (faster && p.currentTime &&
  1162. win.getComputedStyle(faster).display === 'block' &&
  1163. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  1164. p.waitAfterSkip = true;
  1165. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  1166. console.log('Доступен быстрый пропуск…');
  1167. } else {
  1168. setTimeout(adStepper, 1000, p);
  1169. }
  1170. }
  1171.  
  1172. p.addEventListener('timeupdate', skipListener, false);
  1173. },
  1174. o = new MutationObserver(function (ms) {
  1175. var m, node;
  1176. for (m of ms) {
  1177. for (node of m.addedNodes) {
  1178. if (node.id === 'player' &&
  1179. node.nodeName === 'VIDEO' &&
  1180. node.getAttribute('preload') !== 'auto') {
  1181. cl(node);
  1182. }
  1183. }
  1184. }
  1185. });
  1186. if (p.nodeName === 'VIDEO') {
  1187. cl(p);
  1188. } else {
  1189. o.observe(m, {childList: true});
  1190. }
  1191. }
  1192. };
  1193. scripts['brb.to'] = scripts['fs.to'];
  1194. scripts['cxz.to'] = scripts['fs.to'];
  1195.  
  1196. scripts['drive2.ru'] = function() {
  1197. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  1198. };
  1199.  
  1200. scripts['fishki.net'] = function() {
  1201. gardener('.main-post', /543769|Реклама/);
  1202. };
  1203.  
  1204. scripts['gidonline.club'] = {
  1205. 'now': function() {
  1206. createStyle('.tray > div[style] {display: none!important}');
  1207. }
  1208. };
  1209. scripts['gidonlinekino.com'] = scripts['gidonline.club'];
  1210.  
  1211. scripts['hdgo.cc'] = {
  1212. 'now': function(){
  1213. var o = new MutationObserver(function(ms) {
  1214. var m, node;
  1215. for (m of ms) {
  1216. for (node of m.addedNodes) {
  1217. if (node.tagName === 'SCRIPT' && node.getAttribute('onerror') !== null) {
  1218. node.removeAttribute('onerror');
  1219. }
  1220. }
  1221. }
  1222. });
  1223. o.observe(document, {childList:true, subtree: true});
  1224. }
  1225. };
  1226. scripts['couber.be'] = scripts['hdgo.cc'];
  1227. scripts['46.30.43.38'] = scripts['hdgo.cc'];
  1228.  
  1229. scripts['hdrezka.me'] = {
  1230. 'now': function() {
  1231. Object.defineProperty(win, 'fuckAdBlock', {
  1232. value: {
  1233. onDetected: function() {
  1234. console.log('Pretending to be an ABP detector.');
  1235. }
  1236. }
  1237. });
  1238. Object.defineProperty(win, 'ab', {
  1239. value: false,
  1240. enumerable: true
  1241. });
  1242. },
  1243. 'DOMContentLoaded': function() {
  1244. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  1245. }
  1246. };
  1247.  
  1248. scripts['megogo.net'] = {
  1249. 'now': function() {
  1250. Object.defineProperty(win, "adBlock", {
  1251. value : false,
  1252. enumerable : true
  1253. });
  1254. Object.defineProperty(win, "showAdBlockMessage", {
  1255. value : function () {},
  1256. enumerable : true
  1257. });
  1258. }
  1259. };
  1260.  
  1261. scripts['naruto-base.su'] = function() {
  1262. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1263. };
  1264.  
  1265. scripts['overclockers.ru'] = {
  1266. 'now': function() {
  1267. // Following code inspired by:
  1268. // https://greasyfork.org/en/scripts/23922-anti-adblock-killer-for-overclockers-ru
  1269. function antiAntiABP() {
  1270. var o = new MutationObserver(function(ms) {
  1271. var m, node;
  1272. for (m of ms) {
  1273. for (node of m.addedNodes) {
  1274. if (node.nodeType === Node.ELEMENT_NODE && node.onerror) {
  1275. node.onerror = null;
  1276. if (!/^https:\/\/an\.yandex\.ru\//.test(node.src)) {
  1277. console.log("Disabled 'onerror' on", node);
  1278. }
  1279. }
  1280. }
  1281. }
  1282. });
  1283. o.observe(document, {childList: true, subtree: true});
  1284. var s = document.currentScript;
  1285. s.parentNode.removeChild(s);
  1286. var log = window.console.log;
  1287. window.console.log = function() {
  1288. log.apply(this, arguments);
  1289. if (arguments[0] === 'blocked') {
  1290. throw new Error('or not, it\'s the question');
  1291. }
  1292. }
  1293. }
  1294. var s = document.createElement('script');
  1295. s.textContent = '(' + antiAntiABP.toString() + ')();';
  1296. document.documentElement.appendChild(s);
  1297. }
  1298. };
  1299. scripts['forums.overclockers.ru'] = {
  1300. 'now': function() {
  1301. createStyle(['.needblock {position: fixed; left: -10000px}']);
  1302. Object.defineProperty(win, 'adblck', {
  1303. value: 'no',
  1304. enumerable: true
  1305. });
  1306. }
  1307. };
  1308.  
  1309. scripts['pb.wtf'] = function() {
  1310. createStyle(['.reques,#result,tbody.row1:not([id]) {display: none !important}']);
  1311. // image in the slider in the header
  1312. gardener('a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1313. // ads in blocks on the page
  1314. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  1315. // line above topic content
  1316. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1317. };
  1318. scripts['piratbit.org'] = scripts['pb.wtf'];
  1319. scripts['piratbit.ru'] = scripts['pb.wtf'];
  1320.  
  1321. scripts['pikabu.ru'] = function() {
  1322. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1323. };
  1324.  
  1325. scripts['rp5.ru'] = function() {
  1326. var co = document.querySelector('#content'), i, nodes;
  1327. if (!co) {
  1328. return;
  1329. }
  1330. nodes = co.parentNode.childNodes;
  1331. i = nodes.length;
  1332. while (i--) {
  1333. if (nodes[i] !== co) {
  1334. nodes[i].parentNode.removeChild(nodes[i]);
  1335. }
  1336. }
  1337. };
  1338.  
  1339. scripts['rustorka.com'] = {
  1340. 'now': function() {
  1341. createStyle([
  1342. '.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}'
  1343. ], {
  1344. id: 'tempHidingStyles'
  1345. }, true);
  1346. win.open = function(){
  1347. console.log('Site attempted to open a new window', arguments);
  1348. };
  1349. window.open = win.open;
  1350. var realCreateElement = Document.prototype.createElement;
  1351. function wrappedCreateElement(name) {
  1352. var el = realCreateElement.apply(this, arguments);
  1353. if (el.tagName === 'A') {
  1354. el.addEventListener('click', function(e){
  1355. if (!e.target.parentNode || !e.isTrusted) {
  1356. e.preventDefault();
  1357. console.log('Blocked suspicious click event', e, 'on', e.target);
  1358. }
  1359. }, false);
  1360. }
  1361. return el;
  1362. }
  1363. Document.prototype.createElement = wrappedCreateElement;
  1364. },
  1365. 'DOMContentLoaded': function() {
  1366. for (var o of document.querySelectorAll('IMG, A')) {
  1367. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  1368. (o.clientWidth === 300 && o.clientHeight === 250)) {
  1369. while (o && o.tagName !== 'A') {
  1370. o = o.parentNode;
  1371. }
  1372. if (o) {
  1373. o.setAttribute('style', 'display: none !important');
  1374. }
  1375. }
  1376. }
  1377. var s = document.querySelector('#tempHidingStyles');
  1378. s.parentNode.removeChild(s);
  1379. }
  1380. };
  1381. scripts['rumedia.ws'] = scripts['rustorka.com'];
  1382.  
  1383. scripts['sport-express.ru'] = function() {
  1384. gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  1385. };
  1386.  
  1387. scripts['sports.ru'] = function() {
  1388. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  1389. };
  1390.  
  1391. scripts['turbobit.net'] = {'now': preventBackgroundRedirect};
  1392.  
  1393. scripts['yap.ru'] = function() {
  1394. var words = /member1438|Administration/;
  1395. gardener('form > table[id^="p_row_"]', words);
  1396. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  1397. };
  1398. scripts['yaplakal.com'] = scripts['yap.ru'];
  1399.  
  1400. scripts['reactor.cc'] = {
  1401. 'now': function() {
  1402. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  1403. },
  1404. 'click': function(e) {
  1405. var node = e.target;
  1406. if (node.nodeType === Node.ELEMENT_NODE &&
  1407. node.style.position === 'absolute' &&
  1408. node.style.zIndex > 0)
  1409. node.parentNode.removeChild(node);
  1410. },
  1411. 'DOMContentLoaded': function() {
  1412. var words = new RegExp(
  1413. 'блокировщика рекламы'
  1414. .split('')
  1415. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  1416. .join('')
  1417. .replace(' ', '\\s*')
  1418. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  1419. 'i'),
  1420. can;
  1421. function deeper(spider) {
  1422. var c, l, n;
  1423. if (words.test(spider.innerText)) {
  1424. if (spider.nodeType === Node.TEXT_NODE) {
  1425. return true;
  1426. }
  1427. c = spider.childNodes;
  1428. l = c.length;
  1429. n = 0;
  1430. while(l--) {
  1431. if (deeper(c[l]), can) {
  1432. n++;
  1433. }
  1434. }
  1435. if (n > 0 && n === c.length && spider.offsetHeight < 750) {
  1436. can.push(spider);
  1437. }
  1438. return false;
  1439. }
  1440. return true;
  1441. }
  1442. function probe(){
  1443. if (words.test(document.body.innerText)) {
  1444. can = [];
  1445. deeper(document.body);
  1446. var i = can.length, j, spider;
  1447. while(i--) {
  1448. spider = can[i];
  1449. if (spider.offsetHeight > 10 && spider.offsetHeight < 750) {
  1450. spider.setAttribute('style', 'background:none!important');
  1451. }
  1452. }
  1453. }
  1454. }
  1455. var o = new MutationObserver(probe);
  1456. o.observe(document,{childList:true, subtree:true});
  1457. }
  1458. };
  1459. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  1460. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  1461.  
  1462. scripts['auto.ru'] = function() {
  1463. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  1464. var userAdsListAds = [
  1465. '.listing-list > .listing-item',
  1466. '.listing-item_type_fixed.listing-item'
  1467. ];
  1468. var catalogAds = [
  1469. 'div[class*="layout_catalog-inline"]',
  1470. 'div[class$="layout_horizontal"]'
  1471. ];
  1472. var otherAds = [
  1473. '.advt_auto',
  1474. '.sidebar-block',
  1475. '.pager-listing + div[class]',
  1476. '.card > div[class][style]',
  1477. '.sidebar > div[class]',
  1478. '.main-page__section + div[class]',
  1479. '.listing > tbody'];
  1480. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  1481. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  1482. gardener(otherAds.join(','), words);
  1483. };
  1484.  
  1485. scripts['rsload.net'] = {
  1486. 'load': function() {
  1487. var dis = document.querySelector('.cb-disable');
  1488. if (dis) {
  1489. dis.click();
  1490. }
  1491. },
  1492. 'click': function(e) {
  1493. var t = e.target;
  1494. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  1495. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  1496. }
  1497. }
  1498. };
  1499.  
  1500. scripts['imageban.ru'] = {
  1501. 'now': preventBackgroundRedirect,
  1502. 'DOMContentLoaded': function() {
  1503. win.addEventListener('unload', function() {
  1504. if (!window.location.hash) {
  1505. window.location.replace(window.location+'#');
  1506. } else {
  1507. window.location.hash = '';
  1508. }
  1509. }, true);
  1510. }
  1511. };
  1512.  
  1513. var domain = document.domain, name;
  1514. while (domain.indexOf('.') !== -1) {
  1515. if (scripts.hasOwnProperty(domain)) {
  1516. if (typeof scripts[domain] === 'function') {
  1517. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  1518. }
  1519. for (name in scripts[domain]) {
  1520. if (name !== 'now') {
  1521. (name === 'load' ? window : document)
  1522. .addEventListener (name, scripts[domain][name], false);
  1523. } else {
  1524. scripts[domain][name]();
  1525. }
  1526. }
  1527. }
  1528. domain = domain.slice(domain.indexOf('.') + 1);
  1529. }
  1530. })();