RU AdList JS Fixes

try to take over the world!

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

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