RU AdList JS Fixes

try to take over the world!

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

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