RU AdList JS Fixes

try to take over the world!

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

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