RU AdList JS Fixes

try to take over the world!

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

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