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