RU AdList JS Fixes

try to take over the world!

当前为 2017-04-10 提交的版本,查看 最新版本

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