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