RU AdList JS Fixes

try to take over the world!

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

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