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