RU AdList JS Fixes

try to take over the world!

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

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