RU AdList JS Fixes

try to take over the world!

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

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