RU AdList JS Fixes

try to take over the world!

当前为 2016-10-07 提交的版本,查看 最新版本

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