RU AdList JS Fixes

try to take over the world!

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

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