RU AdList JS Fixes

try to take over the world!

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

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