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