RU AdList JS Fixes

try to take over the world!

目前为 2016-06-18 提交的版本,查看 最新版本

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