RU AdList JS Fixes

try to take over the world!

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

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