RU AdList JS Fixes

try to take over the world!

当前为 2016-08-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 1.0.34
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var win = unsafeWindow || window;
  16. function inIFrame() {
  17. try {
  18. return win.self !== win.top;
  19. } catch (ignore) {
  20. return true;
  21. }
  22. }
  23.  
  24. if (!(/firefox/i.test(navigator.userAgent))) { // scripts for non-Firefox browsers
  25.  
  26. // https://greasyfork.org/scripts/19144-websuckit/
  27. (function() {
  28. var to_block = [
  29. '||bgrndi.com^',
  30. '||brokeloy.com^',
  31. '||dreadfula.ru^',
  32. '||et-code.ru^',
  33. '||gocdn.ru^',
  34. '||hghit.com^',
  35. '||kuveres.com^',
  36. '||lepubs.com^',
  37. '||mail.ru^',
  38. '||marketgid.com^',
  39. '||mxtads.com^',
  40. '||psma01.com^',
  41. '||psma02.com^',
  42. '||psma03.com^',
  43. '||recreativ.ru^',
  44. '||regpole.com^',
  45. '||torvind.com^',
  46. '||trafmag.com^',
  47. '||xxuhter.ru^'
  48. ];
  49. var masks = [];
  50. to_block.forEach(function(m){
  51. masks.push(new RegExp(
  52. m.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  53. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  54. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  55. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  56. 'i'));
  57. });
  58. var ws = window.WebSocket;
  59. function wsGetter(tgt, nm) {
  60. console.log('[WSI] Registered call to property "', nm, '"');
  61. var closingFunctions = ['close', 'send'];
  62. try {
  63. if (typeof ws.prototype[nm] === 'function') {
  64. if (closingFunctions.indexOf(nm) > -1) {
  65. tgt.readyState = ws.CLOSED;
  66. }
  67. return function(){return;};
  68. }
  69. if (typeof ws.prototype[nm] === 'number') {
  70. return ws[nm];
  71. }
  72. } catch(ignore) {}
  73. return tgt[nm];
  74. }
  75. window.WebSocket = new Proxy(ws, {
  76. construct: function(target, args) {
  77. var url = args[0];
  78. console.log('[WSI] Opening socket on', url, '…');
  79. var i = masks.length;
  80. while(i--) {
  81. if (masks[i].test(url)) {
  82. console.log("[WSI] Blocked.");
  83. return new Proxy({url: url, readyState: ws.OPEN}, {
  84. get: wsGetter
  85. });
  86. }
  87. }
  88. return new target(args[0], args[1]);
  89. }
  90. });
  91. })();
  92.  
  93. // https://greasyfork.org/scripts/14720-it-s-not-important
  94. (function(){
  95. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  96.  
  97. function unimportanter(el, si) {
  98. if (!imptt.test(si) || el.style.display === 'none') {
  99. return 0; // get out if we have nothing to do here
  100. }
  101. if (el.nodeName === 'IFRAME' && el.src &&
  102. el.src.slice(0,17) === 'chrome-extension:') {
  103. return 0; // Web of Trust uses this method to add their frame
  104. }
  105. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  106. if (si !== so) {
  107. ret = 1;
  108. el.setAttribute('style', so);
  109. }
  110. return ret;
  111. }
  112.  
  113. function logger(c) {
  114. if (c) {
  115. console.log('Some page elements became a bit less important.');
  116. }
  117. }
  118.  
  119. function checkTarget(m, c) {
  120. var si = m.getAttribute ? m.getAttribute('style') : null;
  121. if (si && si.indexOf('!') > -1) {
  122. c += unimportanter(m, si);
  123. }
  124. return c;
  125. }
  126.  
  127. function checkNodes(m, c) {
  128. var i = m.length;
  129. while(i--) {
  130. c = checkTarget(m[i], c);
  131. }
  132. return c;
  133. }
  134.  
  135. var observer = new MutationObserver(function(mutations) {
  136. setTimeout(function(m) {
  137. var i = m.length, c = 0;
  138. while(i--) {
  139. if (m[i].target) {
  140. c = checkTarget(m[i].target, c);
  141. }
  142. if (m[i].addedNodes.length) {
  143. c = checkNodes(m[i].addedNodes, c);
  144. }
  145. }
  146. logger(c);
  147. },0,mutations);
  148. });
  149.  
  150. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  151.  
  152. win.addEventListener ("load", function(){
  153. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  154. while(i--) {
  155. c+= checkTarget(imp[i], c);
  156. }
  157. logger(c);
  158. }, false);
  159. })();
  160.  
  161. }
  162.  
  163. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix
  164. (function () {
  165. if (!inIFrame) {
  166. return;
  167. }
  168.  
  169. document.addEventListener ("DOMContentLoaded", function() {
  170. var player;
  171. if (win.iframe_adv_enabled !== undefined) {
  172. win.iframe_adv_enabled = false;
  173. } else if (win.banner_second !== undefined) {
  174. win.banner_second = 0;
  175. player = document.getElementById('play-player-hd');
  176. if (player) {
  177. player.onclick = function() {
  178. var adsdiv = document.getElementById("ads-player-hd");
  179. adsdiv.parentNode.removeChild(adsdiv);
  180. win.setPlayer();
  181. };
  182. }
  183. } else if (win.MXoverrollCallback !== undefined) {
  184. player = document.getElementsByClassName('play_button')[0];
  185. if (player) {
  186. player.onclick = win.MXoverrollCallback.bind(window);
  187. }
  188. }
  189. },false);
  190. })();
  191.  
  192. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  193. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  194. document.addEventListener ("DOMContentLoaded", function() {
  195. // Generic ads removal and fixes
  196. function removeGenericAds() {
  197. var s, i;
  198. s = document.querySelector('.serp-header');
  199. if (s) {
  200. s.style.marginTop='0';
  201. }
  202. s = document.querySelectorAll('.serp-adv__head + .serp-item');
  203. i = s.length;
  204. while(i--) {
  205. s[i].parentNode.removeChild(s[i]);
  206. }
  207. s = document.querySelectorAll('#adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]');
  208. i = s.length;
  209. while(i--) {
  210. s[i].parentNode.removeChild(s[i]);
  211. }
  212. }
  213. removeGenericAds();
  214.  
  215. // Search ads
  216. function removeAds() {
  217. var s = document.querySelectorAll('.serp-block, .serp-item, .search-item');
  218. var i = s.length, item;
  219. while(i--) {
  220. item = s[i].querySelector('.label, .serp-item__label, .document__provider-name');
  221. if (item && (
  222. item.textContent.indexOf('Реклама') > -1 ||
  223. item.textContent.indexOf('Яндекс.Директ') > -1)) {
  224. s[i].parentNode.removeChild(s[i]);
  225. console.log('Ads removed.');
  226. }
  227. }
  228. }
  229. // News ads
  230. function removeNewsAds() {
  231. var s = document.querySelectorAll('.story[id], .document[id], .story__group[id]');
  232. var i = s.length;
  233. while(i--) {
  234. if (window.getComputedStyle(s[i]).position === 'absolute') {
  235. s[i].parentNode.removeChild(s[i]);
  236. console.log('Ads removed.');
  237. }
  238. }
  239. }
  240. // News fixes
  241. function removePageAdsClass() {
  242. if (document.body.classList.contains("b-page_ads_yes")){
  243. document.body.classList.remove("b-page_ads_yes");
  244. console.log('Page ads class removed.');
  245. }
  246. }
  247. // Attaches observer to the page elements which Yandex updates via AJAX to display new search or news results
  248. function pageUpdateObserver(func, obj, params) {
  249. if (obj) {
  250. var o = new MutationObserver(func);
  251. o.observe(obj,(params || {childList:true}));
  252. }
  253. }
  254.  
  255. if (window.location.hostname.search(/^news\./i) === 0) {
  256. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  257. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  258. removeNewsAds();
  259. removePageAdsClass();
  260. } else {
  261. pageUpdateObserver(removeAds, document.querySelector('.main__content'));
  262. removeAds();
  263. }
  264. });
  265. } else {
  266. // all the other cases
  267. document.addEventListener ("DOMContentLoaded", function() {
  268. // function to search and remove nodes by content
  269. // selector - standard CSS selector to define set of nodes to check
  270. // words - regular expression to check content of the suspicious nodes
  271. // params - object with multiple extra parameters:
  272. // .parent - parent node to remove if content is found in the child node
  273. // .siblings - number of simling nodes to remove (excluding text nodes)
  274. function scissors (selector, words, scope, params) {
  275. var nodes = scope.querySelectorAll(selector),
  276. i = nodes.length,
  277. toRemove = [],
  278. siblings = Math.abs(params.siblings) || 0,
  279. iterFunc = params.siblings > 0 ? 'nextSibling' : 'previousSibling',
  280. node;
  281. while(i--) {
  282. node = nodes[i];
  283. if (words.test(node.innerHTML) || !node.childNodes.length) {
  284. // drill up to the specified parent node if required
  285. if (params.parent) {
  286. while(node !== scope && !(node.matches(params.parent))) {
  287. node = node.parentNode;
  288. }
  289. }
  290. if (node === scope) {
  291. break;
  292. }
  293. toRemove.push(node);
  294. // add multiple nodes if defined more than one sibling
  295. while (siblings) {
  296. node = node[iterFunc];
  297. toRemove.push(node);
  298. if (node.tagName) {
  299. siblings -= 1; //don't count text nodes
  300. }
  301. }
  302. }
  303. }
  304. i = toRemove.length;
  305. while(i--) {
  306. toRemove[i].parentNode.removeChild(toRemove[i]);
  307. }
  308.  
  309. return toRemove.length;
  310. }
  311.  
  312. // function to perform multiple checks if ads inserted with a delay
  313. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  314. // also does 1 extra check when a page completely loads
  315. // selector and words - passed dow to scissors
  316. // params - object with multiple extra parameters:
  317. // .root - selector to narrow down scope to scan;
  318. // .observe - if true then check will be performed continuously;
  319. // .parent - passed down to scissors;
  320. // .siblings - passed down to scissors;
  321. function gardener(selector, words, params) {
  322. params = params || {};
  323. var scope = document.body,
  324. nonstop = false;
  325. // narrow down scope to a specific element
  326. if (params.root) {
  327. scope = scope.querySelector(params.root);
  328. if (!scope) {// exit if the root element is not present on the page
  329. return 0;
  330. }
  331. }
  332. // add observe mode if required
  333. if (params.observe) {
  334. if (typeof MutationObserver === 'function') {
  335. var o = new MutationObserver(function(ms){
  336. ms.forEach(function(m){
  337. if (m.addedNodes.length) {
  338. scissors(selector, words, scope, params);
  339. }
  340. });
  341. });
  342. o.observe(document.querySelector(params.root),
  343. {childList:true, subtree: true});
  344. } else {
  345. nonstop = true;
  346. }
  347. }
  348. // wait for a full page load to do one extra cut
  349. win.addEventListener('load',function(){
  350. scissors(selector, words, scope, params);
  351. });
  352. // do multiple cuts until ads removed
  353. function cut(sci, s, w, sc, p, i) {
  354. if (i > 0) {
  355. i -= 1;
  356. }
  357. if (i && !sci(s, w, sc, p)) {
  358. setTimeout(cut, 100, sci, s, w, sc, p, i);
  359. }
  360. }
  361. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  362. }
  363.  
  364. function preventBackgroundRedirect() {
  365. console.log("Background redirect prevention enabled.");
  366. var orgOpen = win.open;
  367. win.open = function(){
  368. var loc = arguments[0];
  369. if (loc.indexOf(win.location.host) > -1 ||
  370. loc.indexOf('://') === -1) {
  371. win.addEventListener('unload',function(){
  372. win.close();
  373. }, true);
  374. }
  375. orgOpen.apply(window, arguments);
  376. };
  377. }
  378.  
  379. var scripts = {};
  380. scripts['fs.to'] = function() {
  381. function skipClicker(i) {
  382. if (!i) {
  383. return;
  384. }
  385. var skip = document.querySelector('.b-aplayer-banners__close');
  386. if (skip) {
  387. skip.click();
  388. } else {
  389. setTimeout(skipClicker, 100, i-1);
  390. }
  391. }
  392. setTimeout(skipClicker, 100, 30);
  393.  
  394. var divs = document.getElementsByTagName('div'),
  395. re = /\w{1,5}\d{1,5}\w{1,5}\d{1,5}/,
  396. i = divs.length;
  397. while(i--) {
  398. if (re.test(divs[i].className)) {
  399. divs[i].style.display = 'none';
  400. }
  401. }
  402.  
  403. var style = document.head.appendChild( document.createElement('style') );
  404. style.type = 'text/css';
  405.  
  406. var toHide = [
  407. '.b-aplayer-teasers > a',
  408. '.b-player-popup__content > div[class][style="position: relative;"]',
  409. 'div[class^="b-adproxy"]',
  410. 'div[id^="admixer_async_"]'
  411. ];
  412. style.sheet.insertRule(toHide.join(',')+'{display:none!important}', 0);
  413.  
  414. if (/\/view_iframe\//i.test(document.location.pathname)) {
  415. var p = document.querySelector('#player:not([preload="auto"])'),
  416. m = document.querySelector('.main'),
  417. adStepper = function(p) {
  418. if (p.currentTime < p.duration) {
  419. p.currentTime += 1;
  420. }
  421. },
  422. adSkipper = function(f, p) {
  423. f.click();
  424. p.waitAfterSkip = false;
  425. console.log('Пропущена.');
  426. },
  427. cl = function(p) {
  428. var faster = document.querySelector('.b-aplayer__html5-desktop-skip');
  429.  
  430. function skipListener() {
  431. if (p.waitAfterSkip) {
  432. console.log('Доступен быстрый пропуск рекламы…');
  433. return;
  434. }
  435. p.pause();
  436. if (!p.classList.contains('m-hidden')) {
  437. p.classList.add('m-hidden');
  438. }
  439. if (faster &&
  440. win.getComputedStyle(faster).display === 'block' &&
  441. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  442. p.waitAfterSkip = true;
  443. setTimeout(adSkipper, 1000, faster, p);
  444. } else {
  445. setTimeout(adStepper, 1000, p);
  446. }
  447. }
  448.  
  449. p.addEventListener('timeupdate', skipListener, false);
  450. },
  451. o = new MutationObserver(function (mut) {
  452. mut.forEach(function (e) {
  453. var i = e.addedNodes.length;
  454. while(i--) {
  455. if (e.addedNodes[i].id === 'player' &&
  456. e.addedNodes[i].nodeName === 'VIDEO' &&
  457. e.addedNodes[i].getAttribute('preload') !== 'auto') {
  458. cl(e.addedNodes[i]);
  459. }
  460. }
  461. });
  462. });
  463. if (p.nodeName === 'VIDEO') {
  464. cl(p);
  465. } else {
  466. o.observe(m, {childList: true});
  467. }
  468. }
  469. };
  470. scripts['brb.to'] = scripts['fs.to'];
  471. scripts['cxz.to'] = scripts['fs.to'];
  472.  
  473. scripts['drive2.ru'] = function() {
  474. gardener('.g-column-wide > .c-block', /Реклама|\.relap\./i);
  475. };
  476.  
  477. scripts['pikabu.ru'] = function() {
  478. gardener('.story', /story__sponsor|profile\/ads"/i, {root:'.stories,.page-story', observe: true});
  479. };
  480.  
  481. scripts['fishki.net'] = function() {
  482. gardener('.main-post', /543769|Реклама/);
  483. };
  484.  
  485. scripts['hdrezka.me'] = function() {
  486. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  487. };
  488.  
  489. scripts['naruto-base.tv'] = function() {
  490. gardener('div[id^="entryID"],center', /\/goo.gl\//i);
  491. };
  492.  
  493. scripts['pb.wtf'] = function() {
  494. gardener('a[href$="=="]', /data:image/i, {root:'.msd .containe', observe:true, parent:'div[class]'});
  495. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  496. };
  497. scripts['piratbit.org'] = scripts['pb.wtf'];
  498. scripts['piratbit.ru'] = scripts['pb.wtf'];
  499.  
  500. scripts['sports.ru'] = function() {
  501. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  502. };
  503.  
  504. scripts['rustorka.com'] = function() {
  505. var s = document.head.childNodes, i = s.length;
  506. if (i < 5) {
  507. while(i--) {
  508. if (s[i].httpEquiv && s[i].httpEquiv === 'refresh') {
  509. win.close();
  510. }
  511. }
  512. }
  513. gardener('span[class],ul[class],span[id],ul[id]', /\/\d{12,}\.php/i, {root:'#sidebar1', observe:true});
  514. gardener('div[id][style*="!important"]', /!important/i);
  515. };
  516. scripts['rumedia.ws'] = scripts['rustorka.com'];
  517.  
  518. scripts['yap.ru'] = function() {
  519. var words = /member1438|Administration/;
  520. gardener('form > table[id^="p_row_"]', words);
  521. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  522. };
  523. scripts['yaplakal.com'] = scripts['yap.ru'];
  524.  
  525. scripts['reactor.cc'] = preventBackgroundRedirect;
  526. scripts['joyreactor.cc'] = preventBackgroundRedirect;
  527. scripts['pornreactor.cc'] = preventBackgroundRedirect;
  528.  
  529. scripts['auto.ru'] = function() {
  530. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  531. var userAdsListAds = [
  532. '.listing-list > .listing-item',
  533. '.listing-item_type_fixed.listing-item'
  534. ];
  535. var catalogAds = [
  536. 'div[class*="layout_catalog-inline"]',
  537. 'div[class$="layout_horizontal"]'
  538. ];
  539. var otherAds = [
  540. '.advt_auto',
  541. '.sidebar-block',
  542. '.pager-listing + div[class]',
  543. '.card > div[class][style]',
  544. '.sidebar > div[class]',
  545. '.main-page__section + div[class]',
  546. '.listing > tbody'];
  547. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  548. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  549. gardener(otherAds.join(','), words);
  550. };
  551.  
  552. scripts['online.anidub.com'] = function() {
  553. var script = document.createElement('script');
  554. script.type = "text/javascript";
  555. script.innerHTML = "function ogonekstart1() {}";
  556. document.getElementsByTagName('head')[0].appendChild(script);
  557.  
  558. var style = document.createElement('style');
  559. style.type = 'text/css';
  560. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  561. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  562. document.head.appendChild(style);
  563. };
  564.  
  565. scripts['rsload.net'] = function() {
  566. win.addEventListener('load', function() {
  567. var dis = document.querySelector('.cb-disable');
  568. if (dis) {
  569. dis.click();
  570. }
  571. });
  572. document.addEventListener('click',function(e){
  573. var t = e.target;
  574. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  575. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  576. }
  577. });
  578. };
  579.  
  580. var domain = document.domain;
  581. while (domain.indexOf('.') !== -1) {
  582. if (scripts.hasOwnProperty(domain)) {
  583. scripts[domain]();
  584. break;
  585. }
  586. domain = domain.slice(domain.indexOf('.') + 1);
  587. }
  588. });
  589. }
  590. })();