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