RU AdList JS Fixes

try to take over the world!

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

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