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