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