RU AdList JS Fixes

try to take over the world!

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

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