RU AdList JS Fixes

try to take over the world!

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

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