RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 0.3
  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. var to_block =[
  19. 'et-code.ru',
  20. 'wsp.marketgid.com',
  21. 'trafmag.com',
  22. 'ws.hghit.com'
  23. ];
  24. var ws = window.WebSocket;
  25. window.WebSocket = new Proxy(ws, {
  26. construct: function(e,i){
  27. console.log('Opening WebSocket on', i[0], '…');
  28. var d = i[0].match(/:\/\/[^:/]+/)[0];
  29. if (d && to_block.indexOf(d.substring(3)) > -1) {
  30. console.log("Nope! Not gonna happen!");
  31. return {};
  32. } else return new e(i[0],i[1]);
  33. }
  34. });
  35. })();
  36. // https://greasyfork.org/scripts/14720-it-s-not-important
  37. (function(){
  38. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  39. rplsf = function(str,grp){return grp;};
  40.  
  41. function unimportanter(el, si) {
  42. if (!imptt.test(si) || el.style.display == 'none')
  43. return 0; // get out if we have nothing to do here
  44. var so = si.replace(imptt, rplsf), ret = 0;
  45. if (si != so) {
  46. ret = 1;
  47. el.setAttribute('style', so);
  48. }
  49. return ret;
  50. }
  51.  
  52. function logger(c) {
  53. if (c) console.log('Some page elements became a bit less important.');
  54. }
  55.  
  56. function checkTarget(m, c) {
  57. var si = m.getAttribute ? m.getAttribute('style') : null;
  58. if (si && si.indexOf('!') > -1)
  59. c+=unimportanter(m, si);
  60. return c;
  61. }
  62.  
  63. function checkNodes(m, c) {
  64. var i = m.length;
  65. while(i--)
  66. c = checkTarget(m[i], c);
  67. return c;
  68. }
  69.  
  70. var observer = new MutationObserver(function(mutations) {
  71. setTimeout(function(m) {
  72. var i = m.length, c = 0;
  73. while(i--) {
  74. if (m[i].target)
  75. c = checkTarget(m[i].target, c);
  76. if (m[i].addedNodes.length)
  77. c = checkNodes(m[i].addedNodes, c);
  78. }
  79. logger(c);
  80. },0,mutations);
  81. });
  82.  
  83. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  84.  
  85. window.addEventListener ("load", function(){
  86. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  87. while(i--) {
  88. c+= checkTarget(imp[i], c);
  89. }
  90. logger(c);
  91. }, false);
  92. })();
  93. }
  94.  
  95. document.addEventListener ("DOMContentLoaded", function() {
  96. var nRemove = function(node) {
  97. node.parentNode.removeChild(node);
  98. },
  99. scissors = function(selector, words, block) {
  100. var nodes = document.querySelectorAll(selector),
  101. i = nodes.length,
  102. toRemove = [],
  103. ret = false;
  104. while (i--)
  105. if (words.test(nodes[i].innerHTML)) {
  106. if (!block) {
  107. toRemove.push(nodes[i]);
  108. } else {
  109. var p = nodes[i],
  110. iterFunc = block.siblings > 0 ? 'nextSibling' : 'previousSibling',
  111. siblings = Math.abs(block.siblings) || 0;
  112. while(block.parent &&
  113. p !== document.body &&
  114. p.tagName.toLowerCase() !== block.parent) {
  115. p = p.parentNode;
  116. }
  117. if (p !== document.body) {
  118. toRemove.push(p);
  119. while(siblings) {
  120. p = p[iterFunc];
  121. toRemove.push(p);
  122. if (p.tagName) siblings--; //don't count text nodes
  123. }
  124. }
  125. }
  126. ret = true;
  127. }
  128. i = toRemove.length;
  129. while(i--)
  130. toRemove[i].parentNode.removeChild(toRemove[i]);
  131. return ret;
  132. };
  133.  
  134. var scripts = {};
  135. scripts['fs.to'] = function() {
  136. function skipClicker(i) {
  137. if (!i) return;
  138. var skip = document.querySelector('.b-aplayer-banners__close');
  139. if (skip)
  140. skip.click();
  141. else
  142. setTimeout(skipClicker, 100, i-1);
  143. }
  144. setTimeout(skipClicker, 100, 30);
  145.  
  146. var divs = document.getElementsByTagName('div');
  147. var re = /\w{1,5}\d{1,5}\w{1,5}\d{1,5}/;
  148. for(var i = 0; i < divs.length; i++)
  149. if(re.test(divs[i].className))
  150. divs[i].style.display = 'none';
  151.  
  152. var style = document.head.appendChild( document.createElement('style') );
  153. style.type = 'text/css';
  154.  
  155. style.sheet.insertRule(['.b-aplayer-teasers > a',
  156. '.b-player-popup__content > div[class][style="position: relative;"]',
  157. 'div[class^="b-adproxy"]',
  158. 'div[id^="admixer_async_"]'
  159. ].join(',')+'{display:none!important}', 0);
  160.  
  161. if (/\/view_iframe\//i.test(document.location.pathname)) {
  162. var p = document.querySelector('#player:not([preload="auto"])'),
  163. m = document.querySelector('.main'),
  164. adStepper = function(p) {
  165. if (p.currentTime < p.duration)
  166. p.currentTime++;
  167. },
  168. cl = function(p) {
  169. function skipListener() {
  170. p.pause();
  171. if (!p.classList.contains('m-hidden'))
  172. p.classList.add('m-hidden');
  173. setTimeout(adStepper, 1000, p);
  174. }
  175. p.addEventListener('timeupdate', skipListener, false);
  176. },
  177. o = new MutationObserver(function (mut) {
  178. mut.forEach(function (e) {
  179. for (var i = 0; i < e.addedNodes.length; i++) {
  180. if (e.addedNodes[i].id === 'player' &&
  181. e.addedNodes[i].nodeName === 'VIDEO' &&
  182. e.addedNodes[i].getAttribute('preload') != 'auto') {
  183. cl(e.addedNodes[i]);
  184. }
  185. }
  186. });
  187. });
  188. if (p.nodeName === 'VIDEO')
  189. cl(p);
  190. else
  191. o.observe(m, {childList: true});
  192. }
  193. };
  194. scripts['brb.to'] = scripts['fs.to'];
  195. scripts['cxz.to'] = scripts['fs.to'];
  196.  
  197. scripts['fishki.net'] = function() {
  198. scissors('.main-post', /543769|Реклама/);
  199. };
  200.  
  201. scripts['hdrezka.me'] = function() {
  202. scissors('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  203. };
  204.  
  205. scripts['yap.ru'] = function() {
  206. var words = /member1438|Administration/;
  207. scissors('form > table[id^="p_row_"]', words);
  208. scissors('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  209. };
  210. scripts['yaplakal.com'] = scripts['yap.ru'];
  211.  
  212. scripts['auto.ru'] = function() {
  213. function check1(sci, i) {
  214. if (i && !sci('.listing-list > .listing-item, .listing-item_type_fixed.listing-item, div[class*="layout_catalog-inline"], .listing > tbody', /Реклама/))
  215. setTimeout(check1, 100, sci, i-1);
  216. }
  217. function check2(sci, i) {
  218. if (i && !sci('.sidebar-block, .pager-listing + div[class], div[class$="layout_horizontal"], .card > div[class][style], .sidebar > div[class], .main-page__section + div[class]', /Яндекс\.Директ/))
  219. setTimeout(check2, 100, sci, i-1);
  220. }
  221. check1(scissors, 30);
  222. check2(scissors, 30);
  223. };
  224.  
  225. scripts['online.anidub.com'] = function() {
  226. var script = document.createElement('script');
  227. script.type = "text/javascript";
  228. script.innerHTML = "function ogonekstart1() {}";
  229. document.getElementsByTagName('head')[0].appendChild(script);
  230.  
  231. var style = document.createElement('style');
  232. style.type = 'text/css';
  233. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  234. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  235. document.head.appendChild(style);
  236. };
  237.  
  238. var domain = document.domain;
  239. while (domain.indexOf('.') + 1) {
  240. if (domain in scripts) {
  241. scripts[domain]();
  242. break;
  243. }
  244. domain = domain.slice(domain.indexOf('.') + 1);
  245. }
  246. });
  247. })();