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:0
  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 && isDataURL.test(f.src) && f.src.indexOf(code) < 0) {
  319. f.src = f.src.replace(',',',' + code);
  320. }
  321. if (f.src && isBlobURL.test(f.src) && w && w.WebSocket) {
  322. w.WebSocket = createWebSocketWrapper();
  323. }
  324. }
  325.  
  326. function wrappedCreateElement(name) {
  327. if (name && name.toUpperCase &&
  328. name.toUpperCase() === 'IFRAME') {
  329. var ifr = realCreateElement.apply(document, arguments);
  330. ifr.addEventListener('load', frameRewrite, false);
  331. return ifr;
  332. }
  333. return realCreateElement.apply(document, arguments);
  334. }
  335. document.createElement = wrappedCreateElement.bind(document);
  336.  
  337. document.addEventListener('DOMContentLoaded', function(){
  338. for (var ifr of document.querySelectorAll('IFRAME')) {
  339. ifr.addEventListener('load', frameRewrite, false);
  340. }
  341. }, false);
  342. }
  343.  
  344. this.init = function() {
  345. win.WebSocket = createWebSocketWrapper();
  346. WorkerWrapper();
  347. if (typeof document !== 'undefined') {
  348. CreateElementWrapper();
  349. }
  350. };
  351. }
  352.  
  353. if (/firefox/i.test(navigator.userAgent)) {
  354. var script = document.createElement('script');
  355. script.appendChild(document.createTextNode(getWrappedCode()));
  356. document.head.insertBefore(script, document.head.firstChild);
  357. return; //we don't want to call functions on page from here in Fx, so exit
  358. }
  359.  
  360. (new WSI((unsafeWindow||self||window),(self||window))).init();
  361. })();
  362.  
  363. if (!(/firefox/i.test(navigator.userAgent))) { // scripts for non-Firefox browsers
  364.  
  365. // https://greasyfork.org/scripts/14720-it-s-not-important
  366. (function(){
  367. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  368.  
  369. function unimportanter(el, si) {
  370. if (!imptt.test(si) || el.style.display === 'none') {
  371. return 0; // get out if we have nothing to do here
  372. }
  373. if (el.nodeName === 'IFRAME' && el.src &&
  374. el.src.slice(0,17) === 'chrome-extension:') {
  375. return 0; // Web of Trust uses this method to add their frame
  376. }
  377. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  378. if (si !== so) {
  379. ret = 1;
  380. el.setAttribute('style', so);
  381. }
  382. return ret;
  383. }
  384.  
  385. function logger(c) {
  386. if (c) {
  387. console.log('Some page elements became a bit less important.');
  388. }
  389. }
  390.  
  391. function checkTarget(node, cnt) {
  392. if (!(node && node.getAttribute)) {
  393. return 0;
  394. }
  395. var si = node.getAttribute('style');
  396. if (si && si.indexOf('!') > -1) {
  397. cnt += unimportanter(node, si);
  398. }
  399. return cnt;
  400. }
  401.  
  402. var observer = new MutationObserver(function(mutations) {
  403. setTimeout(function(ms) {
  404. var cnt = 0, m, node;
  405. for (m of ms) {
  406. cnt = checkTarget(m.target, cnt);
  407. for (node of m.addedNodes) {
  408. cnt += checkTarget(node, cnt);
  409. }
  410. }
  411. logger(cnt);
  412. }, 0, mutations);
  413. });
  414.  
  415. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  416.  
  417. win.addEventListener ("load", function(){
  418. var c = 0, imp;
  419. for (imp of document.querySelectorAll('[style*="!"]')) {
  420. c+= checkTarget(imp, c);
  421. }
  422. logger(c);
  423. }, false);
  424. })();
  425.  
  426. }
  427.  
  428. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  429. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  430. (function(){
  431. var adWords = ['Яндекс.Директ','Реклама','Ad'];
  432. function remove(node) {
  433. node.parentNode.removeChild(node);
  434. }
  435. // Generic ads removal and fixes
  436. function removeGenericAds() {
  437. var s, i;
  438. s = document.querySelector('.serp-header');
  439. if (s) {
  440. s.style.marginTop='0';
  441. }
  442. for (s of document.querySelectorAll('.serp-adv__head + .serp-item, #adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]')) {
  443. remove(s);
  444. }
  445. }
  446. // Search ads
  447. function removeSearchAds() {
  448. var s, item;
  449. for (s of document.querySelectorAll('.serp-block, .serp-item, .search-item')) {
  450. item = s.querySelector('.label, .serp-item__label, .document__provider-name');
  451. if (item && adWords.indexOf(item.textContent) > -1) {
  452. remove(s);
  453. console.log('Ads removed.');
  454. }
  455. }
  456. }
  457. // News ads
  458. function removeNewsAds() {
  459. var s;
  460. for (s of document.querySelectorAll('.page-content__left > *,.page-content__right > *:not(.page-content__col),.page-content__right > .page-content__col > *')) {
  461. if (s.textContent.indexOf(adWords[0]) > -1) {
  462. remove(s);
  463. console.log('Ads removed.');
  464. }
  465. }
  466. }
  467. // News fixes
  468. function removePageAdsClass() {
  469. if (document.body.classList.contains("b-page_ads_yes")){
  470. document.body.classList.remove("b-page_ads_yes");
  471. console.log('Page ads class removed.');
  472. }
  473. }
  474. // Function to attach an observer to monitor dynamic changes on the page
  475. function pageUpdateObserver(func, obj, params) {
  476. if (obj) {
  477. var o = new MutationObserver(func);
  478. o.observe(obj,(params || {childList:true, subtree:true}));
  479. }
  480. }
  481. // Cleaner
  482. document.addEventListener ('DOMContentLoaded', function() {
  483. removeGenericAds();
  484. if (win.location.hostname.search(/^news\./i) === 0) {
  485. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  486. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  487. removeNewsAds();
  488. removePageAdsClass();
  489. } else {
  490. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  491. removeSearchAds();
  492. }
  493. });
  494. })();
  495. return; //skip fixes for other sites
  496. }
  497.  
  498. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  499. if (/(^|\.)4pda\.ru$/i.test(window.location.hostname)) {
  500. (function() {
  501. var isForum = document.location.href.search('/forum/') !== -1,
  502. hStyle;
  503.  
  504. function remove(n) {
  505. if (n) {
  506. n.parentNode.removeChild(n);
  507. }
  508. }
  509.  
  510. function afterClean() {
  511. hStyle.disabled = true;
  512. remove(hStyle);
  513. }
  514.  
  515. function beforeClean() {
  516. // attach styles before document displayed
  517. hStyle = createStyle([
  518. 'html { overflow-y: scroll }',
  519. 'article + aside * { display: none !important }',
  520. '#header + div:after {'+(
  521. 'content: "";'+
  522. 'position: fixed;'+
  523. 'top: 0;'+
  524. 'left: 0;'+
  525. 'width: 100%;'+
  526. 'height: 100%;'+
  527. 'background-color: #E6E7E9'
  528. )+'}',
  529. // http://codepen.io/Beaugust/pen/DByiE
  530. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  531. 'article + aside:after {'+(
  532. 'content: "";'+
  533. 'position: absolute;'+
  534. 'width: 150px;'+
  535. 'height: 150px;'+
  536. 'top: 150px;'+
  537. 'left: 50%;'+
  538. 'margin-top: -75px;'+
  539. 'margin-left: -75px;'+
  540. 'box-sizing: border-box;'+
  541. 'border-radius: 100%;'+
  542. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  543. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  544. 'animation: spin 2s infinite linear'
  545. )+'}'
  546. ], {id:'ubrHider'}, true);
  547.  
  548. // display content of a page if time to load a page is more than 2 seconds to avoid
  549. // blocking access to a page if it is loading for too long or stuck in a loading state
  550. setTimeout(2000, afterClean);
  551. }
  552.  
  553. createStyle([
  554. '#nav .use-ad {display: block !important;}',
  555. 'article:not(.post) + article:not(#id) { display: none !important }'
  556. ]);
  557.  
  558. if (!isForum) {
  559. beforeClean();
  560. }
  561.  
  562. // clean a page
  563. window.addEventListener('DOMContentLoaded', function(){
  564. var rem, si, itm;
  565. function width(){ return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0; }
  566. function height(){ return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0; }
  567.  
  568.  
  569. if (isForum) {
  570. si = document.querySelector('#logostrip');
  571. if (si) {
  572. remove(si.parentNode.nextSibling);
  573. }
  574. }
  575.  
  576. if (document.location.href.search('/forum/dl/') !== -1) {
  577. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  578. ';background-color:black!important');
  579. for (itm of document.querySelectorAll('body>div')) {
  580. if (!itm.querySelector('.dw-fdwlink')) {
  581. remove(itm);
  582. }
  583. }
  584. }
  585.  
  586. if (isForum) { // Do not continue if it's a forum
  587. return;
  588. }
  589.  
  590. si = document.querySelector('#header');
  591. if (si) {
  592. rem = si.previousSibling;
  593. while (rem) {
  594. si = rem.previousSibling;
  595. remove(rem);
  596. rem = si;
  597. }
  598. }
  599.  
  600. for (itm of document.querySelectorAll('#nav li[class]')) {
  601. if (itm && itm.querySelector('a[href^="/tag/"]')) {
  602. remove(itm);
  603. }
  604. }
  605.  
  606. var style, result;
  607. for (itm of document.querySelectorAll('DIV')) {
  608. if (itm.offsetWidth > 0.95 * width() && itm.offsetHeight > 0.9 * height()) {
  609. style = window.getComputedStyle(itm, null);
  610. result = [];
  611. if(style.backgroundImage !== 'none') {
  612. result.push('background-image:none!important');
  613. }
  614. if(style.backgroundColor !== 'transparent') {
  615. result.push('background-color:transparent!important');
  616. }
  617. if (result.length) {
  618. if (itm.getAttribute('style')) {
  619. result.unshift(itm.getAttribute('style'));
  620. }
  621. itm.setAttribute('style', result.join(';'));
  622. }
  623. }
  624. }
  625.  
  626. for (itm of document.querySelectorAll('ASIDE>DIV')) {
  627. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  628. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  629. !itm.classList.contains('post') ) || !itm.childNodes.length ) {
  630. remove(itm);
  631. }
  632. }
  633.  
  634. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  635.  
  636. // display content of the page
  637. afterClean();
  638. });
  639. })();
  640. return;
  641. }
  642.  
  643. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.6
  644. document.addEventListener ('DOMContentLoaded', function() {
  645. if (!inIFrame) {
  646. return;
  647. }
  648. var tmp;
  649. function log (e) {
  650. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  651. }
  652. if (win.adv_enabled !== undefined && win.condition_detected !== undefined) {
  653. log('Moonwalk');
  654. win.adv_enabled = false;
  655. win.condition_detected = false;
  656. } else if (win.banner_second !== undefined && win.$banner_ads !== undefined) {
  657. log('HDGo');
  658. win.banner_second = 0;
  659. win.$banner_ads = false;
  660. win.$new_ads = false;
  661. win.canRunAds = true;
  662. tmp = document.body.querySelector('#swtf');
  663. if (tmp) {
  664. tmp.style.display = 'none';
  665. }
  666. } else if (win.MXoverrollCallback !== undefined && win.iframeSearch !== undefined) {
  667. log('Kodik');
  668. win.IsAdBlock = false;
  669. win.iframeSearch = null;
  670. tmp = document.getElementsByClassName('play_button')[0];
  671. if (tmp) {
  672. tmp.onclick = win.MXoverrollCallback.bind(window);
  673. }
  674. }
  675. }, false);
  676.  
  677. // function to search and remove nodes by content
  678. // selector - standard CSS selector to define set of nodes to check
  679. // words - regular expression to check content of the suspicious nodes
  680. // params - object with multiple extra parameters:
  681. // .hide - set display to none instead of removing from the page
  682. // .parent - parent node to remove if content is found in the child node
  683. // .siblings - number of simling nodes to remove (excluding text nodes)
  684. function scRemove(e) {e.parentNode.removeChild(e);}
  685. function scHide(e) {
  686. var s = e.getAttribute('style')||'',
  687. h = ';display:none!important;';
  688. if (s.indexOf(h) < 0) {
  689. e.setAttribute('style', s+h);
  690. }
  691. }
  692. function scissors (selector, words, scope, params) {
  693. var remFunc = (params.hide ? scHide : scRemove),
  694. iterFunc = (params.siblings > 0 ?
  695. 'nextSibling' :
  696. 'previousSibling'),
  697. toRemove = [],
  698. siblings,
  699. node;
  700. for (node of scope.querySelectorAll(selector)) {
  701. if (words.test(node.innerHTML) || !node.childNodes.length) {
  702. // drill up to the specified parent node if required
  703. if (params.parent) {
  704. while(node !== scope && !(node.matches(params.parent))) {
  705. node = node.parentNode;
  706. }
  707. }
  708. if (node === scope) {
  709. break;
  710. }
  711. toRemove.push(node);
  712. // add multiple nodes if defined more than one sibling
  713. siblings = Math.abs(params.siblings) || 0;
  714. while (siblings) {
  715. node = node[iterFunc];
  716. toRemove.push(node);
  717. if (node.nodeType === 1) {
  718. siblings -= 1; //count only element nodes
  719. }
  720. }
  721. }
  722. }
  723. for (node of toRemove) {
  724. remFunc(node);
  725. }
  726. return toRemove.length;
  727. }
  728.  
  729. // function to perform multiple checks if ads inserted with a delay
  730. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  731. // also does 1 extra check when a page completely loads
  732. // selector and words - passed dow to scissors
  733. // params - object with multiple extra parameters:
  734. // .root - selector to narrow down scope to scan;
  735. // .observe - if true then check will be performed continuously;
  736. // Other parameters passed down to scissors.
  737. function gardener(selector, words, params) {
  738. params = params || {};
  739. var scope = document.body,
  740. nonstop = false;
  741. // narrow down scope to a specific element
  742. if (params.root) {
  743. scope = scope.querySelector(params.root);
  744. if (!scope) {// exit if the root element is not present on the page
  745. return 0;
  746. }
  747. }
  748. // add observe mode if required
  749. if (params.observe) {
  750. if (typeof MutationObserver === 'function') {
  751. var o = new MutationObserver(function(ms){
  752. for (var m of ms) {
  753. if (m.addedNodes.length) {
  754. scissors(selector, words, scope, params);
  755. }
  756. }
  757. });
  758. o.observe(scope, {childList:true, subtree: true});
  759. } else {
  760. nonstop = true;
  761. }
  762. }
  763. // wait for a full page load to do one extra cut
  764. win.addEventListener('load',function(){
  765. scissors(selector, words, scope, params);
  766. });
  767. // do multiple cuts until ads removed
  768. function cut(sci, s, w, sc, p, i) {
  769. if (i > 0) {
  770. i -= 1;
  771. }
  772. if (i && !sci(s, w, sc, p)) {
  773. setTimeout(cut, 100, sci, s, w, sc, p, i);
  774. }
  775. }
  776. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  777. }
  778.  
  779. function preventBackgroundRedirect() {
  780. // create "cose_me" event to call high-level window.close()
  781. var key = Math.random().toString(36).substr(2);
  782. window.addEventListener('close_me_'+key, function(e) {
  783. window.close();
  784. });
  785.  
  786. // window.open wrapper
  787. function pbrLander() {
  788. var orgOpen = window.open.bind(window);
  789. function closeWindow(){
  790. // site went to a new tab and attempts to unload
  791. // call for high-level close through event
  792. var event = new CustomEvent("close_me_%key%", {});
  793. window.dispatchEvent(event);
  794. }
  795. function open(){
  796. var idx = String.prototype.indexOf;
  797. if (arguments[0] &&
  798. (idx.call(arguments[0], window.location.host) > -1 ||
  799. idx.call(arguments[0], '://') === -1)) {
  800. window.addEventListener('unload', closeWindow, true);
  801. }
  802. orgOpen.apply(window, arguments);
  803. }
  804. window.open = open.bind(window);
  805. var s = document.currentScript;
  806. if (s) {s.parentNode.removeChild(s);}
  807. }
  808.  
  809. // land wrapper on the page
  810. var script = document.createElement('script');
  811. script.appendChild(document.createTextNode('('+pbrLander.toString().replace(/%key%/g,key)+')();'));
  812. document.head.insertBefore(script,document.head.firstChild);
  813. console.log("Background redirect prevention enabled.");
  814. }
  815.  
  816. function forbidServiceWorker() {
  817. if (!("serviceWorker" in navigator)) {
  818. return;
  819. }
  820. var svr = navigator.serviceWorker.ready;
  821. Object.defineProperty(navigator, 'serviceWorker', {
  822. value: {
  823. register: function(){
  824. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  825. return new Promise(function(){});
  826. },
  827. ready: new Promise(function(){}),
  828. addEventListener:function(){}
  829. }
  830. });
  831. document.addEventListener('DOMContentLoaded', function() {
  832. if (!svr) {
  833. return;
  834. }
  835. svr.then(function(sw) {
  836. console.log('Found existing serviceWorker:', sw);
  837. console.log('Attempting to unregister...');
  838. sw.unregister().then(function() {
  839. console.log('Unregistered! :)');
  840. }).catch(function(err) {
  841. console.log('Unregistration failed. :(', err);
  842. console.log('Try to remove it manually:');
  843. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  844. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  845. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  846. });
  847. }).catch(function(err) {
  848. console.log("Lol, it failed on it's own. -_-", err);
  849. });
  850. }, false);
  851. }
  852.  
  853. var scripts = {};
  854. scripts['fs.to'] = function() {
  855. function skipClicker(i) {
  856. if (!i) {
  857. return;
  858. }
  859. var skip = document.querySelector('.b-aplayer-banners__close');
  860. if (skip) {
  861. skip.click();
  862. } else {
  863. setTimeout(skipClicker, 100, i-1);
  864. }
  865. }
  866. setTimeout(skipClicker, 100, 30);
  867.  
  868. createStyle([
  869. '.l-body-branding *,'+
  870. '.b-styled__item-central,'+
  871. '.b-styled__content-right,'+
  872. '.b-styled__section-central,'+
  873. 'div[id^="adsProxy-"]'+
  874. '{display:none!important}',
  875. 'body {background-image:url(data:image/png;base64,'+
  876. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACX'+
  877. 'BIWXMAAC4jAAAuIwF4pT92AAAADUlEQVR42mOQUdL5DwACMgFq'+
  878. 'BC3ttwAAAABJRU5ErkJggg==)!important}'
  879. ]);
  880.  
  881. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  882. var p = document.querySelector('#player:not([preload="auto"])'),
  883. m = document.querySelector('.main'),
  884. adStepper = function(p) {
  885. if (p.currentTime < p.duration) {
  886. p.currentTime += 1;
  887. }
  888. },
  889. adSkipper = function(f, p) {
  890. f.click();
  891. p.waitAfterSkip = false;
  892. p.longerSkipper = false;
  893. console.log('Пропустили.');
  894. },
  895. cl = function(p) {
  896. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  897. series = document.querySelector('.b-aplayer__actions-series');
  898.  
  899. function clickSelected() {
  900. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  901. if (s) {
  902. s.click();
  903. }
  904. }
  905.  
  906. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  907. series.click();
  908. p.seriesClicked = true;
  909. p.longerSkipper = true;
  910. setTimeout(clickSelected, 1000);
  911. p.pause();
  912. }
  913.  
  914. function skipListener() {
  915. if (p.waitAfterSkip) {
  916. console.log('В процессе пропуска…');
  917. return;
  918. }
  919. p.pause();
  920. if (!p.classList.contains('m-hidden')) {
  921. p.classList.add('m-hidden');
  922. }
  923. if (faster && p.currentTime &&
  924. win.getComputedStyle(faster).display === 'block' &&
  925. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  926. p.waitAfterSkip = true;
  927. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  928. console.log('Доступен быстрый пропуск…');
  929. } else {
  930. setTimeout(adStepper, 1000, p);
  931. }
  932. }
  933.  
  934. p.addEventListener('timeupdate', skipListener, false);
  935. },
  936. o = new MutationObserver(function (ms) {
  937. var m, node;
  938. for (m of ms) {
  939. for (node of m.addedNodes) {
  940. if (node.id === 'player' &&
  941. node.nodeName === 'VIDEO' &&
  942. node.getAttribute('preload') !== 'auto') {
  943. cl(node);
  944. }
  945. }
  946. }
  947. });
  948. if (p.nodeName === 'VIDEO') {
  949. cl(p);
  950. } else {
  951. o.observe(m, {childList: true});
  952. }
  953. }
  954. };
  955. scripts['brb.to'] = scripts['fs.to'];
  956. scripts['cxz.to'] = scripts['fs.to'];
  957.  
  958. scripts['drive2.ru'] = function() {
  959. gardener('.c-block', />Реклама<\/|\.relap\..*display:\s?none/i);
  960. };
  961.  
  962. scripts['fishki.net'] = function() {
  963. gardener('.main-post', /543769|Реклама/);
  964. };
  965.  
  966. scripts['hdgo.cc'] = {
  967. 'now': function(){
  968. var o = new MutationObserver(function(ms) {
  969. var m, node;
  970. for (m of ms) {
  971. for (node of m.addedNodes) {
  972. if (node.tagName === 'SCRIPT' && node.getAttribute('onerror') !== null) {
  973. node.removeAttribute('onerror');
  974. }
  975. }
  976. }
  977. });
  978. o.observe(document, {childList:true, subtree: true});
  979. }
  980. };
  981. scripts['couber.be'] = scripts['hdgo.cc'];
  982. scripts['46.30.43.38'] = scripts['hdgo.cc'];
  983.  
  984. scripts['hdrezka.me'] = {
  985. 'now': function() {
  986. Object.defineProperty(win, 'fuckAdBlock', {
  987. value: {
  988. onDetected: function() {
  989. console.log('Pretending to be an ABP detector.');
  990. }
  991. }
  992. });
  993. Object.defineProperty(win, 'ab', { value: false });
  994. },
  995. 'DOMContentLoaded': function() {
  996. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  997. }
  998. };
  999.  
  1000. scripts['naruto-base.su'] = function() {
  1001. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1002. };
  1003.  
  1004. scripts['overclockers.ru'] = {
  1005. 'load': function() {
  1006. gardener('OBJECT', /.?/i);
  1007. }
  1008. };
  1009.  
  1010. scripts['pb.wtf'] = function() {
  1011. createStyle(['.reques,#result,tbody.row1:not([id]) {display: none !important}']);
  1012. // image in the slider in the header
  1013. gardener('a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1014. // ads in blocks on the page
  1015. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  1016. // line above topic content
  1017. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1018. };
  1019. scripts['piratbit.org'] = scripts['pb.wtf'];
  1020. scripts['piratbit.ru'] = scripts['pb.wtf'];
  1021.  
  1022. scripts['pikabu.ru'] = function() {
  1023. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1024. };
  1025.  
  1026. scripts['rustorka.com'] = function() {
  1027. var s = document.head.childNodes, node;
  1028. if (s.length < 5) {
  1029. for (node of s) {
  1030. if (node.httpEquiv === 'refresh') {
  1031. window.close();
  1032. }
  1033. }
  1034. }
  1035. gardener('span[class],ul[class],span[id],ul[id]', /\/\d{12,}\.php/i, {root:'#sidebar1', observe:true});
  1036. gardener('div[id][style*="!important"]', /!important/i);
  1037. };
  1038. scripts['rumedia.ws'] = scripts['rustorka.com'];
  1039.  
  1040. scripts['sports.ru'] = function() {
  1041. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  1042. };
  1043.  
  1044. scripts['turbobit.net'] = {'now': preventBackgroundRedirect};
  1045.  
  1046. scripts['yap.ru'] = function() {
  1047. var words = /member1438|Administration/;
  1048. gardener('form > table[id^="p_row_"]', words);
  1049. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  1050. };
  1051. scripts['yaplakal.com'] = scripts['yap.ru'];
  1052.  
  1053. scripts['reactor.cc'] = {
  1054. 'now': preventBackgroundRedirect,
  1055. 'DOMContentLoaded': function() {
  1056. var words = new RegExp(
  1057. 'блокировщика рекламы'
  1058. .split('')
  1059. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  1060. .join('')
  1061. .replace(' ', '\\s*')
  1062. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  1063. 'i'),
  1064. can;
  1065. function deeper(spider) {
  1066. var c, l, n;
  1067. if (words.test(spider.innerText)) {
  1068. if (spider.nodeType === Node.TEXT_NODE) {
  1069. return true;
  1070. }
  1071. c = spider.childNodes;
  1072. l = c.length;
  1073. n = 0;
  1074. while(l--) {
  1075. if (deeper(c[l]), can) {
  1076. n++;
  1077. }
  1078. }
  1079. if (n > 0 && n === c.length && spider.offsetHeight < 750) {
  1080. can.push(spider);
  1081. }
  1082. return false;
  1083. }
  1084. return true;
  1085. }
  1086. function probe(){
  1087. if (words.test(document.body.innerText)) {
  1088. can = [];
  1089. deeper(document.body);
  1090. var i = can.length, j, spider;
  1091. while(i--) {
  1092. spider = can[i];
  1093. if (spider.offsetHeight > 10 && spider.offsetHeight < 750) {
  1094. spider.setAttribute('style', 'background:none!important');
  1095. }
  1096. }
  1097. }
  1098. }
  1099. var o = new MutationObserver(probe);
  1100. o.observe(document,{childList:true, subtree:true});
  1101. }
  1102. };
  1103. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  1104. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  1105.  
  1106. scripts['auto.ru'] = function() {
  1107. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  1108. var userAdsListAds = [
  1109. '.listing-list > .listing-item',
  1110. '.listing-item_type_fixed.listing-item'
  1111. ];
  1112. var catalogAds = [
  1113. 'div[class*="layout_catalog-inline"]',
  1114. 'div[class$="layout_horizontal"]'
  1115. ];
  1116. var otherAds = [
  1117. '.advt_auto',
  1118. '.sidebar-block',
  1119. '.pager-listing + div[class]',
  1120. '.card > div[class][style]',
  1121. '.sidebar > div[class]',
  1122. '.main-page__section + div[class]',
  1123. '.listing > tbody'];
  1124. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  1125. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  1126. gardener(otherAds.join(','), words);
  1127. };
  1128.  
  1129. scripts['online.anidub.com'] = function() {
  1130. var script = document.createElement('script');
  1131. script.type = "text/javascript";
  1132. script.innerHTML = "function ogonekstart1() {}";
  1133. document.getElementsByTagName('head')[0].appendChild(script);
  1134.  
  1135. var style = document.createElement('style');
  1136. style.type = 'text/css';
  1137. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  1138. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  1139. document.head.appendChild(style);
  1140. };
  1141.  
  1142. scripts['rsload.net'] = {
  1143. 'load': function() {
  1144. var dis = document.querySelector('.cb-disable');
  1145. if (dis) {
  1146. dis.click();
  1147. }
  1148. },
  1149. 'click': function(e) {
  1150. var t = e.target;
  1151. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  1152. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  1153. }
  1154. }
  1155. };
  1156.  
  1157. scripts['imageban.ru'] = {
  1158. 'now': preventBackgroundRedirect,
  1159. 'DOMContentLoaded': function() {
  1160. win.addEventListener('unload', function() {
  1161. if (!window.location.hash) {
  1162. window.location.replace(window.location+'#');
  1163. } else {
  1164. window.location.hash = '';
  1165. }
  1166. }, true);
  1167. }
  1168. };
  1169.  
  1170. var domain = document.domain, name;
  1171. while (domain.indexOf('.') !== -1) {
  1172. if (scripts.hasOwnProperty(domain)) {
  1173. if (typeof scripts[domain] === 'function') {
  1174. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  1175. }
  1176. for (name in scripts[domain]) {
  1177. if (name !== 'now') {
  1178. (name === 'load' ? window : document)
  1179. .addEventListener (name, scripts[domain][name], false);
  1180. } else {
  1181. scripts[domain][name]();
  1182. }
  1183. }
  1184. }
  1185. domain = domain.slice(domain.indexOf('.') + 1);
  1186. }
  1187. })();