RU AdList JS Fixes

try to take over the world!

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

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