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