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