RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20161010.2
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var win = (unsafeWindow || window);
  16.  
  17. // NodeList iterator polyfill (mostly for Safari)
  18. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  19. if (!NodeList.prototype[Symbol.iterator]) {
  20. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  21. }
  22.  
  23. // Creates and return protected style (unless protection is manually disabled).
  24. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  25. function createStyle(rules, props, skip_protect) {
  26. var root = document.head;
  27.  
  28. function _protect(style) {
  29. Object.defineProperty(style, 'sheet', {
  30. value: style.sheet,
  31. enumerable: true
  32. });
  33. Object.defineProperty(style, 'disabled', {
  34. get: function() {return true;}, //pretend to be disabled
  35. set: function() {},
  36. enumerable: true
  37. });
  38. }
  39.  
  40. function _create() {
  41. var style = root.appendChild(document.createElement('style')),
  42. prop, rule;
  43. style.type = 'text/css';
  44. for (prop in props) {
  45. if (style.hasOwnProperty(prop)) {
  46. style[prop] = props[prop];
  47. }
  48. }
  49. for (rule of rules) {
  50. try {
  51. style.sheet.insertRule(rule, 0);
  52. } catch (e) {
  53. console.error(e);
  54. }
  55. }
  56. if (!skip_protect) {
  57. _protect(style);
  58. }
  59. return style;
  60. }
  61.  
  62. var style = _create();
  63. if (skip_protect) {
  64. return style;
  65. }
  66.  
  67. var o = new MutationObserver(function(ms){
  68. var m, node, rule;
  69. for (m of ms) {
  70. for (node of m.removedNodes) {
  71. if (node === style) {
  72. style = _create();
  73. }
  74. }
  75. }
  76. });
  77. o.observe(root, {childList:true});
  78.  
  79. return style;
  80. }
  81.  
  82. // https://greasyfork.org/scripts/19144-websuckit/
  83. (function() {
  84. // check does browser support Proxy and WebSocket
  85. if (typeof Proxy !== 'function' ||
  86. typeof WebSocket !== 'function') {
  87. return;
  88. }
  89.  
  90. function getWrappedCode(removeSelf) {
  91. var text = getWrappedCode.toString()+WSI.toString();
  92. text = (
  93. '(function(){"use strict";'+
  94. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  95. '(new WSI(self||window)).init();'+
  96. '})();\n'+
  97. (removeSelf?'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')
  98. );
  99. return text;
  100. }
  101.  
  102. function WSI(win, safeWin) {
  103. safeWin = safeWin || win;
  104. var masks = [], filter;
  105. for (filter of [// blacklist
  106. '||24video.xxx^',
  107. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  108. '||bgrndi.com^', '||brokeloy.com^',
  109. '||cnamerutor.ru^',
  110. '||docfilms.info^', '||dreadfula.ru^',
  111. '||et-code.ru^',
  112. '||film-doma.ru^',
  113. '||free-torrent.org^', '||free-torrent.pw^',
  114. '||free-torrents.org^', '||free-torrents.pw^',
  115. '||game-torrent.info^', '||gocdn.ru^',
  116. '||hdkinoshka.com^', '||hghit.com^',
  117. '||kiev.ua^', '||kinotochka.net^',
  118. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  119. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^',
  120. '||mail.ru^', '||marketgid.com^', '||mxtads.com^',
  121. '||oconner.biz^',
  122. '||pkpojhc.com^',
  123. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  124. '||recreativ.ru^', '||regpole.com^', '||ruttwind.com^',
  125. '||skidl.ru^',
  126. '||torvind.com^', '||trafmag.com^',
  127. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  128. '||xxuhter.ru^',
  129. '||yuiout.online^',
  130. '||zoom-film.ru^'
  131. ]) {
  132. masks.push(new RegExp(
  133. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  134. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  135. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  136. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  137. 'i'));
  138. }
  139.  
  140. function isBlocked(url) {
  141. for (var mask of masks) {
  142. if (mask.test(url)) {
  143. return true;
  144. }
  145. }
  146. return false;
  147. }
  148.  
  149. var realWebSocket = win.WebSocket;
  150. function wsGetter (target, name) {
  151. try {
  152. if (typeof realWebSocket.prototype[name] === 'function') {
  153. if (name === 'close' || name === 'send') { // send also closes connection
  154. target.readyState = realWebSocket.CLOSED;
  155. }
  156. return (
  157. function fake() {
  158. console.log('[WSI] Invoked function "'+name+'"', '| Tracing', (new Error()));
  159. return;
  160. }
  161. );
  162. }
  163. if (typeof realWebSocket.prototype[name] === 'number') {
  164. return realWebSocket[name];
  165. }
  166. } catch(ignore) {}
  167. return target[name];
  168. }
  169.  
  170. function createWebSocketWrapper(target) {
  171. return new Proxy(realWebSocket, {
  172. construct: function (target, args) {
  173. var url = args[0];
  174. console.log('[WSI] Opening socket on ' + url + ' \u2026');
  175. if (isBlocked(url)) {
  176. console.log("[WSI] Blocked.");
  177. return new Proxy({
  178. url: url,
  179. readyState: realWebSocket.OPEN
  180. }, {
  181. get: wsGetter
  182. });
  183. }
  184. return new target(args[0], args[1]);
  185. }
  186. });
  187. }
  188.  
  189. function WorkerWrapper() {
  190. var realWorker = win.Worker;
  191. function wrappedWorker(resourceURI) {
  192. var isBlobURL = /^blob:/i,
  193. _callbacks = new WeakMap(),
  194. _worker = null,
  195. _terminate = false,
  196. _onerror = null,
  197. _onmessage = null,
  198. _messages = [],
  199. _events = [],
  200. _self = this;
  201.  
  202. function callbackWrapper(func) {
  203. if (typeof func !== 'function') {
  204. return undefined;
  205. }
  206. return (
  207. function callback() {
  208. func.apply(_self, arguments);
  209. }
  210. );
  211. }
  212.  
  213. (new Promise(function(resolve, reject){
  214. if (!isBlobURL.test(resourceURI)) {
  215. return resolve(new realWorker(resourceURI));
  216. }
  217.  
  218. var xhrLoadEnd = function() {
  219. resolve(new realWorker(URL.createObjectURL(
  220. new Blob([getWrappedCode(false)+this.result])
  221. )));
  222. };
  223. var xhr = new XMLHttpRequest();
  224. xhr.open('GET', resourceURI, true);
  225. xhr.responseType = 'blob';
  226. xhr.onload = function(){
  227. if (this.status === 200) {
  228. var reader = new FileReader();
  229. reader.addEventListener("loadend", xhrLoadEnd);
  230. reader.readAsText(this.response);
  231. }
  232. };
  233. xhr.send();
  234. })).then(function(val) {
  235. _worker = val;
  236. _worker.onerror = callbackWrapper(_onerror);
  237. _worker.onmessage = callbackWrapper(_onmessage);
  238. var _e;
  239. while(_events.length) {
  240. _e = _events.shift();
  241. _worker[_e[0]].apply(_worker, _e[1]);
  242. }
  243. while(_messages.length) {
  244. _worker.postMessage(_messages.shift());
  245. }
  246. if (_terminate) {
  247. _worker.terminate();
  248. }
  249. });
  250.  
  251. _self.terminate = function(){
  252. _terminate = true;
  253. if (_worker) {
  254. _worker.terminate();
  255. }
  256. };
  257. Object.defineProperty(_self, 'onmessage', {
  258. get: function() {
  259. return _onmessage;
  260. },
  261. set: function(val) {
  262. _onmessage = val;
  263. if (_worker) {
  264. _worker.onmessage = callbackWrapper(val);
  265. }
  266. }
  267. });
  268. Object.defineProperty(_self, 'onerror', {
  269. get: function() {
  270. return _onerror;
  271. },
  272. set: function(val) {
  273. _onerror = val;
  274. if (_worker) {
  275. _worker.onerror = callbackWrapper(val);
  276. }
  277. }
  278. });
  279. _self.postMessage = function(message){
  280. if (_worker) {
  281. _worker.postMessage(message);
  282. } else {
  283. _messages.push(message);
  284. }
  285. };
  286. _self.terminate = function() {
  287. _terminate = true;
  288. if (_worker) {
  289. _worker.terminate();
  290. }
  291. };
  292. _self.addEventListener = function(){
  293. if (typeof arguments[1] !== 'function') {
  294. return;
  295. }
  296. if (!_callbacks.has(arguments[1])) {
  297. _callbacks.set(arguments[1], callbackWrapper(arguments[1]));
  298. }
  299. arguments[1] = _callbacks.get(arguments[1]);
  300. if (_worker) {
  301. _worker.addEventListener.apply(_worker, arguments);
  302. } else {
  303. _events.push(['addEventListener', arguments]);
  304. }
  305. };
  306. _self.removeEventListener = function(){
  307. if (typeof arguments[1] !== 'function' || !_callbacks.has(arguments[1])) {
  308. return;
  309. }
  310. arguments[1] = _callbacks.get(arguments[1]);
  311. _callbacks.delete(arguments[1]);
  312. if (_worker) {
  313. _worker.removeEventListener.apply(_worker, arguments);
  314. } else {
  315. _events.push(['removeEventListener', arguments]);
  316. }
  317. };
  318. }
  319. win.Worker = wrappedWorker.bind(safeWin);
  320. }
  321.  
  322. function CreateElementWrapper() {
  323. var realCreateElement = document.createElement.bind(document),
  324. code = encodeURIComponent('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>\n'),
  325. isDataURL = /^data:/i,
  326. isBlobURL = /^blob:/i;
  327.  
  328. function frameRewrite(e) {
  329. var f = e.target,
  330. w = f.contentWindow;
  331. if (!f.src) {
  332. return; // nothing to do here if source is unknown
  333. }
  334. if (isDataURL.test(f.src) && f.src.indexOf(code) < 0) {
  335. f.src = f.src.replace(',',',' + code);
  336. }
  337. if (w && isBlobURL.test(f.src)) {
  338. w.WebSocket = createWebSocketWrapper();
  339. }
  340. }
  341.  
  342. function wrappedCreateElement(name) {
  343. if (name && name.toUpperCase &&
  344. name.toUpperCase() === 'IFRAME') {
  345. var ifr = realCreateElement.apply(document, arguments);
  346. ifr.addEventListener('load', frameRewrite, false);
  347. return ifr;
  348. }
  349. return realCreateElement.apply(document, arguments);
  350. }
  351. document.createElement = wrappedCreateElement.bind(document);
  352.  
  353. document.addEventListener('DOMContentLoaded', function(){
  354. for (var ifr of document.querySelectorAll('IFRAME')) {
  355. ifr.addEventListener('load', frameRewrite, false);
  356. // special case when content injected from script and iframe source
  357. // isn't specified (normal iframe with src should trigger 'load' later)
  358. try {
  359. if (!ifr.hasAttribute('src') && ifr.contentDocument.readyState === 'complete') {
  360. ifr.src = 'data:text/html;charset=utf-8,' + code +
  361. encodeURIComponent('<html>'+ifr.contentDocument.documentElement.innerHTML+'</html>');
  362. }
  363. } catch(ignore) {}
  364. }
  365. }, false);
  366. }
  367.  
  368. this.init = function() {
  369. win.WebSocket = createWebSocketWrapper();
  370. WorkerWrapper();
  371. if (typeof document !== 'undefined') {
  372. CreateElementWrapper();
  373. }
  374. };
  375. }
  376.  
  377. if (/firefox/i.test(navigator.userAgent)) {
  378. var script = document.createElement('script');
  379. script.appendChild(document.createTextNode(getWrappedCode()));
  380. document.head.insertBefore(script, document.head.firstChild);
  381. return; //we don't want to call functions on page from here in Fx, so exit
  382. }
  383.  
  384. (new WSI((unsafeWindow||self||window),(self||window))).init();
  385. })();
  386.  
  387. if (!(/firefox/i.test(navigator.userAgent))) { // scripts for non-Firefox browsers
  388.  
  389. // https://greasyfork.org/scripts/14720-it-s-not-important
  390. (function(){
  391. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  392.  
  393. function unimportanter(el, si) {
  394. if (!imptt.test(si) || el.style.display === 'none') {
  395. return 0; // get out if we have nothing to do here
  396. }
  397. if (el.nodeName === 'IFRAME' && el.src &&
  398. el.src.slice(0,17) === 'chrome-extension:') {
  399. return 0; // Web of Trust uses this method to add their frame
  400. }
  401. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  402. if (si !== so) {
  403. ret = 1;
  404. el.setAttribute('style', so);
  405. }
  406. return ret;
  407. }
  408.  
  409. function logger(c) {
  410. if (c) {
  411. console.log('Some page elements became a bit less important.');
  412. }
  413. }
  414.  
  415. function checkTarget(node, cnt) {
  416. if (!(node && node.getAttribute)) {
  417. return 0;
  418. }
  419. var si = node.getAttribute('style');
  420. if (si && si.indexOf('!') > -1) {
  421. cnt += unimportanter(node, si);
  422. }
  423. return cnt;
  424. }
  425.  
  426. var observer = new MutationObserver(function(mutations) {
  427. setTimeout(function(ms) {
  428. var cnt = 0, m, node;
  429. for (m of ms) {
  430. cnt = checkTarget(m.target, cnt);
  431. for (node of m.addedNodes) {
  432. cnt += checkTarget(node, cnt);
  433. }
  434. }
  435. logger(cnt);
  436. }, 0, mutations);
  437. });
  438.  
  439. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  440.  
  441. win.addEventListener ("load", function(){
  442. var c = 0, imp;
  443. for (imp of document.querySelectorAll('[style*="!"]')) {
  444. c+= checkTarget(imp, c);
  445. }
  446. logger(c);
  447. }, false);
  448. })();
  449.  
  450. }
  451.  
  452. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  453. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  454. (function(){
  455. var adWords = ['Яндекс.Директ','Реклама','Ad'];
  456. function remove(node) {
  457. node.parentNode.removeChild(node);
  458. }
  459. // Generic ads removal and fixes
  460. function removeGenericAds() {
  461. var s, i;
  462. s = document.querySelector('.serp-header');
  463. if (s) {
  464. s.style.marginTop='0';
  465. }
  466. for (s of document.querySelectorAll('.serp-adv__head + .serp-item, #adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]')) {
  467. remove(s);
  468. }
  469. }
  470. // Search ads
  471. function removeSearchAds() {
  472. var s, item;
  473. for (s of document.querySelectorAll('.serp-block, .serp-item, .search-item')) {
  474. item = s.querySelector('.label, .serp-item__label, .document__provider-name');
  475. if (item && adWords.indexOf(item.textContent) > -1) {
  476. remove(s);
  477. console.log('Ads removed.');
  478. }
  479. }
  480. }
  481. // News ads
  482. function removeNewsAds() {
  483. var s;
  484. for (s of document.querySelectorAll('.page-content__left > *,.page-content__right > *:not(.page-content__col),.page-content__right > .page-content__col > *')) {
  485. if (s.textContent.indexOf(adWords[0]) > -1) {
  486. remove(s);
  487. console.log('Ads removed.');
  488. }
  489. }
  490. }
  491. // News fixes
  492. function removePageAdsClass() {
  493. if (document.body.classList.contains("b-page_ads_yes")){
  494. document.body.classList.remove("b-page_ads_yes");
  495. console.log('Page ads class removed.');
  496. }
  497. }
  498. // Function to attach an observer to monitor dynamic changes on the page
  499. function pageUpdateObserver(func, obj, params) {
  500. if (obj) {
  501. var o = new MutationObserver(func);
  502. o.observe(obj,(params || {childList:true, subtree:true}));
  503. }
  504. }
  505. // Cleaner
  506. document.addEventListener ('DOMContentLoaded', function() {
  507. removeGenericAds();
  508. if (win.location.hostname.search(/^news\./i) === 0) {
  509. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  510. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  511. removeNewsAds();
  512. removePageAdsClass();
  513. } else {
  514. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  515. removeSearchAds();
  516. }
  517. });
  518. })();
  519. return; //skip fixes for other sites
  520. }
  521.  
  522. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  523. if (/(^|\.)4pda\.ru$/i.test(window.location.hostname)) {
  524. (function() {
  525. var isForum = document.location.href.search('/forum/') !== -1,
  526. hStyle;
  527.  
  528. function remove(n) {
  529. if (n) {
  530. n.parentNode.removeChild(n);
  531. }
  532. }
  533.  
  534. function afterClean() {
  535. hStyle.disabled = true;
  536. remove(hStyle);
  537. }
  538.  
  539. function beforeClean() {
  540. // attach styles before document displayed
  541. hStyle = createStyle([
  542. 'html { overflow-y: scroll }',
  543. 'article + aside * { display: none !important }',
  544. '#header + div:after {'+(
  545. 'content: "";'+
  546. 'position: fixed;'+
  547. 'top: 0;'+
  548. 'left: 0;'+
  549. 'width: 100%;'+
  550. 'height: 100%;'+
  551. 'background-color: #E6E7E9'
  552. )+'}',
  553. // http://codepen.io/Beaugust/pen/DByiE
  554. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  555. 'article + aside:after {'+(
  556. 'content: "";'+
  557. 'position: absolute;'+
  558. 'width: 150px;'+
  559. 'height: 150px;'+
  560. 'top: 150px;'+
  561. 'left: 50%;'+
  562. 'margin-top: -75px;'+
  563. 'margin-left: -75px;'+
  564. 'box-sizing: border-box;'+
  565. 'border-radius: 100%;'+
  566. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  567. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  568. 'animation: spin 2s infinite linear'
  569. )+'}'
  570. ], {id:'ubrHider'}, true);
  571.  
  572. // display content of a page if time to load a page is more than 2 seconds to avoid
  573. // blocking access to a page if it is loading for too long or stuck in a loading state
  574. setTimeout(2000, afterClean);
  575. }
  576.  
  577. createStyle([
  578. '#nav .use-ad { display: block !important }',
  579. 'article:not(.post) + article:not(#id), a[target="_blank"] img[height="90"] { display: none !important }'
  580. ]);
  581.  
  582. if (!isForum) {
  583. beforeClean();
  584. }
  585.  
  586. // clean a page
  587. window.addEventListener('DOMContentLoaded', function(){
  588. var rem, si, itm;
  589. function width(){ return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0; }
  590. function height(){ return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0; }
  591.  
  592.  
  593. if (isForum) {
  594. si = document.querySelector('#logostrip');
  595. if (si) {
  596. remove(si.parentNode.nextSibling);
  597. }
  598. }
  599.  
  600. if (document.location.href.search('/forum/dl/') !== -1) {
  601. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  602. ';background-color:black!important');
  603. for (itm of document.querySelectorAll('body>div')) {
  604. if (!itm.querySelector('.dw-fdwlink')) {
  605. remove(itm);
  606. }
  607. }
  608. }
  609.  
  610. if (isForum) { // Do not continue if it's a forum
  611. return;
  612. }
  613.  
  614. si = document.querySelector('#header');
  615. if (si) {
  616. rem = si.previousSibling;
  617. while (rem) {
  618. si = rem.previousSibling;
  619. remove(rem);
  620. rem = si;
  621. }
  622. }
  623.  
  624. for (itm of document.querySelectorAll('#nav li[class]')) {
  625. if (itm && itm.querySelector('a[href^="/tag/"]')) {
  626. remove(itm);
  627. }
  628. }
  629.  
  630. var style, result;
  631. for (itm of document.querySelectorAll('DIV')) {
  632. if (itm.offsetWidth > 0.95 * width() && itm.offsetHeight > 0.9 * height()) {
  633. style = window.getComputedStyle(itm, null);
  634. result = [];
  635. if(style.backgroundImage !== 'none') {
  636. result.push('background-image:none!important');
  637. }
  638. if(style.backgroundColor !== 'transparent') {
  639. result.push('background-color:transparent!important');
  640. }
  641. if (result.length) {
  642. if (itm.getAttribute('style')) {
  643. result.unshift(itm.getAttribute('style'));
  644. }
  645. itm.setAttribute('style', result.join(';'));
  646. }
  647. }
  648. }
  649.  
  650. for (itm of document.querySelectorAll('ASIDE>DIV')) {
  651. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  652. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  653. !itm.classList.contains('post') ) || !itm.childNodes.length ) {
  654. remove(itm);
  655. }
  656. }
  657.  
  658. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  659.  
  660. // display content of the page
  661. afterClean();
  662. });
  663. })();
  664. return;
  665. }
  666.  
  667. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.7 (adapted)
  668. document.addEventListener ('DOMContentLoaded', function() {
  669. var tmp;
  670. function log (e) {
  671. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  672. }
  673. if (win.adv_enabled !== undefined && win.condition_detected !== undefined) { // moonwalk
  674. log('Moonwalk');
  675. win.adv_enabled = false;
  676. win.condition_detected = false;
  677. } else if (win.banner_second !== undefined && win.$banner_ads !== undefined) { // hdgo
  678. log('HDGo');
  679. tmp = document.querySelector('#swtf');
  680. if (tmp) {
  681. tmp.style.display = 'none';
  682. }
  683. win.banner_second = 0;
  684. win.$banner_ads = false;
  685. if (win.$new_ads !== undefined) {
  686. win.$new_ads = false;
  687. }
  688. if (win.canRunAds !== undefined && win.canRunAds !== true) {
  689. win.canRunAds = true;
  690. }
  691. } else if (win.MXoverrollCallback !== undefined && win.iframeSearch !== undefined) { // kodik
  692. log('Kodik');
  693. tmp = document.querySelector('.play_button');
  694. if (tmp) {
  695. tmp.onclick = win.MXoverrollCallback.bind(window);
  696. }
  697. win.IsAdBlock = false;
  698. }
  699. }, false);
  700.  
  701. // function to search and remove nodes by content
  702. // selector - standard CSS selector to define set of nodes to check
  703. // words - regular expression to check content of the suspicious nodes
  704. // params - object with multiple extra parameters:
  705. // .hide - set display to none instead of removing from the page
  706. // .parent - parent node to remove if content is found in the child node
  707. // .siblings - number of simling nodes to remove (excluding text nodes)
  708. function scRemove(e) {e.parentNode.removeChild(e);}
  709. function scHide(e) {
  710. var s = e.getAttribute('style')||'',
  711. h = ';display:none!important;';
  712. if (s.indexOf(h) < 0) {
  713. e.setAttribute('style', s+h);
  714. }
  715. }
  716. function scissors (selector, words, scope, params) {
  717. var remFunc = (params.hide ? scHide : scRemove),
  718. iterFunc = (params.siblings > 0 ?
  719. 'nextSibling' :
  720. 'previousSibling'),
  721. toRemove = [],
  722. siblings,
  723. node;
  724. for (node of scope.querySelectorAll(selector)) {
  725. if (words.test(node.innerHTML) || !node.childNodes.length) {
  726. // drill up to the specified parent node if required
  727. if (params.parent) {
  728. while(node !== scope && !(node.matches(params.parent))) {
  729. node = node.parentNode;
  730. }
  731. }
  732. if (node === scope) {
  733. break;
  734. }
  735. toRemove.push(node);
  736. // add multiple nodes if defined more than one sibling
  737. siblings = Math.abs(params.siblings) || 0;
  738. while (siblings) {
  739. node = node[iterFunc];
  740. toRemove.push(node);
  741. if (node.nodeType === 1) {
  742. siblings -= 1; //count only element nodes
  743. }
  744. }
  745. }
  746. }
  747. for (node of toRemove) {
  748. remFunc(node);
  749. }
  750. return toRemove.length;
  751. }
  752.  
  753. // function to perform multiple checks if ads inserted with a delay
  754. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  755. // also does 1 extra check when a page completely loads
  756. // selector and words - passed dow to scissors
  757. // params - object with multiple extra parameters:
  758. // .root - selector to narrow down scope to scan;
  759. // .observe - if true then check will be performed continuously;
  760. // Other parameters passed down to scissors.
  761. function gardener(selector, words, params) {
  762. params = params || {};
  763. var scope = document.body,
  764. nonstop = false;
  765. // narrow down scope to a specific element
  766. if (params.root) {
  767. scope = scope.querySelector(params.root);
  768. if (!scope) {// exit if the root element is not present on the page
  769. return 0;
  770. }
  771. }
  772. // add observe mode if required
  773. if (params.observe) {
  774. if (typeof MutationObserver === 'function') {
  775. var o = new MutationObserver(function(ms){
  776. for (var m of ms) {
  777. if (m.addedNodes.length) {
  778. scissors(selector, words, scope, params);
  779. }
  780. }
  781. });
  782. o.observe(scope, {childList:true, subtree: true});
  783. } else {
  784. nonstop = true;
  785. }
  786. }
  787. // wait for a full page load to do one extra cut
  788. win.addEventListener('load',function(){
  789. scissors(selector, words, scope, params);
  790. });
  791. // do multiple cuts until ads removed
  792. function cut(sci, s, w, sc, p, i) {
  793. if (i > 0) {
  794. i -= 1;
  795. }
  796. if (i && !sci(s, w, sc, p)) {
  797. setTimeout(cut, 100, sci, s, w, sc, p, i);
  798. }
  799. }
  800. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  801. }
  802.  
  803. function preventBackgroundRedirect() {
  804. // create "cose_me" event to call high-level window.close()
  805. var key = Math.random().toString(36).substr(2);
  806. window.addEventListener('close_me_'+key, function(e) {
  807. window.close();
  808. });
  809.  
  810. // window.open wrapper
  811. function pbrLander() {
  812. var orgOpen = window.open.bind(window);
  813. function closeWindow(){
  814. // site went to a new tab and attempts to unload
  815. // call for high-level close through event
  816. var event = new CustomEvent("close_me_%key%", {});
  817. window.dispatchEvent(event);
  818. }
  819. function open(){
  820. var idx = String.prototype.indexOf;
  821. if (arguments[0] &&
  822. (idx.call(arguments[0], window.location.host) > -1 ||
  823. idx.call(arguments[0], '://') === -1)) {
  824. window.addEventListener('unload', closeWindow, true);
  825. }
  826. orgOpen.apply(window, arguments);
  827. }
  828. window.open = open.bind(window);
  829. var s = document.currentScript;
  830. if (s) {s.parentNode.removeChild(s);}
  831. }
  832.  
  833. // land wrapper on the page
  834. var script = document.createElement('script');
  835. script.appendChild(document.createTextNode('('+pbrLander.toString().replace(/%key%/g,key)+')();'));
  836. document.head.insertBefore(script,document.head.firstChild);
  837. console.log("Background redirect prevention enabled.");
  838. }
  839.  
  840. function forbidServiceWorker() {
  841. if (!("serviceWorker" in navigator)) {
  842. return;
  843. }
  844. var svr = navigator.serviceWorker.ready;
  845. Object.defineProperty(navigator, 'serviceWorker', {
  846. value: {
  847. register: function(){
  848. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  849. return new Promise(function(){});
  850. },
  851. ready: new Promise(function(){}),
  852. addEventListener:function(){}
  853. }
  854. });
  855. document.addEventListener('DOMContentLoaded', function() {
  856. if (!svr) {
  857. return;
  858. }
  859. svr.then(function(sw) {
  860. console.log('Found existing serviceWorker:', sw);
  861. console.log('Attempting to unregister...');
  862. sw.unregister().then(function() {
  863. console.log('Unregistered! :)');
  864. }).catch(function(err) {
  865. console.log('Unregistration failed. :(', err);
  866. console.log('Try to remove it manually:');
  867. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  868. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  869. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  870. });
  871. }).catch(function(err) {
  872. console.log("Lol, it failed on it's own. -_-", err);
  873. });
  874. }, false);
  875. }
  876.  
  877. var scripts = {};
  878. scripts['fs.to'] = function() {
  879. function skipClicker(i) {
  880. if (!i) {
  881. return;
  882. }
  883. var skip = document.querySelector('.b-aplayer-banners__close');
  884. if (skip) {
  885. skip.click();
  886. } else {
  887. setTimeout(skipClicker, 100, i-1);
  888. }
  889. }
  890. setTimeout(skipClicker, 100, 30);
  891.  
  892. createStyle([
  893. '.l-body-branding *,'+
  894. '.b-styled__item-central,'+
  895. '.b-styled__content-right,'+
  896. '.b-styled__section-central,'+
  897. 'div[id^="adsProxy-"]'+
  898. '{display:none!important}',
  899. 'body {background-image:url(data:image/png;base64,'+
  900. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACX'+
  901. 'BIWXMAAC4jAAAuIwF4pT92AAAADUlEQVR42mOQUdL5DwACMgFq'+
  902. 'BC3ttwAAAABJRU5ErkJggg==)!important}'
  903. ]);
  904.  
  905. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  906. var p = document.querySelector('#player:not([preload="auto"])'),
  907. m = document.querySelector('.main'),
  908. adStepper = function(p) {
  909. if (p.currentTime < p.duration) {
  910. p.currentTime += 1;
  911. }
  912. },
  913. adSkipper = function(f, p) {
  914. f.click();
  915. p.waitAfterSkip = false;
  916. p.longerSkipper = false;
  917. console.log('Пропустили.');
  918. },
  919. cl = function(p) {
  920. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  921. series = document.querySelector('.b-aplayer__actions-series');
  922.  
  923. function clickSelected() {
  924. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  925. if (s) {
  926. s.click();
  927. }
  928. }
  929.  
  930. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  931. series.click();
  932. p.seriesClicked = true;
  933. p.longerSkipper = true;
  934. setTimeout(clickSelected, 1000);
  935. p.pause();
  936. }
  937.  
  938. function skipListener() {
  939. if (p.waitAfterSkip) {
  940. console.log('В процессе пропуска…');
  941. return;
  942. }
  943. p.pause();
  944. if (!p.classList.contains('m-hidden')) {
  945. p.classList.add('m-hidden');
  946. }
  947. if (faster && p.currentTime &&
  948. win.getComputedStyle(faster).display === 'block' &&
  949. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  950. p.waitAfterSkip = true;
  951. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  952. console.log('Доступен быстрый пропуск…');
  953. } else {
  954. setTimeout(adStepper, 1000, p);
  955. }
  956. }
  957.  
  958. p.addEventListener('timeupdate', skipListener, false);
  959. },
  960. o = new MutationObserver(function (ms) {
  961. var m, node;
  962. for (m of ms) {
  963. for (node of m.addedNodes) {
  964. if (node.id === 'player' &&
  965. node.nodeName === 'VIDEO' &&
  966. node.getAttribute('preload') !== 'auto') {
  967. cl(node);
  968. }
  969. }
  970. }
  971. });
  972. if (p.nodeName === 'VIDEO') {
  973. cl(p);
  974. } else {
  975. o.observe(m, {childList: true});
  976. }
  977. }
  978. };
  979. scripts['brb.to'] = scripts['fs.to'];
  980. scripts['cxz.to'] = scripts['fs.to'];
  981.  
  982. scripts['drive2.ru'] = function() {
  983. gardener('.c-block', />Реклама<\/(?!.*?c-post-card)/i);
  984. };
  985.  
  986. scripts['fishki.net'] = function() {
  987. gardener('.main-post', /543769|Реклама/);
  988. };
  989.  
  990. scripts['hdgo.cc'] = {
  991. 'now': function(){
  992. var o = new MutationObserver(function(ms) {
  993. var m, node;
  994. for (m of ms) {
  995. for (node of m.addedNodes) {
  996. if (node.tagName === 'SCRIPT' && node.getAttribute('onerror') !== null) {
  997. node.removeAttribute('onerror');
  998. }
  999. }
  1000. }
  1001. });
  1002. o.observe(document, {childList:true, subtree: true});
  1003. }
  1004. };
  1005. scripts['couber.be'] = scripts['hdgo.cc'];
  1006. scripts['46.30.43.38'] = scripts['hdgo.cc'];
  1007.  
  1008. scripts['hdrezka.me'] = {
  1009. 'now': function() {
  1010. Object.defineProperty(win, 'fuckAdBlock', {
  1011. value: {
  1012. onDetected: function() {
  1013. console.log('Pretending to be an ABP detector.');
  1014. }
  1015. }
  1016. });
  1017. Object.defineProperty(win, 'ab', { value: false });
  1018. },
  1019. 'DOMContentLoaded': function() {
  1020. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  1021. }
  1022. };
  1023.  
  1024. scripts['naruto-base.su'] = function() {
  1025. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1026. };
  1027.  
  1028. scripts['forums.overclockers.ru'] = {
  1029. 'now': function() {
  1030. createStyle(['.needblock {position: fixed; left: -10000px}']);
  1031. }
  1032. };
  1033.  
  1034. scripts['pb.wtf'] = function() {
  1035. createStyle(['.reques,#result,tbody.row1:not([id]) {display: none !important}']);
  1036. // image in the slider in the header
  1037. gardener('a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1038. // ads in blocks on the page
  1039. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  1040. // line above topic content
  1041. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1042. };
  1043. scripts['piratbit.org'] = scripts['pb.wtf'];
  1044. scripts['piratbit.ru'] = scripts['pb.wtf'];
  1045.  
  1046. scripts['pikabu.ru'] = function() {
  1047. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1048. };
  1049.  
  1050. scripts['rp5.ru'] = function() {
  1051. var co = document.querySelector('#content'), i, nodes;
  1052. if (!co) {
  1053. return;
  1054. }
  1055. nodes = co.parentNode.childNodes;
  1056. i = nodes.length;
  1057. while (i--) {
  1058. if (nodes[i] !== co) {
  1059. nodes[i].parentNode.removeChild(nodes[i]);
  1060. }
  1061. }
  1062. };
  1063.  
  1064. scripts['rustorka.com'] = function() {
  1065. var s = document.head.childNodes, node;
  1066. if (s.length < 5) {
  1067. for (node of s) {
  1068. if (node.httpEquiv === 'refresh') {
  1069. window.close();
  1070. }
  1071. }
  1072. }
  1073. gardener('span[class],ul[class],span[id],ul[id]', /\/\d{12,}\.php/i, {root:'#sidebar1', observe:true});
  1074. gardener('div[id][style*="!important"]', /!important/i);
  1075. };
  1076. scripts['rumedia.ws'] = scripts['rustorka.com'];
  1077.  
  1078. scripts['sports.ru'] = function() {
  1079. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  1080. };
  1081.  
  1082. scripts['turbobit.net'] = {'now': preventBackgroundRedirect};
  1083.  
  1084. scripts['yap.ru'] = function() {
  1085. var words = /member1438|Administration/;
  1086. gardener('form > table[id^="p_row_"]', words);
  1087. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  1088. };
  1089. scripts['yaplakal.com'] = scripts['yap.ru'];
  1090.  
  1091. scripts['reactor.cc'] = {
  1092. 'now': function() {
  1093. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  1094. },
  1095. 'click': function(e) {
  1096. var node = e.target;
  1097. if (node.nodeType === Node.ELEMENT_NODE &&
  1098. node.style.position === 'absolute' &&
  1099. node.style.zIndex > 0)
  1100. node.parentNode.removeChild(node);
  1101. },
  1102. 'DOMContentLoaded': function() {
  1103. var words = new RegExp(
  1104. 'блокировщика рекламы'
  1105. .split('')
  1106. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  1107. .join('')
  1108. .replace(' ', '\\s*')
  1109. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  1110. 'i'),
  1111. can;
  1112. function deeper(spider) {
  1113. var c, l, n;
  1114. if (words.test(spider.innerText)) {
  1115. if (spider.nodeType === Node.TEXT_NODE) {
  1116. return true;
  1117. }
  1118. c = spider.childNodes;
  1119. l = c.length;
  1120. n = 0;
  1121. while(l--) {
  1122. if (deeper(c[l]), can) {
  1123. n++;
  1124. }
  1125. }
  1126. if (n > 0 && n === c.length && spider.offsetHeight < 750) {
  1127. can.push(spider);
  1128. }
  1129. return false;
  1130. }
  1131. return true;
  1132. }
  1133. function probe(){
  1134. if (words.test(document.body.innerText)) {
  1135. can = [];
  1136. deeper(document.body);
  1137. var i = can.length, j, spider;
  1138. while(i--) {
  1139. spider = can[i];
  1140. if (spider.offsetHeight > 10 && spider.offsetHeight < 750) {
  1141. spider.setAttribute('style', 'background:none!important');
  1142. }
  1143. }
  1144. }
  1145. }
  1146. var o = new MutationObserver(probe);
  1147. o.observe(document,{childList:true, subtree:true});
  1148. }
  1149. };
  1150. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  1151. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  1152.  
  1153. scripts['auto.ru'] = function() {
  1154. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  1155. var userAdsListAds = [
  1156. '.listing-list > .listing-item',
  1157. '.listing-item_type_fixed.listing-item'
  1158. ];
  1159. var catalogAds = [
  1160. 'div[class*="layout_catalog-inline"]',
  1161. 'div[class$="layout_horizontal"]'
  1162. ];
  1163. var otherAds = [
  1164. '.advt_auto',
  1165. '.sidebar-block',
  1166. '.pager-listing + div[class]',
  1167. '.card > div[class][style]',
  1168. '.sidebar > div[class]',
  1169. '.main-page__section + div[class]',
  1170. '.listing > tbody'];
  1171. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  1172. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  1173. gardener(otherAds.join(','), words);
  1174. };
  1175.  
  1176. scripts['online.anidub.com'] = function() {
  1177. var script = document.createElement('script');
  1178. script.type = "text/javascript";
  1179. script.innerHTML = "function ogonekstart1() {}";
  1180. document.getElementsByTagName('head')[0].appendChild(script);
  1181.  
  1182. var style = document.createElement('style');
  1183. style.type = 'text/css';
  1184. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  1185. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  1186. document.head.appendChild(style);
  1187. };
  1188.  
  1189. scripts['rsload.net'] = {
  1190. 'load': function() {
  1191. var dis = document.querySelector('.cb-disable');
  1192. if (dis) {
  1193. dis.click();
  1194. }
  1195. },
  1196. 'click': function(e) {
  1197. var t = e.target;
  1198. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  1199. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  1200. }
  1201. }
  1202. };
  1203.  
  1204. scripts['imageban.ru'] = {
  1205. 'now': preventBackgroundRedirect,
  1206. 'DOMContentLoaded': function() {
  1207. win.addEventListener('unload', function() {
  1208. if (!window.location.hash) {
  1209. window.location.replace(window.location+'#');
  1210. } else {
  1211. window.location.hash = '';
  1212. }
  1213. }, true);
  1214. }
  1215. };
  1216.  
  1217. var domain = document.domain, name;
  1218. while (domain.indexOf('.') !== -1) {
  1219. if (scripts.hasOwnProperty(domain)) {
  1220. if (typeof scripts[domain] === 'function') {
  1221. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  1222. }
  1223. for (name in scripts[domain]) {
  1224. if (name !== 'now') {
  1225. (name === 'load' ? window : document)
  1226. .addEventListener (name, scripts[domain][name], false);
  1227. } else {
  1228. scripts[domain][name]();
  1229. }
  1230. }
  1231. }
  1232. domain = domain.slice(domain.indexOf('.') + 1);
  1233. }
  1234. })();