RU AdList JS Fixes

try to take over the world!

目前為 2016-09-20 提交的版本,檢視 最新版本

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