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