RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 0.6.1
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. if (!/firefox/i.test(navigator.userAgent)) { // scripts for non-Firefox browsers
  16. // https://greasyfork.org/scripts/19144-websuckit/
  17. (function() {
  18. // check if the browser supports Proxy and WebSocket
  19. if (!window.Proxy || !window.WebSocket) return;
  20. var to_block =[
  21. 'et-code.ru',
  22. 'news.mail.ru',
  23. 'mxtads.com',
  24. 'torvind.com',
  25. 'trafmag.com',
  26. 'ws.hghit.com',
  27. 'wsp.marketgid.com'
  28. ];
  29. var ws = window.WebSocket;
  30. window.WebSocket = new Proxy(ws, {
  31. construct: function(WS,i){
  32. console.log('Opening WebSocket on', i[0], '…');
  33. var d = i[0].match(/:\/\/[^:/]+/)[0];
  34. if (d && to_block.indexOf(d.substring(3)) > -1) {
  35. console.log("Nope! Not gonna happen!");
  36. return {};
  37. } else return new WS(i[0],i[1]);
  38. }
  39. });
  40. })();
  41. // https://greasyfork.org/scripts/14720-it-s-not-important
  42. (function(){
  43. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  44. rplsf = function(str,grp){return grp;};
  45.  
  46. function unimportanter(el, si) {
  47. if (!imptt.test(si) || el.style.display == 'none')
  48. return 0; // get out if we have nothing to do here
  49. var so = si.replace(imptt, rplsf), ret = 0;
  50. if (si != so) {
  51. ret = 1;
  52. el.setAttribute('style', so);
  53. }
  54. return ret;
  55. }
  56.  
  57. function logger(c) {
  58. if (c) console.log('Some page elements became a bit less important.');
  59. }
  60.  
  61. function checkTarget(m, c) {
  62. var si = m.getAttribute ? m.getAttribute('style') : null;
  63. if (si && si.indexOf('!') > -1)
  64. c+=unimportanter(m, si);
  65. return c;
  66. }
  67.  
  68. function checkNodes(m, c) {
  69. var i = m.length;
  70. while(i--)
  71. c = checkTarget(m[i], c);
  72. return c;
  73. }
  74.  
  75. var observer = new MutationObserver(function(mutations) {
  76. setTimeout(function(m) {
  77. var i = m.length, c = 0;
  78. while(i--) {
  79. if (m[i].target)
  80. c = checkTarget(m[i].target, c);
  81. if (m[i].addedNodes.length)
  82. c = checkNodes(m[i].addedNodes, c);
  83. }
  84. logger(c);
  85. },0,mutations);
  86. });
  87.  
  88. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  89.  
  90. window.addEventListener ("load", function(){
  91. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  92. while(i--) {
  93. c+= checkTarget(imp[i], c);
  94. }
  95. logger(c);
  96. }, false);
  97. })();
  98. }
  99.  
  100. document.addEventListener ("DOMContentLoaded", function() {
  101. // function to search and remove nodes by conten
  102. // selector - standard CSS selector to define set of nodes to check
  103. // words - regular expression to check content of the suspicious nodes
  104. // params - object with multiple extra parameters:
  105. // .parent - parent node to remove if content is found in the child node
  106. // .siblings - number of simling nodes to remove (excluding text nodes)
  107. function scissors (selector, words, scope, params) {
  108. var nodes = scope.querySelectorAll(selector),
  109. i = nodes.length,
  110. toRemove = [];
  111.  
  112. while (i--)
  113. if (words.test(nodes[i].innerHTML) || !nodes[i].childNodes.length) {
  114. var node = nodes[i],
  115. siblings = Math.abs(params.siblings) || 0,
  116. iterFunc = params.siblings > 0 ? 'nextSibling' : 'previousSibling';
  117. // drill up to the specified parent node if required
  118. if (params.parent)
  119. while(node !== scope &&
  120. node.tagName.toLowerCase() !== params.parent)
  121. node = node.parentNode;
  122. if (node === scope)
  123. break;
  124. toRemove.push(node);
  125. // add multiple nodes if defined more than one sibling
  126. while (siblings) {
  127. node = node[iterFunc];
  128. toRemove.push(node);
  129. if (node.tagName) siblings--; //don't count text nodes
  130. }
  131. }
  132. i = toRemove.length;
  133. while(i--)
  134. toRemove[i].parentNode.removeChild(toRemove[i]);
  135.  
  136. return toRemove.length;
  137. }
  138.  
  139. // function to perform multiple checks if ads inserted with a delay
  140. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  141. // also does 1 extra check when a page completely loads
  142. // selector and words - passed dow to scissors
  143. // params - object with multiple extra parameters:
  144. // .root - selector to narrow down scope to scan
  145. // .watch - if true then check will be performed continuously
  146. // .parent - passed down to scissors
  147. // .siblings - passed down to scissors
  148. function gardener(selector, words, params) {
  149. params = params || {};
  150. var scope = document.body,
  151. nonstop = false;
  152. // narrow dowsn scope to a specific element
  153. if (params.root) {
  154. scope = scope.querySelector(params.root);
  155. if (!scope) // exit if the root element is not present on the page
  156. return 0;
  157. }
  158. // add watch mode if required
  159. if (params.watch) {
  160. if (window.MutationObserver) {
  161. var o = new MutationObserver(function(ms){
  162. ms.forEach(function(m){
  163. if (m.addedNodes.length)
  164. scissors(selector, words, scope, params);
  165. });
  166. });
  167. o.observe(document.querySelector(params.root),
  168. {childList:true, subtree: true});
  169. } else nonstop = true;
  170. }
  171. // watch for a full page load to do one extra cut
  172. window.addEventListener('load',function(){
  173. scissors(selector, words, scope, params);
  174. });
  175. // do multiple cuts until ads removed
  176. function cut(sci, s, w, sc, p, i) {
  177. if (i > 0) i--;
  178. if (i && !sci(s, w, sc, p))
  179. setTimeout(cut, 100, sci, s, w, sc, p, i);
  180. }
  181. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  182. }
  183.  
  184. var scripts = {};
  185. scripts['fs.to'] = function() {
  186. function skipClicker(i) {
  187. if (!i) return;
  188. var skip = document.querySelector('.b-aplayer-banners__close');
  189. if (skip)
  190. skip.click();
  191. else
  192. setTimeout(skipClicker, 100, i-1);
  193. }
  194. setTimeout(skipClicker, 100, 30);
  195.  
  196. var divs = document.getElementsByTagName('div');
  197. var re = /\w{1,5}\d{1,5}\w{1,5}\d{1,5}/;
  198. for(var i = 0; i < divs.length; i++)
  199. if(re.test(divs[i].className))
  200. divs[i].style.display = 'none';
  201.  
  202. var style = document.head.appendChild( document.createElement('style') );
  203. style.type = 'text/css';
  204.  
  205. style.sheet.insertRule([
  206. '.b-aplayer-teasers > a',
  207. '.b-player-popup__content > div[class][style="position: relative;"]',
  208. 'div[class^="b-adproxy"]',
  209. 'div[id^="admixer_async_"]'
  210. ].join(',')+'{display:none!important}', 0);
  211.  
  212. if (/\/view_iframe\//i.test(document.location.pathname)) {
  213. var p = document.querySelector('#player:not([preload="auto"])'),
  214. m = document.querySelector('.main'),
  215. adStepper = function(p) {
  216. if (p.currentTime < p.duration)
  217. p.currentTime++;
  218. },
  219. cl = function(p) {
  220. function skipListener() {
  221. p.pause();
  222. if (!p.classList.contains('m-hidden'))
  223. p.classList.add('m-hidden');
  224. setTimeout(adStepper, 1000, p);
  225. }
  226. p.addEventListener('timeupdate', skipListener, false);
  227. },
  228. o = new MutationObserver(function (mut) {
  229. mut.forEach(function (e) {
  230. for (var i = 0; i < e.addedNodes.length; i++) {
  231. if (e.addedNodes[i].id === 'player' &&
  232. e.addedNodes[i].nodeName === 'VIDEO' &&
  233. e.addedNodes[i].getAttribute('preload') != 'auto') {
  234. cl(e.addedNodes[i]);
  235. }
  236. }
  237. });
  238. });
  239. if (p.nodeName === 'VIDEO')
  240. cl(p);
  241. else
  242. o.observe(m, {childList: true});
  243. }
  244. };
  245. scripts['brb.to'] = scripts['fs.to'];
  246. scripts['cxz.to'] = scripts['fs.to'];
  247.  
  248. scripts['fishki.net'] = function() {
  249. gardener('.main-post', /543769|Реклама/);
  250. };
  251.  
  252. scripts['hdrezka.me'] = function() {
  253. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  254.  
  255. };
  256.  
  257. scripts['yap.ru'] = function() {
  258. var words = /member1438|Administration/;
  259. gardener('form > table[id^="p_row_"]', words);
  260. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  261. };
  262. scripts['yaplakal.com'] = scripts['yap.ru'];
  263.  
  264. scripts['auto.ru'] = function() {
  265. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  266. var userAdsListAds = [
  267. '.listing-list > .listing-item',
  268. '.listing-item_type_fixed.listing-item'
  269. ];
  270. var catalogAds = [
  271. 'div[class*="layout_catalog-inline"]',
  272. 'div[class$="layout_horizontal"]'
  273. ];
  274. var otherAds = [
  275. '.advt_auto',
  276. '.sidebar-block',
  277. '.pager-listing + div[class]',
  278. '.card > div[class][style]',
  279. '.sidebar > div[class]',
  280. '.main-page__section + div[class]',
  281. '.listing > tbody'];
  282. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', watch:true});
  283. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', watch:true});
  284. gardener(otherAds.join(','), words);
  285. };
  286.  
  287. scripts['online.anidub.com'] = function() {
  288. var script = document.createElement('script');
  289. script.type = "text/javascript";
  290. script.innerHTML = "function ogonekstart1() {}";
  291. document.getElementsByTagName('head')[0].appendChild(script);
  292.  
  293. var style = document.createElement('style');
  294. style.type = 'text/css';
  295. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  296. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  297. document.head.appendChild(style);
  298. };
  299.  
  300. var domain = document.domain;
  301. while (domain.indexOf('.') + 1) {
  302. if (domain in scripts) {
  303. scripts[domain]();
  304. break;
  305. }
  306. domain = domain.slice(domain.indexOf('.') + 1);
  307. }
  308. });
  309. })();