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