RU AdList JS Fixes

try to take over the world!

当前为 2017-06-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20170616.1
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_deleteValue
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var win = (unsafeWindow || window),
  19. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  20. isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  21. isChrome = !!window.chrome && !!window.chrome.webstore,
  22. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  23. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  24. isFirefox = typeof InstallTrigger !== 'undefined',
  25. inIFrame = (win.self !== win.top),
  26. _getAttribute = Element.prototype.getAttribute,
  27. _setAttribute = Element.prototype.setAttribute,
  28. _de = document.documentElement,
  29. _appendChild = Document.prototype.appendChild.bind(_de),
  30. _removeChild = Document.prototype.removeChild.bind(_de);
  31.  
  32. // NodeList iterator polyfill (mostly for Safari)
  33. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  34. if (!NodeList.prototype[Symbol.iterator]) {
  35. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  36. }
  37.  
  38. // Options
  39. var opts = {
  40. 'useWSIFunc': useWSI
  41. };
  42. (function(){
  43. function optsCall(callback) {
  44. // Register event listener
  45. var key = "optsCallEvent_" + Math.random().toString(36).substr(2),
  46. cb = callback.func.bind(callback.name);
  47. window.addEventListener(key, cb, false);
  48. // Generate and dispatch synthetic event
  49. var ev = document.createEvent("HTMLEvents");
  50. ev.initEvent(key, true, false);
  51. window.dispatchEvent(ev);
  52. // Remove listener
  53. window.removeEventListener(key, cb, false);
  54. }
  55. function initOptsHandler() {
  56. /*jshint validthis:true */
  57. opts[this] = GM_getValue(this, true);
  58. if(opts[this]) {
  59. opts[this+'Func']();
  60. }
  61. }
  62. optsCall({
  63. func: initOptsHandler,
  64. name: 'useWSI'
  65. });
  66. // show options page
  67. function openOptions() {
  68. var ovl = document.createElement('div'),
  69. inner = document.createElement('div');
  70. ovl.style = (
  71. 'position: fixed;'+
  72. 'top:0; left:0;'+
  73. 'bottom: 0; right: 0;'+
  74. 'background: rgba(0,0,0,0.85);'+
  75. 'z-index: 2147483647;'+
  76. 'padding: 5em'
  77. );
  78. inner.style = (
  79. 'background: whitesmoke;'+
  80. 'font-size: 10pt;'+
  81. 'color: black;'+
  82. 'padding: 1em'
  83. );
  84. inner.textContent = 'JS Fixes Options: (reload page to apply)';
  85. inner.appendChild(document.createElement('br'));
  86. inner.appendChild(document.createElement('br'));
  87. ovl.addEventListener('click', function(e){
  88. if (e.target === ovl) {
  89. ovl.parentNode.removeChild(ovl);
  90. e.preventDefault();
  91. }
  92. e.stopPropagation();
  93. }, false);
  94. // append checkbox with label function
  95. function addCheckbox(optName, optLabel) {
  96. var c = document.createElement('input'),
  97. l = document.createElement('label');
  98. c.type = 'checkbox';
  99. c.id = optName;
  100. optsCall({
  101. func:function(){
  102. c.checked = GM_getValue(this);
  103. },
  104. name:optName
  105. });
  106. c.addEventListener('click', function(e) {
  107. optsCall({
  108. func:function(){
  109. GM_setValue(this, e.target.checked);
  110. opts[this] = e.target.checked;
  111. },
  112. name:optName
  113. });
  114. }, true);
  115. l.textContent = optLabel;
  116. l.setAttribute('for', optName);
  117. inner.appendChild(c);
  118. inner.appendChild(l);
  119. inner.appendChild(document.createElement('br'));
  120. }
  121. // append checkboxes
  122. addCheckbox('useWSI', 'Use WebSocket filter. Disable if experience problems with WebSocket connections.');
  123. document.body.appendChild(ovl);
  124. ovl.appendChild(inner);
  125. }
  126. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  127. var opPos = 0, opKey = 'Jsf', isNotKey;
  128. document.addEventListener('keydown', function(e) {
  129. isNotKey = (e.key.length > 1);
  130. if ((e.key === opKey[opPos] || isNotKey) &&
  131. (!!opPos || e.altKey && e.ctrlKey)) {
  132. opPos += (isNotKey ? 0 : 1);
  133. e.stopPropagation();
  134. e.preventDefault();
  135. } else {
  136. opPos = 0;
  137. }
  138. if (opPos === opKey.length) {
  139. opPos = 0;
  140. openOptions();
  141. }
  142. }, false);
  143. })();
  144.  
  145. // Special wrapper script to run scripts designed to override standard DOM functions
  146. // In Firefox appends supplied script to a page to make it run in page context and let
  147. // page content access overridden functions. In other browsers just run it as-is.
  148. function scriptLander(func, prepend) {
  149. if (!isFirefox) {
  150. func();
  151. return;
  152. }
  153. var s = document.createElement('script');
  154. s.textContent = '(function(){var win=window;' + (
  155. prepend && prepend.join('') || ''
  156. ) + '!' + func + '();})();';
  157. _appendChild(s);
  158. _removeChild(s);
  159. }
  160.  
  161. // Creates and return protected style (unless protection is manually disabled).
  162. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  163. function createStyle(rules, props, skip_protect) {
  164. function _createGetterSetter(obj) {
  165. return {
  166. get: function() {return obj;}, //pretend to be empty
  167. set: function() {},
  168. enumerable: true
  169. };
  170. }
  171. function _protect(style) {
  172. Object.defineProperty(style, 'sheet', {
  173. value: null,
  174. enumerable: true
  175. });
  176. Object.defineProperty(style, 'disabled', {
  177. get: function() {return true;}, //pretend to be disabled
  178. set: function() {},
  179. enumerable: true
  180. });
  181. (new MutationObserver(function() {
  182. _removeChild(style);
  183. })).observe(style, {childList: true});
  184. }
  185.  
  186. function _create() {
  187. var style = _appendChild(document.createElement('style'));
  188. style.type = 'text/css';
  189. Object.assign(style, props);
  190. function insertRule(rule) {
  191. try {
  192. style.sheet.insertRule(rule, 0);
  193. } catch (e) {
  194. console.error(e);
  195. }
  196. }
  197. if (typeof rules === 'string') {
  198. insertRule(rules);
  199. } else {
  200. rules.forEach(insertRule);
  201. }
  202. if (!skip_protect) {
  203. _protect(style);
  204. }
  205. return style;
  206. }
  207.  
  208. var style = _create();
  209. if (skip_protect) {
  210. return style;
  211. }
  212.  
  213. (new MutationObserver(function(ms){
  214. var m, node,
  215. resolveInANewContext = function(resolve){
  216. setTimeout(function(resolve){
  217. resolve(_create());
  218. }, 0, resolve);
  219. },
  220. setStyle = function(st){
  221. style = st;
  222. };
  223. for (m of ms) {
  224. for (node of m.removedNodes) {
  225. if (node === style) {
  226. (new Promise(resolveInANewContext))
  227. .then(setStyle);
  228. }
  229. }
  230. }
  231. })).observe(_de, {childList:true});
  232.  
  233. return style;
  234. }
  235.  
  236. // https://greasyfork.org/scripts/19144-websuckit/
  237. function useWSI() {
  238. // check does browser support Proxy and WebSocket
  239. if (typeof Proxy !== 'function' ||
  240. typeof WebSocket !== 'function') {
  241. return;
  242. }
  243.  
  244. function getWrappedCode(removeSelf) {
  245. var text = getWrappedCode.toString()+WSI.toString();
  246. text = (
  247. '(function(){"use strict";'+
  248. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  249. '(new WSI(self||window)).init();'+
  250. '})();\n'+
  251. (removeSelf?'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')
  252. );
  253. return text;
  254. }
  255.  
  256. function WSI(win, safeWin) {
  257. safeWin = safeWin || win;
  258. var masks = [], filter;
  259. for (filter of [// blacklist
  260. '||185.87.50.147^',
  261. '||10root25.website^', '||24video.xxx^',
  262. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  263. '||bgrndi.com^', '||brokeloy.com^',
  264. '||cnamerutor.ru^',
  265. '||docfilms.info^', '||dreadfula.ru^',
  266. '||et-code.ru^',
  267. '||franecki.net^', '||film-doma.ru^',
  268. '||free-torrent.org^', '||free-torrent.pw^',
  269. '||free-torrents.org^', '||free-torrents.pw^',
  270. '||game-torrent.info^', '||gocdn.ru^',
  271. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  272. '||kiev.ua^', '||kinotochka.net^',
  273. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  274. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  275. '||mail.ru^', '||marketgid.com^', '||mixadvert.com^', '||mxtads.com^',
  276. '||nickhel.com^',
  277. '||oconner.biz^', '||oconner.link^', '||octoclick.net^', '||octozoon.org^',
  278. '||pkpojhc.com^',
  279. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  280. '||recreativ.ru^', '||redtram.com^', '||regpole.com^', '||rootmedia.ws^', '||ruttwind.com^',
  281. '||skidl.ru^',
  282. '||torvind.com^', '||traffic-media.co^', '||trafmag.com^',
  283. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  284. '||xxuhter.ru^',
  285. '||yuiout.online^',
  286. '||zoom-film.ru^'
  287. ]) {
  288. masks.push(new RegExp(
  289. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  290. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  291. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  292. .replace(/^\|\|/,'^(ws|http)s?:\\/+([^\/.]+\\.)*'),
  293. 'i'));
  294. }
  295.  
  296. function isBlocked(url) {
  297. for (var mask of masks) {
  298. if (mask.test(url)) {
  299. return true;
  300. }
  301. }
  302. return false;
  303. }
  304.  
  305. var realWebSocket = win.WebSocket;
  306. function wsGetter (target, name) {
  307. try {
  308. if (typeof realWebSocket.prototype[name] === 'function') {
  309. if (name === 'close' || name === 'send') { // send also closes connection
  310. target.readyState = realWebSocket.CLOSED;
  311. }
  312. return (
  313. function fake() {
  314. console.log('[WSI] Invoked function "'+name+'"', '| Tracing', (new Error()));
  315. return;
  316. }
  317. );
  318. }
  319. if (typeof realWebSocket.prototype[name] === 'number') {
  320. return realWebSocket[name];
  321. }
  322. } catch(ignore) {}
  323. return target[name];
  324. }
  325.  
  326. function createWebSocketWrapper(target) {
  327. return new Proxy(realWebSocket, {
  328. construct: function (target, args) {
  329. var url = args[0];
  330. console.log('[WSI] Opening socket on ' + url + ' \u2026');
  331. if (isBlocked(url)) {
  332. console.log("[WSI] Blocked.");
  333. return new Proxy({
  334. url: url,
  335. readyState: realWebSocket.OPEN
  336. }, {
  337. get: wsGetter
  338. });
  339. }
  340. return new target(args[0], args[1]);
  341. }
  342. });
  343. }
  344.  
  345. function WorkerWrapper() {
  346. var realWorker = win.Worker;
  347. win.Worker = function Worker() {
  348. var isBlobURL = /^blob:/i,
  349. resourceURI = arguments[0],
  350. deepLogMode = false,
  351. xhr = null,
  352. _callbacks = new WeakMap(),
  353. _worker = null,
  354. _onevs = { names: ['onmessage', 'onerror'] },
  355. _actions = [],
  356. /*jshint validthis:true */
  357. _self = this;
  358.  
  359. function log() {
  360. if (deepLogMode) {
  361. console.log.apply(this, arguments);
  362. }
  363. }
  364.  
  365. function callbackWrapper(func) {
  366. if (typeof func !== 'function') {
  367. return undefined;
  368. }
  369. return (
  370. function callback() {
  371. func.apply(_self, arguments);
  372. }
  373. );
  374. }
  375.  
  376. function updateWorker() {
  377. var action, name, args;
  378. for ([action, name, args] of _actions) {
  379. log(_worker, action, name, args);
  380. if (action === 'set') {
  381. _worker[name] = callbackWrapper(args);
  382. }
  383. if (action === 'call') {
  384. _worker[name].apply(_worker, args);
  385. }
  386. }
  387. _actions.length = 0;
  388. log('Applied buffered actions.');
  389. }
  390.  
  391. function createGetSet(prop) {
  392. return {
  393. get: function() {
  394. return _onevs[prop];
  395. },
  396. set: function(val) {
  397. _onevs[prop] = val;
  398. if (_worker) {
  399. _worker[prop] = callbackWrapper(val);
  400. } else {
  401. _actions.push(['set', prop, val]);
  402. log('Stored into buffer:', arguments);
  403. }
  404. return val;
  405. },
  406. enumerable: true
  407. };
  408. }
  409. for (var _onev of _onevs.names) {
  410. Object.defineProperty(_self, _onev, createGetSet(_onev));
  411. }
  412.  
  413. _self.postMessage = function(){
  414. if (_worker) {
  415. _worker.postMessage.apply(_worker, arguments);
  416. } else {
  417. _actions.push(['call', 'postMessage', arguments]);
  418. log('Stored into buffer:', arguments);
  419. }
  420. };
  421. _self.terminate = function(){
  422. if (_worker) {
  423. _worker.terminate();
  424. } else {
  425. _actions.push(['call','terminate', arguments]);
  426. log('Stored into buffer:', arguments);
  427. }
  428. };
  429. _self.addEventListener = function(event, callback, other) {
  430. if (typeof callback !== 'function') {
  431. return;
  432. }
  433. if (!_callbacks.has(callback)) {
  434. _callbacks.set(callback, callbackWrapper(callback));
  435. }
  436. arguments[1] = _callbacks.get(callback);
  437. if (_worker) {
  438. _worker.addEventListener.apply(_worker, arguments);
  439. } else {
  440. _actions.push(['call', 'addEventListener', arguments]);
  441. log('Stored into buffer:', arguments);
  442. }
  443. };
  444. _self.removeEventListener = function(event, callback, other){
  445. if (typeof callback !== 'function' || !_callbacks.has(callback)) {
  446. return;
  447. }
  448. arguments[1] = _callbacks.get(callback);
  449. _callbacks.delete(callback);
  450. if (_worker) {
  451. _worker.removeEventListener.apply(_worker, arguments);
  452. } else {
  453. _actions.push(['call', 'removeEventListener', arguments]);
  454. log('Stored into buffer:', arguments);
  455. }
  456. };
  457.  
  458. if (!isBlobURL.test(resourceURI)) {
  459. _worker = new realWorker(resourceURI);
  460. return; // not a blob, no need to wrap
  461. }
  462.  
  463. xhr = new XMLHttpRequest();
  464. xhr.responseType = 'blob';
  465. try {
  466. xhr.open('GET', resourceURI, true);
  467. } catch(ignore) {
  468. _worker = new realWorker(resourceURI);
  469. return; // failed to open connection, unable to continue wrapping procedure
  470. }
  471. (new Promise(function(resolve, reject){
  472. if (xhr.readyState !== XMLHttpRequest.OPENED) {
  473. // connection wasn't opened, unable to continue wrapping procedure
  474. return reject();
  475. }
  476. xhr.onload = function(){
  477. if (this.status === 200) {
  478. var reader = new FileReader();
  479. reader.addEventListener("loadend", function() {
  480. resolve(new realWorker(URL.createObjectURL(
  481. new Blob([getWrappedCode(false)+this.result])
  482. )));
  483. });
  484. reader.readAsText(this.response);
  485. }
  486. };
  487. xhr.onerror = function(e) {
  488. reject(e);
  489. };
  490. xhr.send();
  491. })).then(function(val) {
  492. _worker = val;
  493. updateWorker();
  494. }).catch(function(e) {
  495. // connection were blocked by CSP or something else triggered error event on xhr object
  496. // it should be safe to create worker with original URI now and let it dispatch error event
  497. _worker = new realWorker(resourceURI);
  498. updateWorker();
  499. });
  500.  
  501. if (deepLogMode) {
  502. return new Proxy(_self, {
  503. get: function(target, prop) {
  504. console.log('Worker _get_', prop);
  505. return target[prop];
  506. },
  507. set: function(target, prop, val) {
  508. console.log('Worker _set_', prop, '_to_', val);
  509. target[prop] = val;
  510. return val;
  511. }
  512. });
  513. }
  514. }.bind(safeWin);
  515. }
  516.  
  517. function CreateElementWrapper() {
  518. var realCreateElement = Document.prototype.createElement,
  519. _addEventListener = Element.prototype.addEventListener,
  520. code = encodeURIComponent('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>\n'),
  521. isDataURL = /^data:/i,
  522. isBlobURL = /^blob:/i;
  523.  
  524. function frameRewrite(e) {
  525. var f = e.target,
  526. w = f.contentWindow;
  527. if (!f.src || (w && isBlobURL.test(f.src))) {
  528. w.WebSocket = createWebSocketWrapper();
  529. }
  530. if (isDataURL.test(f.src) && f.src.indexOf(code) < 0) {
  531. f.src = f.src.replace(',',',' + code);
  532. }
  533. }
  534.  
  535. var scriptMap = new WeakMap();
  536. scriptMap.isBlocked = isBlocked;
  537. var onErrorWrapper = {
  538. set: function(val) {
  539. if (scriptMap.has(this)) {
  540. this.removeEventListener('error', scriptMap.get(this).wrp, false);
  541. scriptMap.delete(this);
  542. }
  543. if (!val || typeof val !== 'function') {
  544. return val;
  545. }
  546. scriptMap.set(this, {
  547. org: val,
  548. wrp: function() {
  549. if (scriptMap.isBlocked(this.src)) {
  550. console.log('[WSI] Blocked "onerror" callback from', this);
  551. return;
  552. }
  553. scriptMap.get(this).org.apply(this, arguments);
  554. }
  555. });
  556. this.addEventListener('error', scriptMap.get(this).wrp, false);
  557. return val;
  558. },
  559. get: function() {
  560. return scriptMap.has(this) ? scriptMap.get(this).org : null;
  561. },
  562. enumerable: true
  563. };
  564. function wrappedCreateElement(name) {
  565. /*jshint validthis:true */
  566. var el = realCreateElement.apply(this, arguments);
  567. if (el.tagName === 'IFRAME') {
  568. _addEventListener.call(el, 'load', frameRewrite, false);
  569. }
  570. if (el.tagName === 'SCRIPT') {
  571. Object.defineProperty(el, 'onerror', onErrorWrapper);
  572. }
  573. return el;
  574. }
  575. Document.prototype.createElement = wrappedCreateElement;
  576.  
  577. document.addEventListener('DOMContentLoaded', function(){
  578. for (var ifr of document.querySelectorAll('IFRAME')) {
  579. _addEventListener.call(ifr, 'load', frameRewrite, false);
  580. }
  581. }, false);
  582. }
  583.  
  584. this.init = function() {
  585. win.WebSocket = createWebSocketWrapper();
  586. if (!(/firefox/i.test(navigator.userAgent))) {
  587. WorkerWrapper(); // skip WorkerWrapper in Firefox
  588. }
  589. if (typeof document !== 'undefined') {
  590. CreateElementWrapper();
  591. }
  592. };
  593. }
  594.  
  595. if (isFirefox) {
  596. var script = document.createElement('script');
  597. script.appendChild(document.createTextNode(getWrappedCode(true)));
  598. document.head.insertBefore(script, document.head.firstChild);
  599. return; //we don't want to call functions on page from here in Fx, so exit
  600. }
  601.  
  602. (new WSI((unsafeWindow||self||window),(self||window))).init();
  603. }
  604.  
  605. if (!isFirefox) { // scripts for non-Firefox browsers
  606.  
  607. // https://greasyfork.org/scripts/14720-it-s-not-important
  608. (function(){
  609. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  610. ret_b = function(a,b){return b;},
  611. _toLowerCase = String.prototype.toLowerCase,
  612. protectedNodes = new WeakSet();
  613.  
  614. function unimportanter(node) {
  615. var style = (node.nodeType === Node.ELEMENT_NODE) ?
  616. _getAttribute.call(node, 'style') : null;
  617. if (!style || !imptt.test(style) || node.style.display === 'none') {
  618. return false; // get out if we have nothing to do here
  619. }
  620. if (node.nodeName === 'IFRAME' && node.src &&
  621. node.src.slice(0,17) === 'chrome-extension:') {
  622. return false; // Web of Trust uses this method to add their frame
  623. }
  624. protectedNodes.add(node);
  625. _setAttribute.call(node, 'style',
  626. style.replace(imptt, ret_b));
  627. return true;
  628. }
  629.  
  630. function logger(log) {
  631. if (log) {
  632. console.log('Some page elements became a bit less important.');
  633. }
  634. }
  635.  
  636. (new MutationObserver(function(mutations) {
  637. setTimeout(function(ms) {
  638. var log = false, m, node;
  639. for (m of ms) {
  640. for (node of m.addedNodes) {
  641. log = unimportanter(node) | log;
  642. }
  643. }
  644. logger(log);
  645. }, 0, mutations);
  646. })).observe(document, {
  647. childList : true,
  648. subtree : true
  649. });
  650.  
  651. Element.prototype.setAttribute = function setAttribute(name, value) {
  652. "[native code]";
  653. var replaced = value;
  654. if (_toLowerCase.call(name) === 'style' && protectedNodes.has(this)) {
  655. replaced = value.replace(imptt, ret_b);
  656. logger(replaced !== value);
  657. }
  658. return _setAttribute.call(this, name, replaced);
  659. };
  660.  
  661. win.addEventListener ("load", function(){
  662. var log = false, imp;
  663. for (imp of document.querySelectorAll('[style*="!"]')) {
  664. log = unimportanter(imp) | log;
  665. }
  666. logger(log);
  667. }, false);
  668. })();
  669.  
  670. }
  671.  
  672. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  673. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  674. (function(){
  675. var adWords = ['Яндекс.Директ','Реклама','Ad'],
  676. genericAdSelectors = (
  677. '.serp-adv__head + .serp-item,'+
  678. '#adbanner,'+
  679. '.serp-adv,'+
  680. '.b-spec-adv,'+
  681. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  682. );
  683. function remove(node) {
  684. node.parentNode.removeChild(node);
  685. }
  686. // Generic ads removal and fixes
  687. function removeGenericAds() {
  688. var s = document.querySelector('.serp-header');
  689. if (s) {
  690. s.style.marginTop='0';
  691. }
  692. for (s of document.querySelectorAll(genericAdSelectors)) {
  693. remove(s);
  694. }
  695. }
  696. // Search ads
  697. function removeSearchAds() {
  698. var s, item, l;
  699. for (s of document.querySelectorAll('.t-construct-adapter__legacy')) {
  700. item = s.querySelector('.organic__subtitle');
  701. l = window.getComputedStyle(item, ':after').content;
  702. if (item && adWords.indexOf(l.replace(/"/g,'')) > -1) {
  703. remove(s);
  704. console.log('Ads removed.');
  705. }
  706. }
  707. }
  708. // News ads
  709. function removeNewsAds() {
  710. for (var s of document.querySelectorAll(
  711. '.page-content__left > *,'+
  712. '.page-content__right > *:not(.page-content__col),'+
  713. '.page-content__right > .page-content__col > *'
  714. )) {
  715. if (s.textContent.indexOf(adWords[0]) > -1 ||
  716. (s.clientHeight < 15 && s.classList.contains('rubric'))) {
  717. remove(s);
  718. console.log('Ads removed.');
  719. }
  720. }
  721. }
  722. // Music ads
  723. function removeMusicAds() {
  724. for (var s of document.querySelectorAll('.ads-block')) {
  725. remove(s);
  726. }
  727. }
  728. // Mail ads
  729. function removeMailAds() {
  730. var slice = Array.prototype.slice,
  731. nodes = slice.call(document.querySelectorAll('.ns-view-folders')),
  732. node, len, cls;
  733. for (node of nodes) {
  734. if (!len || len > node.classList.length) {
  735. len = node.classList.length;
  736. }
  737. }
  738. node = nodes.pop();
  739. while (node) {
  740. if (node.classList.length > len) {
  741. for (cls of slice.call(node.classList)) {
  742. if (cls.indexOf('-') === -1) {
  743. remove(node);
  744. break;
  745. }
  746. }
  747. }
  748. node = nodes.pop();
  749. }
  750. }
  751. // News fixes
  752. function removePageAdsClass() {
  753. if (document.body.classList.contains("b-page_ads_yes")){
  754. document.body.classList.remove("b-page_ads_yes");
  755. console.log('Page ads class removed.');
  756. }
  757. }
  758. // Function to attach an observer to monitor dynamic changes on the page
  759. function pageUpdateObserver(func, obj, params) {
  760. if (obj) {
  761. (new MutationObserver(func)).observe(obj,(params || {childList:true, subtree:true}));
  762. }
  763. }
  764. // Cleaner
  765. document.addEventListener ('DOMContentLoaded', function() {
  766. removeGenericAds();
  767. if (win.location.hostname.search(/^mail\./i) === 0) {
  768. pageUpdateObserver(function(ms, o){
  769. var aside = document.querySelector('.mail-Layout-Aside');
  770. if (aside) {
  771. o.disconnect();
  772. pageUpdateObserver(removeMailAds, aside);
  773. }
  774. }, document.querySelector('BODY'));
  775. removeMailAds();
  776. } else if (win.location.hostname.search(/^music\./i) === 0) {
  777. pageUpdateObserver(removeMusicAds, document.querySelector('.sidebar'));
  778. removeMusicAds();
  779. } else if (win.location.hostname.search(/^news\./i) === 0) {
  780. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  781. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  782. removeNewsAds();
  783. removePageAdsClass();
  784. } else {
  785. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  786. removeSearchAds();
  787. }
  788. });
  789. })();
  790. }
  791. // Yandex Link Tracking
  792. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href)) {
  793. // Partially based on https://greasyfork.org/en/scripts/22737-remove-yandex-redirect
  794. (function(){
  795. var link, selectors = (
  796. 'A[onmousedown*="/jsredir"],'+
  797. 'A[data-vdir-href],'+
  798. 'A[data-counter]'
  799. );
  800. function removeTrackingAttributes(link) {
  801. link.removeAttribute('onmousedown');
  802. if (link.hasAttribute('data-vdir-href')) {
  803. link.removeAttribute('data-vdir-href');
  804. link.removeAttribute('data-orig-href');
  805. }
  806. if (link.hasAttribute('data-counter')) {
  807. link.removeAttribute('data-counter');
  808. link.removeAttribute('data-bem');
  809. }
  810. }
  811. function removeTracking(scope) {
  812. for (link of scope.querySelectorAll(selectors)) {
  813. removeTrackingAttributes(link);
  814. }
  815. }
  816. document.addEventListener('DOMContentLoaded', function(e) {
  817. removeTracking(e.target);
  818. });
  819. (new MutationObserver(function(ms) {
  820. var m, node;
  821. for (m of ms) {
  822. for (node of m.addedNodes) {
  823. if (node.nodeType === Node.ELEMENT_NODE) {
  824. if (node.tagName === 'A' && node.matches(selectors)) {
  825. removeTrackingAttributes(node);
  826. } else {
  827. removeTracking(node);
  828. }
  829. }
  830. }
  831. }
  832. })).observe(_de, {childList: true, subtree: true});
  833. })();
  834. return; //skip fixes for other sites
  835. }
  836.  
  837. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  838. document.addEventListener ('DOMContentLoaded', function() {
  839. var tmp;
  840. function log (e) {
  841. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  842. }
  843. if (win.adv_enabled !== undefined && win.condition_detected !== undefined) { // moonwalk
  844. log('Moonwalk');
  845. if (win.adv_enabled) {
  846. win.adv_enabled = false;
  847. }
  848. win.condition_detected = false;
  849. if (win.MXoverrollCallback) {
  850. document.addEventListener('click', function catcher(e){
  851. e.stopPropagation();
  852. win.MXoverrollCallback.call(window);
  853. document.removeEventListener('click', catcher, true);
  854. }, true);
  855. }
  856. } else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined) { // hdgo
  857. log('HDGo');
  858. document.body.onclick = null;
  859. tmp = document.querySelector('#swtf');
  860. if (tmp) {
  861. tmp.style.display = 'none';
  862. }
  863. if (win.banner_second !== undefined) {
  864. win.banner_second = 0;
  865. }
  866. if (win.$banner_ads !== undefined) {
  867. win.$banner_ads = false;
  868. }
  869. if (win.$new_ads !== undefined) {
  870. win.$new_ads = false;
  871. }
  872. if (win.createCookie !== undefined) {
  873. win.createCookie('popup','true','999');
  874. }
  875. if (win.canRunAds !== undefined && win.canRunAds !== true) {
  876. win.canRunAds = true;
  877. }
  878. } else if (win.MXoverrollCallback && win.iframeSearch !== undefined) { // kodik
  879. log('Kodik');
  880. tmp = document.querySelector('.play_button');
  881. if (tmp) {
  882. tmp.onclick = win.MXoverrollCallback.bind(window);
  883. }
  884. win.IsAdBlock = false;
  885. }
  886. }, false);
  887.  
  888. // Automated protection against specific circumvention method based on unwrapping various functions,
  889. // hiding ads in the Shadow DOM and injecting iFrames with ads. Previously this code were known as
  890. // apiBreaker since it were breaking Shadow DOM and onerror/onload API on specific domains. This
  891. // version should be safe enough to run on majority of sites without actually breaking them.
  892. scriptLander(function() {
  893. var blacklist = new WeakMap(),
  894. replacer, func;
  895. /* Wrap functions used to attach shadow root to a node */
  896. replacer = function (func) {
  897. return function() {
  898. blacklist.set(this, true);
  899. return func.apply(this, arguments);
  900. };
  901. };
  902. for (func of ['createShadowRoot', 'attachShadow']) {
  903. if (func in Element.prototype) {
  904. Element.prototype[func] = replacer(Element.prototype[func]);
  905. }
  906. }
  907. /* Wrap functions used to insert/append elements to check for IFRAME objects */
  908. replacer = function (func) {
  909. return function(el, par) {
  910. if (el.tagName === 'IFRAME' &&
  911. ((typeof par === 'object' && blacklist.get(par))/* ||
  912. el.style.display === 'none'*/)) {
  913. console.log('Blocked suspicious', func.name, arguments);
  914. return null;
  915. }
  916. return func.apply(this, arguments);
  917. };
  918. };
  919. for (func of [/*'appendChild', */'insertBefore']) {
  920. Object.defineProperty(Element.prototype, func, {
  921. value: replacer(Element.prototype[func]), enumerable: true
  922. });
  923. }
  924. });
  925.  
  926. // === Helper functions ===
  927.  
  928. // function to search and remove nodes by content
  929. // selector - standard CSS selector to define set of nodes to check
  930. // words - regular expression to check content of the suspicious nodes
  931. // params - object with multiple extra parameters:
  932. // .log - display log in the console
  933. // .hide - set display to none instead of removing from the page
  934. // .parent - parent node to remove if content is found in the child node
  935. // .siblings - number of simling nodes to remove (excluding text nodes)
  936. function scRemove(e) {
  937. e.parentNode.removeChild(e);
  938. }
  939. function scHide(e) {
  940. var s = _getAttribute.call(e, 'style') || '',
  941. h = ';display:none!important;';
  942. if (s.indexOf(h) < 0) {
  943. _setAttribute.call(e, 'style', s+h);
  944. }
  945. }
  946. function scissors (selector, words, scope, params) {
  947. if (params.log) console.log('[s] starting with', selector, words, scope, JSON.stringify(params));
  948. var remFunc = (params.hide ? scHide : scRemove),
  949. iterFunc = (params.siblings > 0 ?
  950. 'nextSibling' :
  951. 'previousSibling'),
  952. toRemove = [],
  953. siblings,
  954. node;
  955. for (node of scope.querySelectorAll(selector)) {
  956. if (params.log) console.log('[s] found node', node);
  957. if (params.parent) {
  958. while(node !== scope && !(node.matches(params.parent))) {
  959. node = node.parentNode;
  960. }
  961. if (params.log) console.log('[s] moving to parent node', node);
  962. }
  963. if (words.test(node.innerHTML) || !node.childNodes.length) {
  964. // drill up to the specified parent node if required
  965. if (node === scope) {
  966. if (params.log) console.log('[s] oops, we don\'t want to remove our scope!');
  967. break;
  968. }
  969. if (toRemove.indexOf(node) === -1) {
  970. if (params.log) console.log('[s] adding node into list for removal');
  971. toRemove.push(node);
  972. // add multiple nodes if defined more than one sibling
  973. siblings = Math.abs(params.siblings) || 0;
  974. while (siblings) {
  975. node = node[iterFunc];
  976. if (node.nodeType === Node.ELEMENT_NODE) {
  977. if (params.log) console.log('[s] adding sibling node', node);
  978. toRemove.push(node);
  979. siblings -= 1; //count only element nodes
  980. } else if (!params.hide) {
  981. if (params.log) console.log('[s] adding sibling node', node);
  982. toRemove.push(node);
  983. }
  984. }
  985. } else {
  986. if (params.log) console.log('[s] node already marked for removal');
  987. }
  988. } else {
  989. if (params.log) console.log('[s] word test failed, proceed to the next node');
  990. }
  991. }
  992. if (params.log) console.log('[s] proceed with', (params.hide?'hide':'removal'), 'of', toRemove);
  993. for (node of toRemove) {
  994. remFunc(node);
  995. }
  996. return toRemove.length;
  997. }
  998.  
  999. // function to perform multiple checks if ads inserted with a delay
  1000. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1001. // also does 1 extra check when a page completely loads
  1002. // selector and words - passed dow to scissors
  1003. // params - object with multiple extra parameters:
  1004. // .log - display log in the console
  1005. // .root - selector to narrow down scope to scan;
  1006. // .observe - if true then check will be performed continuously;
  1007. // Other parameters passed down to scissors.
  1008. function gardener(selector, words, params) {
  1009. params = params || {};
  1010. if (params.log) console.log('[g] starting with', selector, words, JSON.stringify(params));
  1011. var scope = document,
  1012. nonstop = false;
  1013. // narrow down scope to a specific element
  1014. if (params.root) {
  1015. scope = scope.querySelector(params.root);
  1016. if (!scope) {// exit if the root element is not present on the page
  1017. return 0;
  1018. }
  1019. if (params.log) console.log('[g] scope', scope);
  1020. }
  1021. // add observe mode if required
  1022. if (params.observe) {
  1023. if (typeof MutationObserver === 'function') {
  1024. (new MutationObserver(function(ms){
  1025. for (var m of ms) {
  1026. if (m.addedNodes.length) {
  1027. scissors(selector, words, scope, params);
  1028. }
  1029. }
  1030. })).observe(scope, {childList:true, subtree: true});
  1031. if (params.log) console.log('[g] observer enabled');
  1032. } else {
  1033. nonstop = true;
  1034. if (params.log) console.log('[g] nonstop mode enabled');
  1035. }
  1036. }
  1037. // wait for a full page load to do one extra cut
  1038. win.addEventListener('load',function(){
  1039. if (params.log) console.log('[g] onload cleanup');
  1040. scissors(selector, words, scope, params);
  1041. });
  1042. // do multiple cuts until ads removed
  1043. function cut(sci, s, w, sc, p, i) {
  1044. if (i > 0) {
  1045. i -= 1;
  1046. }
  1047. if (i && !sci(s, w, sc, p)) {
  1048. setTimeout(cut, 100, sci, s, w, sc, p, i);
  1049. }
  1050. }
  1051. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  1052. }
  1053.  
  1054. // Helper function to close background tab if site opens itself in a new tab and then
  1055. // loads a 3rd-party page in the background one (thus performing background redirect).
  1056. function preventBackgroundRedirect() {
  1057. // create "cose_me" event to call high-level window.close()
  1058. var key = Math.random().toString(36).substr(2);
  1059. window.addEventListener('close_me_'+key, function(e) {
  1060. window.close();
  1061. });
  1062.  
  1063. // window.open wrapper
  1064. function pbrLander() {
  1065. var orgOpen = window.open.bind(window),
  1066. idx = String.prototype.indexOf,
  1067. event = new CustomEvent("close_me_%key%", {});
  1068. function closeWindow(){
  1069. // site went to a new tab and attempts to unload
  1070. // call for high-level close through event
  1071. window.dispatchEvent(event);
  1072. }
  1073. // window.open wrapper
  1074. function open(){
  1075. console.log(arguments, window.location.host);
  1076. if (arguments[0] &&
  1077. (idx.call(arguments[0], window.location.host) > -1 ||
  1078. idx.call(arguments[0], '://') === -1)) {
  1079. window.addEventListener('unload', closeWindow, true);
  1080. }
  1081. orgOpen.apply(window, arguments);
  1082. }
  1083. window.open = open.bind(window);
  1084. // Node.createElement wrapper to prevent click-dispatch in Google Chrome and similar browsers
  1085. var realCreateElement = Document.prototype.createElement;
  1086. function wrappedCreateElement(name) {
  1087. /*jshint validthis:true */
  1088. var el = realCreateElement.apply(this, arguments);
  1089. if (el.tagName === 'A') {
  1090. el.addEventListener('click', function(e){
  1091. if (!e.target.parentNode || !e.isTrusted) {
  1092. window.addEventListener('unload', closeWindow, true);
  1093. }
  1094. }, false);
  1095. }
  1096. return el;
  1097. }
  1098. Document.prototype.createElement = wrappedCreateElement;
  1099. console.log("Background redirect prevention enabled.");
  1100. }
  1101.  
  1102. // land wrapper on the page
  1103. var script = document.createElement('script');
  1104. script.appendChild(document.createTextNode('('+pbrLander.toString().replace(/%key%/g,key)+')();'));
  1105. document.head.insertBefore(script, document.head.firstChild);
  1106. script.parentNode.removeChild(script);
  1107. }
  1108.  
  1109. // Function to catch and block various methods to open a new window with 3rd-party content.
  1110. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1111. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1112. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1113. // node or simply a link with piece of javascript code in the HREF attribute.
  1114. function preventPopups() {
  1115. if (inIFrame) {
  1116. var i = -1, val;
  1117. do {
  1118. i++;
  1119. val = GM_getValue('forbid.popups.'+i);
  1120. } while(val & val !== win.location.href);
  1121. GM_setValue('forbid.popups.'+i, win.location.href);
  1122. win.top.postMessage('forbid.popups.'+i,'*');
  1123. return;
  1124. }
  1125.  
  1126. scriptLander(function() {
  1127. var _createElement = Document.prototype.createElement,
  1128. _appendChild = Element.prototype.appendChild;
  1129.  
  1130. function open() {
  1131. '[native code]';
  1132. console.log('Site attempted to open a new window', arguments);
  1133. function nil(){}
  1134. return {
  1135. document: {
  1136. write: nil,
  1137. writeln: nil
  1138. }
  1139. };
  1140. }
  1141.  
  1142. function redefineOpen(obj) {
  1143. Object.defineProperty(obj, 'open', {
  1144. get: function () {
  1145. return open;
  1146. },
  1147. set: function (val) {
  1148. console.log('Site attempted to change window.open');
  1149. return val;
  1150. },
  1151. enumerable: true
  1152. });
  1153. }
  1154. redefineOpen(win);
  1155.  
  1156. Document.prototype.createElement = function createElement(name) {
  1157. /*jshint validthis:true */
  1158. var el = _createElement.apply(this, arguments);
  1159. if (el.tagName === 'A') {
  1160. el.addEventListener('click', function(e) {
  1161. if (!e.target.parentNode || !e.isTrusted ||
  1162. (e.target.href && e.target.href.toLowerCase().indexOf('javascript') > -1)) {
  1163. e.preventDefault();
  1164. console.log('Blocked suspicious click event', e, 'on', e.target);
  1165. }
  1166. }, false);
  1167. }
  1168. if (el.tagName === 'IFRAME') {
  1169. el.addEventListener('load', function(){
  1170. try {
  1171. redefineOpen(this.contentWindow);
  1172. } catch(ignore) {}
  1173. }, false);
  1174. }
  1175. return el;
  1176. };
  1177.  
  1178. Element.prototype.appendChild = function appendChild() {
  1179. /*jshint validthis:true */
  1180. var child = _appendChild.apply(this, arguments);
  1181. if (child && child.nodeType === Node.ELEMENT_NODE && child.tagName === 'IFRAME') {
  1182. try {
  1183. redefineOpen(child.contentWindow);
  1184. } catch(ignore) {}
  1185. }
  1186. return child;
  1187. };
  1188. console.log('Popup prevention enabled.');
  1189. });
  1190. }
  1191. // External listener for case when site known to open popups were loaded in iframe
  1192. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1193. // Some sites replace frame's window.location with data-url to run in clean context
  1194. (function(){
  1195. var popWindows = new WeakSet();
  1196. if (!inIFrame) {
  1197. window.addEventListener('message', function(e){
  1198. if (e.data.slice(0,13) === 'forbid.popups' && !popWindows.has(e.source)) {
  1199. var src = GM_getValue(e.data);
  1200. if (src) {
  1201. GM_deleteValue(e.data);
  1202. }
  1203. popWindows.add(e.source); // remember window of iframe with suspected domain
  1204. for (var frame of document.querySelectorAll('iframe')) {
  1205. if (frame.contentWindow === e.source) {
  1206. if (frame.hasAttribute('sandbox')) {
  1207. // remove allow-popups if frame already sandboxed
  1208. frame.sandbox.remove('allow-popups');
  1209. } else {
  1210. // set sandbox mode for troublesome frame and allow scripts and forms
  1211. frame.setAttribute('sandbox','allow-forms allow-scripts');
  1212. }
  1213. console.log('Disallowed popups from iframe', frame);
  1214. // reload frame content to apply restrictions
  1215. if (!src) {
  1216. src = frame.src;
  1217. console.log('Unable to get current iframe location, reloading from src', src);
  1218. } else {
  1219. console.log('Reloading iframe with URL', src);
  1220. }
  1221. frame.src = 'about:blank';
  1222. frame.src = src;
  1223. }
  1224. }
  1225. }
  1226. }, false);
  1227. }
  1228. })();
  1229.  
  1230. // Currently unused piece of code developed to prevent site from registering serviceWorker
  1231. // and uninstall any existing instances of serivceWorker in case there is one already.
  1232. /* Commented out since not used
  1233. function forbidServiceWorker() {
  1234. if (!("serviceWorker" in navigator)) {
  1235. return;
  1236. }
  1237. var svr = navigator.serviceWorker.ready;
  1238. Object.defineProperty(navigator, 'serviceWorker', {
  1239. value: {
  1240. register: function(){
  1241. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  1242. return new Promise(function(){});
  1243. },
  1244. ready: new Promise(function(){}),
  1245. addEventListener:function(){}
  1246. }
  1247. });
  1248. document.addEventListener('DOMContentLoaded', function() {
  1249. if (!svr) {
  1250. return;
  1251. }
  1252. svr.then(function(sw) {
  1253. console.log('Found existing serviceWorker:', sw);
  1254. console.log('Attempting to unregister...');
  1255. sw.unregister().then(function() {
  1256. console.log('Unregistered! :)');
  1257. }).catch(function(err) {
  1258. console.log('Unregistration failed. :(', err);
  1259. console.log('Try to remove it manually:');
  1260. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  1261. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  1262. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  1263. });
  1264. }).catch(function(err) {
  1265. console.log("Lol, it failed on it's own. -_-", err);
  1266. });
  1267. }, false);
  1268. }
  1269. /**/
  1270.  
  1271. // Currently obsolete code developed to prevent error and load calls on objects supposed to load resources
  1272. // from the internet like IMG or IFRAME, but missing SRC/HREF attribute. Usually tricks like this are used
  1273. // to unwrap wrapped functions to be able to load ads.
  1274. /* Commented out since not used
  1275. function errorAndLoadEventsFilter() {
  1276. var toString = Function.prototype.toString,
  1277. addEventListener = Element.prototype.addEventListener,
  1278. removeEventListener = Element.prototype.removeEventListener,
  1279. hasAttribute = Element.prototype.hasAttribute,
  1280. evtMap = new WeakMap();
  1281. Element.prototype.addEventListener = function(evt, func, capt) {
  1282. if (evt === 'error' || evt === 'load') {
  1283. if (!evtMap.get(func)) {
  1284. evtMap.set(func, function() {
  1285. if (hasAttribute.call(this, 'src') ||
  1286. hasAttribute.call(this, 'href')) {
  1287. func.apply(this, arguments);
  1288. } else {
  1289. console.log('Blocked', evt, 'handler', toString.call(func), 'on', this);
  1290. }
  1291. });
  1292. }
  1293. }
  1294. addEventListener.call(this, evt, (evtMap.get(func) || func), capt);
  1295. };
  1296. Element.prototype.removeEventListener = function(evt, func, capt) {
  1297. removeEventListener.call(this, evt, (evtMap.get(func) || func), capt);
  1298. };
  1299. Object.defineProperty(HTMLElement.prototype, 'onload', {
  1300. set: function(func) {
  1301. if(evtMap.has(this)) {
  1302. if (evtMap.get(this).onload) {
  1303. Element.prototype.removeEventListener.call(this, 'load', evtMap.get(this).onload, false);
  1304. }
  1305. evtMap.get(this).onload = func;
  1306. } else {
  1307. evtMap.set(this, { onload: func });
  1308. }
  1309. if (func) {
  1310. Element.prototype.addEventListener.call(this, 'load', func, false);
  1311. }
  1312. return func;
  1313. },
  1314. get: function() {
  1315. return evtMap.has(this) ? evtMap.get(this).onload : null;
  1316. }
  1317. });
  1318. Object.defineProperty(HTMLElement.prototype, 'onerror', {
  1319. set: function(func) {
  1320. if (evtMap.has(this)) {
  1321. evtMap.get(this).onerror = func;
  1322. } else {
  1323. evtMap.set(this, { onerror: func });
  1324. }
  1325. if (func) {
  1326. console.log('Blocked error handler', toString.call(func), 'on', this);
  1327. }
  1328. return func;
  1329. },
  1330. get: function() {
  1331. return evtMap.has(this) ? evtMap.get(this).onerror : null;
  1332. }
  1333. });
  1334. }
  1335. /**/
  1336.  
  1337. // === Scripts for specific domains ===
  1338.  
  1339. var scripts = {};
  1340. // prevent popups and redirects block
  1341. var preventPopupsNow = { 'now': preventPopups },
  1342. preventBackgroundRedirectNow = { 'now': preventBackgroundRedirect };
  1343. // Popups
  1344. scripts['biqle.ru'] = preventPopupsNow;
  1345. scripts['chaturbate.com'] = preventPopupsNow;
  1346. scripts['dfiles.ru'] = preventPopupsNow;
  1347. scripts['hentaiz.org'] = preventPopupsNow;
  1348. scripts['mirrorcreator.com'] = preventPopupsNow;
  1349. scripts['online-multy.ru'] = preventPopupsNow;
  1350. scripts['openload.co'] = preventPopupsNow;
  1351. scripts['radikal.ru'] = preventPopupsNow;
  1352. scripts['seedoff.cc'] = preventPopupsNow;
  1353. scripts['seedoff.tv'] = preventPopupsNow;
  1354. scripts['tapochek.net'] = preventPopupsNow;
  1355. scripts['thepiratebay.org'] = preventPopupsNow;
  1356. scripts['torseed.net'] = preventPopupsNow;
  1357. scripts['unionpeer.com'] = preventPopupsNow;
  1358. scripts['zippyshare.com'] = preventPopupsNow;
  1359. // Background redirects
  1360. scripts['mediafire.com'] = preventBackgroundRedirectNow;
  1361. scripts['megapeer.org'] = preventBackgroundRedirectNow;
  1362. scripts['megapeer.ru'] = preventBackgroundRedirectNow;
  1363. scripts['perfectgirls.net'] = preventBackgroundRedirectNow;
  1364. scripts['turbobit.net'] = preventBackgroundRedirectNow;
  1365.  
  1366. // other
  1367. scripts['4pda.ru'] = {
  1368. 'now': function() {
  1369. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  1370. var isForum = document.location.href.search('/forum/') !== -1,
  1371. hStyle;
  1372.  
  1373. function remove(n) {
  1374. if (n) {
  1375. n.parentNode.removeChild(n);
  1376. }
  1377. }
  1378.  
  1379. function afterClean() {
  1380. hStyle.disabled = true;
  1381. remove(hStyle);
  1382. }
  1383.  
  1384. function beforeClean() {
  1385. // attach styles before document displayed
  1386. hStyle = createStyle([
  1387. 'html { overflow-y: scroll }',
  1388. 'section[id] {'+(
  1389. 'position: absolute;'+
  1390. 'width: 100%'
  1391. )+'}',
  1392. 'article + aside * { display: none !important }',
  1393. '#header + div:after {'+(
  1394. 'content: "";'+
  1395. 'position: fixed;'+
  1396. 'top: 0;'+
  1397. 'left: 0;'+
  1398. 'width: 100%;'+
  1399. 'height: 100%;'+
  1400. 'background-color: #E6E7E9'
  1401. )+'}',
  1402. // http://codepen.io/Beaugust/pen/DByiE
  1403. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  1404. 'article + aside:after {'+(
  1405. 'content: "";'+
  1406. 'position: absolute;'+
  1407. 'width: 150px;'+
  1408. 'height: 150px;'+
  1409. 'top: 150px;'+
  1410. 'left: 50%;'+
  1411. 'margin-top: -75px;'+
  1412. 'margin-left: -75px;'+
  1413. 'box-sizing: border-box;'+
  1414. 'border-radius: 100%;'+
  1415. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  1416. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  1417. 'animation: spin 2s infinite linear'
  1418. )+'}'
  1419. ], {id:'ubrHider'}, true);
  1420.  
  1421. // display content of a page if time to load a page is more than 2 seconds to avoid
  1422. // blocking access to a page if it is loading for too long or stuck in a loading state
  1423. setTimeout(2000, afterClean);
  1424. }
  1425.  
  1426. createStyle([
  1427. '#nav .use-ad { display: block !important }',
  1428. 'article:not(.post) + article:not(#id),'+
  1429. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  1430. ]);
  1431.  
  1432. if (!isForum) {
  1433. beforeClean();
  1434. }
  1435.  
  1436. // save links to non-overridden functions to use later
  1437. var protectedElems;
  1438. // protect/hide changed attributes in case site attempt to restore them
  1439. function styleProtector(eventMode) {
  1440. var isStyleText = function(t){ return t === 'style'; },
  1441. returnUndefined = function(){},
  1442. protectedElems = new WeakMap();
  1443. function protoOverride(element, functionName, isStyleCheck, returnIfProtected) {
  1444. var oF = element.prototype[functionName], r;
  1445. element.prototype[functionName] = function() {
  1446. if (protectedElems.has(this) && isStyleCheck(arguments[0])) {
  1447. return returnIfProtected(this, arguments);
  1448. }
  1449. r = oF.apply(this, arguments);
  1450. return r;
  1451. };
  1452. }
  1453. protoOverride(Element, 'removeAttribute', isStyleText, returnUndefined);
  1454. protoOverride(Element, 'hasAttribute', isStyleText, function(_this) {
  1455. return protectedElems.get(_this) !== null;
  1456. });
  1457. protoOverride(Element, 'setAttribute', isStyleText, function(_this, args) {
  1458. protectedElems.set(_this, args[1]);
  1459. });
  1460. protoOverride(Element, 'getAttribute', isStyleText, function(_this) {
  1461. return protectedElems.get(_this);
  1462. });
  1463. if (eventMode) {
  1464. var e = document.createEvent('Event');
  1465. e.initEvent('protoOverride', false, false);
  1466. window.protectedElems = protectedElems;
  1467. window.dispatchEvent(e);
  1468. } else {
  1469. return protectedElems;
  1470. }
  1471. }
  1472. if (isFirefox) {
  1473. var s = document.createElement('script');
  1474. s.textContent = '(' + styleProtector.toString() + ')(true);';
  1475. window.addEventListener('protoOverride', function protoOverrideCallback(e){
  1476. if (win.protectedElems) {
  1477. protectedElems = win.protectedElems;
  1478. delete win.protectedElems;
  1479. }
  1480. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  1481. }, true);
  1482. _appendChild(s);
  1483. _removeChild(s);
  1484. } else {
  1485. protectedElems = styleProtector(false);
  1486. }
  1487.  
  1488. // clean a page
  1489. window.addEventListener('DOMContentLoaded', function(){
  1490. var rem, si, itm;
  1491. function width(){ return window.innerWidth||_de.clientWidth||document.body.clientWidth||0; }
  1492. function height(){ return window.innerHeight||_de.clientHeight||document.body.clientHeight||0; }
  1493.  
  1494.  
  1495. if (isForum) {
  1496. si = document.querySelector('#logostrip');
  1497. if (si) {
  1498. remove(si.parentNode.nextSibling);
  1499. }
  1500. }
  1501.  
  1502. if (document.location.href.search('/forum/dl/') !== -1) {
  1503. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  1504. ';background-color:black!important');
  1505. for (itm of document.querySelectorAll('body>div')) {
  1506. if (!itm.querySelector('.dw-fdwlink')) {
  1507. remove(itm);
  1508. }
  1509. }
  1510. }
  1511.  
  1512. if (isForum) { // Do not continue if it's a forum
  1513. return;
  1514. }
  1515.  
  1516. si = document.querySelector('#header');
  1517. if (si) {
  1518. rem = si.previousSibling;
  1519. while (rem) {
  1520. si = rem.previousSibling;
  1521. remove(rem);
  1522. rem = si;
  1523. }
  1524. }
  1525.  
  1526. for (itm of document.querySelectorAll('#nav li[class]')) {
  1527. if (itm && itm.querySelector('a[href^="/tag/"]')) {
  1528. remove(itm);
  1529. }
  1530. }
  1531.  
  1532. var style, result, fakeStyle,
  1533. fakeStyles = new WeakMap(),
  1534. styleProxy = {
  1535. get: function(target, prop) {
  1536. fakeStyle = fakeStyles.get(target);
  1537. if (fakeStyle.hasOwnProperty(prop)) {
  1538. return fakeStyle[prop];
  1539. } else {
  1540. return target[prop];
  1541. }
  1542. },
  1543. set: function(target, prop, value) {
  1544. fakeStyle = fakeStyles.get(target);
  1545. if (fakeStyle.hasOwnProperty(prop)) {
  1546. fakeStyle[prop] = value;
  1547. } else {
  1548. target[prop] = value;
  1549. }
  1550. return value;
  1551. }
  1552. };
  1553. for (itm of document.querySelectorAll('DIV, A')) {
  1554. if (itm.tagName ==='DIV' && itm.offsetWidth > 0.95 * width() && itm.offsetHeight > 0.85 * height()) {
  1555. style = window.getComputedStyle(itm, null);
  1556. result = [];
  1557. if (style.backgroundImage !== 'none') {
  1558. result.push('background-image:none!important');
  1559. }
  1560. if (style.backgroundColor !== 'transparent' &&
  1561. style.backgroundColor !== 'rgba(0, 0, 0, 0)') {
  1562. result.push('background-color:transparent!important');
  1563. }
  1564. if (result.length) {
  1565. if (itm.getAttribute('style')) {
  1566. result.unshift(itm.getAttribute('style'));
  1567. }
  1568. fakeStyles.set(itm.style, {
  1569. 'backgroundImage': itm.style.backgroundImage,
  1570. 'backgroundColor': itm.style.backgroundColor
  1571. });
  1572. try {
  1573. Object.defineProperty(itm, 'style', {
  1574. value: new Proxy(itm.style, styleProxy),
  1575. enumerable: true
  1576. });
  1577. } catch (e) {
  1578. console.log('Unable to protect style property.', e);
  1579. }
  1580. if (protectedElems) {
  1581. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  1582. }
  1583. _setAttribute.call(itm, 'style', result.join(';'));
  1584. }
  1585. }
  1586. if (itm.tagName ==='A' && (itm.offsetWidth > 0.95 * width() || itm.offsetHeight > 0.85 * height())) {
  1587. if (protectedElems) {
  1588. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  1589. }
  1590. _setAttribute.call(itm, 'style', 'display:none!important');
  1591. }
  1592. }
  1593.  
  1594. for (itm of document.querySelectorAll('ASIDE>DIV')) {
  1595. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  1596. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  1597. !itm.classList.contains('post') ) || !itm.childNodes.length ) {
  1598. remove(itm);
  1599. }
  1600. }
  1601.  
  1602. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  1603.  
  1604. // display content of the page
  1605. afterClean();
  1606. });
  1607. }
  1608. };
  1609.  
  1610. scripts['allmovie.pro'] = function() {
  1611. // pretend to be Android to make site use different played for ads
  1612. if (isSafari) {
  1613. return;
  1614. }
  1615. Object.defineProperty(navigator, 'userAgent', {
  1616. get: function(){ return 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19'; },
  1617. enumerable: true
  1618. });
  1619. };
  1620. scripts['rufilmtv.org'] = scripts['allmovie.pro'];
  1621.  
  1622. scripts['anidub-online.ru'] = function() {
  1623. var script = document.createElement('script');
  1624. script.type = "text/javascript";
  1625. script.innerHTML = "function ogonekstart1() {}";
  1626. document.getElementsByTagName('head')[0].appendChild(script);
  1627.  
  1628. var style = document.createElement('style');
  1629. style.type = 'text/css';
  1630. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  1631. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  1632. document.head.appendChild(style);
  1633. };
  1634. scripts['online.anidub.com'] = scripts['anidub-online.ru'];
  1635.  
  1636. scripts['fs.to'] = function() {
  1637. function skipClicker(i) {
  1638. if (!i) {
  1639. return;
  1640. }
  1641. var skip = document.querySelector('.b-aplayer-banners__close');
  1642. if (skip) {
  1643. skip.click();
  1644. } else {
  1645. setTimeout(skipClicker, 100, i-1);
  1646. }
  1647. }
  1648. setTimeout(skipClicker, 100, 30);
  1649.  
  1650. createStyle([
  1651. '.l-body-branding *,'+
  1652. '.b-styled__item-central,'+
  1653. '.b-styled__content-right,'+
  1654. '.b-styled__section-central,'+
  1655. 'div[id^="adsProxy-"]'+
  1656. '{display:none!important}',
  1657. 'body {background-image:url(data:image/png;base64,'+
  1658. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACX'+
  1659. 'BIWXMAAC4jAAAuIwF4pT92AAAADUlEQVR42mOQUdL5DwACMgFq'+
  1660. 'BC3ttwAAAABJRU5ErkJggg==)!important}'
  1661. ]);
  1662.  
  1663. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  1664. var p = document.querySelector('#player:not([preload="auto"])'),
  1665. m = document.querySelector('.main'),
  1666. adStepper = function(p) {
  1667. if (p.currentTime < p.duration) {
  1668. p.currentTime += 1;
  1669. }
  1670. },
  1671. adSkipper = function(f, p) {
  1672. f.click();
  1673. p.waitAfterSkip = false;
  1674. p.longerSkipper = false;
  1675. console.log('Пропустили.');
  1676. },
  1677. cl = function(p) {
  1678. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  1679. series = document.querySelector('.b-aplayer__actions-series');
  1680.  
  1681. function clickSelected() {
  1682. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  1683. if (s) {
  1684. s.click();
  1685. }
  1686. }
  1687.  
  1688. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  1689. series.click();
  1690. p.seriesClicked = true;
  1691. p.longerSkipper = true;
  1692. setTimeout(clickSelected, 1000);
  1693. p.pause();
  1694. }
  1695.  
  1696. function skipListener() {
  1697. if (p.waitAfterSkip) {
  1698. console.log('В процессе пропуска…');
  1699. return;
  1700. }
  1701. p.pause();
  1702. if (!p.classList.contains('m-hidden')) {
  1703. p.classList.add('m-hidden');
  1704. }
  1705. if (faster && p.currentTime &&
  1706. win.getComputedStyle(faster).display === 'block' &&
  1707. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  1708. p.waitAfterSkip = true;
  1709. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  1710. console.log('Доступен быстрый пропуск…');
  1711. } else {
  1712. setTimeout(adStepper, 1000, p);
  1713. }
  1714. }
  1715.  
  1716. p.addEventListener('timeupdate', skipListener, false);
  1717. };
  1718. if (p.nodeName === 'VIDEO') {
  1719. cl(p);
  1720. } else {
  1721. (new MutationObserver(function (ms) {
  1722. var m, node;
  1723. for (m of ms) {
  1724. for (node of m.addedNodes) {
  1725. if (node.id === 'player' &&
  1726. node.nodeName === 'VIDEO' &&
  1727. _getAttribute.call(node, 'preload') !== 'auto') {
  1728. cl(node);
  1729. }
  1730. }
  1731. }
  1732. })).observe(m, {childList: true});
  1733. }
  1734. }
  1735. };
  1736. scripts['brb.to'] = scripts['fs.to'];
  1737. scripts['cxz.to'] = scripts['fs.to'];
  1738.  
  1739. scripts['drive2.ru'] = function() {
  1740. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  1741. };
  1742.  
  1743. scripts['fishki.net'] = function() {
  1744. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров/);
  1745. };
  1746.  
  1747. scripts['gidonline.club'] = {
  1748. 'now': function() {
  1749. createStyle('.tray > div[style] {display: none!important}');
  1750. }
  1751. };
  1752. scripts['gidonlinekino.com'] = scripts['gidonline.club'];
  1753.  
  1754. scripts['hdgo.cc'] = {
  1755. 'now': function(){
  1756. (new MutationObserver(function(ms) {
  1757. var m, node;
  1758. for (m of ms) {
  1759. for (node of m.addedNodes) {
  1760. if (node.tagName === 'SCRIPT' && _getAttribute(node, 'onerror') !== null) {
  1761. node.removeAttribute('onerror');
  1762. }
  1763. }
  1764. }
  1765. })).observe(document, {childList:true, subtree: true});
  1766. }
  1767. };
  1768. scripts['couber.be'] = scripts['hdgo.cc'];
  1769. scripts['46.30.43.38'] = scripts['hdgo.cc'];
  1770.  
  1771. scripts['gismeteo.ru'] = {
  1772. 'DOMContentLoaded': function() {
  1773. gardener('div > a[target^="_"]', /Яндекс\.Директ/i, { root: 'body', observe: true, parent: 'div[class*="frame"]' });
  1774. }
  1775. };
  1776.  
  1777. scripts['hdrezka.me'] = {
  1778. 'now': function() {
  1779. Object.defineProperty(win, 'fuckAdBlock', {
  1780. value: {
  1781. onDetected: function() {
  1782. console.log('Pretending to be an ABP detector.');
  1783. }
  1784. }
  1785. });
  1786. Object.defineProperty(win, 'ab', {
  1787. value: false,
  1788. enumerable: true
  1789. });
  1790. },
  1791. 'DOMContentLoaded': function() {
  1792. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  1793. }
  1794. };
  1795.  
  1796. scripts['imageban.ru'] = {
  1797. 'now': preventBackgroundRedirect,
  1798. 'DOMContentLoaded': function() {
  1799. win.addEventListener('unload', function() {
  1800. if (!window.location.hash) {
  1801. window.location.replace(window.location+'#');
  1802. } else {
  1803. window.location.hash = '';
  1804. }
  1805. }, true);
  1806. }
  1807. };
  1808.  
  1809. scripts['e.mail.ru'] = function() {
  1810. /*gardener('#LEGO :not([data-mnemo])>.js-href[data-id]',
  1811. /data:image.*>Реклама<|>Реклама<.*\/\/favicon\./i,
  1812. {root:'#LEGO', observe: true, parent:'div[id][class]'});*/
  1813. };
  1814.  
  1815. scripts['mail.ru'] = {
  1816. 'now': function() {
  1817. // Trick to prevent mail.ru from removing 3rd-party styles
  1818. scriptLander(function(){
  1819. Object.defineProperty(Object.prototype, 'restoreVisibility', {
  1820. get: function() { return function(){}; },
  1821. set: function() {}
  1822. });
  1823. });
  1824. }
  1825. };
  1826.  
  1827. scripts['megogo.net'] = {
  1828. 'now': function() {
  1829. Object.defineProperty(win, "adBlock", {
  1830. value : false,
  1831. enumerable : true
  1832. });
  1833. Object.defineProperty(win, "showAdBlockMessage", {
  1834. value : function () {},
  1835. enumerable : true
  1836. });
  1837. }
  1838. };
  1839.  
  1840. scripts['naruto-base.su'] = function() {
  1841. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1842. };
  1843.  
  1844. scripts['overclockers.ru'] = {
  1845. 'now': function() {
  1846. createStyle('.fixoldhtml {display:block!important}');
  1847. if (!isChrome && !isOpera) {
  1848. return; // Looks like my code works only in Chrome-like browsers
  1849. }
  1850. var noContentYet = true;
  1851. function jWrap() {
  1852. var _$ = win.$, _e = _$.extend;
  1853. win.$ = function() {
  1854. var _ret = _$.apply(window, arguments);
  1855. if (_ret[0] === document.body) {
  1856. _ret.html = function() {
  1857. console.log('Anti-adblock prevented.');
  1858. };
  1859. }
  1860. return _ret;
  1861. };
  1862. win.$.extend = function() {
  1863. return _e.apply(_$, arguments);
  1864. };
  1865. win.jQuery = win.$;
  1866. }
  1867. (function jReady() {
  1868. if (!win.$ && noContentYet) {
  1869. setTimeout(jReady, 0);
  1870. } else {
  1871. jWrap();
  1872. }
  1873. })();
  1874. document.addEventListener ('DOMContentLoaded', function(){
  1875. noContentYet = false;
  1876. }, false);
  1877. }
  1878. };
  1879. scripts['forums.overclockers.ru'] = {
  1880. 'now': function() {
  1881. createStyle('.needblock {position: fixed; left: -10000px}');
  1882. Object.defineProperty(win, 'adblck', {
  1883. value: 'no',
  1884. enumerable: true
  1885. });
  1886. }
  1887. };
  1888.  
  1889. scripts['pb.wtf'] = function() {
  1890. createStyle('.reques,#result,tbody.row1:not([id]) {display: none !important}');
  1891. // image in the slider in the header
  1892. gardener('a[href^="/ex"],a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1893. // ads in blocks on the page
  1894. gardener('a[href^="/topic/234257"]', /Как\sразместить/i, {siblings:-1, root:'#main_content', observe:true, parent:'span[style]'});
  1895. // line above topic content
  1896. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1897. };
  1898. scripts['piratbit.org'] = scripts['pb.wtf'];
  1899. scripts['piratbit.ru'] = scripts['pb.wtf'];
  1900.  
  1901. scripts['pikabu.ru'] = function() {
  1902. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1903. };
  1904.  
  1905. scripts['rp5.ru'] = function() {
  1906. createStyle('#bannerBottom {display: none!important}');
  1907. var co = document.querySelector('#content'), i, nodes;
  1908. if (!co) {
  1909. return;
  1910. }
  1911. nodes = co.parentNode.childNodes;
  1912. i = nodes.length;
  1913. while (i--) {
  1914. if (nodes[i] !== co) {
  1915. nodes[i].parentNode.removeChild(nodes[i]);
  1916. }
  1917. }
  1918. };
  1919. scripts['rp5.by'] = scripts['rp5.ru'];
  1920. scripts['rp5.kz'] = scripts['rp5.ru'];
  1921. scripts['rp5.ua'] = scripts['rp5.ru'];
  1922.  
  1923. scripts['rustorka.com'] = {
  1924. 'now': function() {
  1925. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  1926. id: 'tempHidingStyles'
  1927. }, true);
  1928. preventPopups();
  1929. },
  1930. 'DOMContentLoaded': function() {
  1931. for (var o of document.querySelectorAll('IMG, A')) {
  1932. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  1933. (o.clientWidth === 300 && o.clientHeight === 250)) {
  1934. while (o && o.tagName !== 'A') {
  1935. o = o.parentNode;
  1936. }
  1937. if (o) {
  1938. _setAttribute.call(o, 'style', 'display: none !important');
  1939. }
  1940. }
  1941. }
  1942. var s = document.querySelector('#tempHidingStyles');
  1943. s.parentNode.removeChild(s);
  1944. }
  1945. };
  1946. scripts['rumedia.ws'] = scripts['rustorka.com'];
  1947.  
  1948. scripts['sport-express.ru'] = function() {
  1949. gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  1950. };
  1951.  
  1952. scripts['sports.ru'] = function() {
  1953. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  1954. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  1955. // extra functionality: shows/hides panel at the top depending on scroll direction
  1956. createStyle([
  1957. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  1958. '.user-panel-up { top: -40px!important }'
  1959. ], {id: 'userPanelSlide'}, false);
  1960. (function lookForPanel() {
  1961. var panel = document.querySelector('.user-panel__fixed');
  1962. if (!panel) {
  1963. setTimeout(lookForPanel, 100);
  1964. } else {
  1965. window.addEventListener('wheel', function(e){
  1966. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up')) {
  1967. panel.classList.add('user-panel-up');
  1968. } else
  1969. if (e.deltaY < 0 && panel.classList.contains('user-panel-up')) {
  1970. panel.classList.remove('user-panel-up');
  1971. }
  1972. }, false);
  1973. }
  1974. })();
  1975. };
  1976.  
  1977. scripts['www.ukr.net'] = scripts['sinoptik.com.ru'];
  1978.  
  1979. scripts['vk.com'] = function() {
  1980. gardener('div[data-post-id]', /wall_marked_as_ads/, {root: '#page_wall_posts', observe: true});
  1981. };
  1982.  
  1983. scripts['yap.ru'] = function() {
  1984. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  1985. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  1986. };
  1987. scripts['yaplakal.com'] = scripts['yap.ru'];
  1988.  
  1989. scripts['rambler.ru'] = {
  1990. 'now': function() {
  1991. scriptLander(function() {
  1992. var _createElement = Document.prototype.createElement,
  1993. loadMap = new WeakMap();
  1994. Document.prototype.createElement = function createElement(name) {
  1995. /*jshint validthis:true */
  1996. var el = _createElement.apply(this, arguments);
  1997. if (el.tagName === 'LINK') {
  1998. Object.defineProperty(el, 'onload', {
  1999. get: function() {
  2000. return loadMap.get(loadMap.get(this));
  2001. },
  2002. set: function(func) {
  2003. var wrap = loadMap.get(this),
  2004. isContent = /\{\s*content\s*:\s*"[^"]+"/i;
  2005. if (wrap) {
  2006. this.removeEventListener('load', wrap, false);
  2007. loadMap.remove(wrap);
  2008. loadMap.remove(this);
  2009. }
  2010. wrap = function(e) {
  2011. if (e.target && e.target.sheet && e.target.sheet.cssRules &&
  2012. e.target.sheet.cssRules[0] && e.target.sheet.cssRules[0].cssText &&
  2013. isContent.test(e.target.sheet.cssRules[0].cssText)) {
  2014. console.log('Blocked "onload" for', e.target.href);
  2015. return false;
  2016. }
  2017. return func.apply(this, arguments);
  2018. };
  2019. loadMap.set(this, wrap);
  2020. loadMap.set(wrap, func);
  2021. this.addEventListener('load', wrap, false);
  2022. },
  2023. enumberable: true
  2024. });
  2025. }
  2026. return el;
  2027. };
  2028. });
  2029. }
  2030. };
  2031.  
  2032. scripts['reactor.cc'] = {
  2033. 'now': function() {
  2034. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  2035. },
  2036. 'click': function(e) {
  2037. var node = e.target;
  2038. if (node.nodeType === Node.ELEMENT_NODE &&
  2039. node.style.position === 'absolute' &&
  2040. node.style.zIndex > 0)
  2041. node.parentNode.removeChild(node);
  2042. },
  2043. 'DOMContentLoaded': function() {
  2044. var words = new RegExp(
  2045. 'блокировщика рекламы'
  2046. .split('')
  2047. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  2048. .join('')
  2049. .replace(' ', '\\s*')
  2050. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  2051. 'i'),
  2052. can;
  2053. function deeper(spider) {
  2054. var c, l, n;
  2055. if (words.test(spider.innerText)) {
  2056. if (spider.nodeType === Node.TEXT_NODE) {
  2057. return true;
  2058. }
  2059. c = spider.childNodes;
  2060. l = c.length;
  2061. n = 0;
  2062. while(l--) {
  2063. if (deeper(c[l]), can) {
  2064. n++;
  2065. }
  2066. }
  2067. if (n > 0 && n === c.length && spider.offsetHeight < 750) {
  2068. can.push(spider);
  2069. }
  2070. return false;
  2071. }
  2072. return true;
  2073. }
  2074. function probe(){
  2075. if (words.test(document.body.innerText)) {
  2076. can = [];
  2077. deeper(document.body);
  2078. var i = can.length, spider;
  2079. while(i--) {
  2080. spider = can[i];
  2081. if (spider.offsetHeight > 10 && spider.offsetHeight < 750) {
  2082. _setAttribute.call(spider, 'style', 'background:none!important');
  2083. }
  2084. }
  2085. }
  2086. }
  2087. (new MutationObserver(probe)).observe(document,{childList:true, subtree:true});
  2088. }
  2089. };
  2090. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  2091. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  2092.  
  2093. scripts['auto.ru'] = function() {
  2094. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  2095. var userAdsListAds = [
  2096. '.listing-list > .listing-item',
  2097. '.listing-item_type_fixed.listing-item'
  2098. ];
  2099. var catalogAds = [
  2100. 'div[class*="layout_catalog-inline"]',
  2101. 'div[class$="layout_horizontal"]'
  2102. ];
  2103. var otherAds = [
  2104. '.advt_auto',
  2105. '.sidebar-block',
  2106. '.pager-listing + div[class]',
  2107. '.card > div[class][style]',
  2108. '.sidebar > div[class]',
  2109. '.main-page__section + div[class]',
  2110. '.listing > tbody'];
  2111. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  2112. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  2113. gardener(otherAds.join(','), words);
  2114. };
  2115.  
  2116. scripts['rsload.net'] = {
  2117. 'load': function() {
  2118. var dis = document.querySelector('label[class*="cb-disable"]');
  2119. if (dis) {
  2120. dis.click();
  2121. }
  2122. },
  2123. 'click': function(e) {
  2124. var t = e.target;
  2125. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  2126. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  2127. }
  2128. }
  2129. };
  2130.  
  2131. var domain = document.domain, name;
  2132. while (domain.indexOf('.') !== -1) {
  2133. if (scripts.hasOwnProperty(domain)) {
  2134. if (typeof scripts[domain] === 'function') {
  2135. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  2136. }
  2137. for (name in scripts[domain]) {
  2138. if (name !== 'now') {
  2139. (name === 'load' ? window : document)
  2140. .addEventListener (name, scripts[domain][name], false);
  2141. } else {
  2142. scripts[domain][name]();
  2143. }
  2144. }
  2145. }
  2146. domain = domain.slice(domain.indexOf('.') + 1);
  2147. }
  2148. })();