RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 0.9
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var win = unsafeWindow || window,
  15. inIFrame = function() {
  16. try {
  17. return win.self !== win.top;
  18. } catch (e) {
  19. return true;
  20. }
  21. };
  22.  
  23. if (!/firefox/i.test(navigator.userAgent)) { // scripts for non-Firefox browsers
  24.  
  25. // https://greasyfork.org/scripts/19144-websuckit/
  26. (function() {
  27. // check if the browser supports Proxy and WebSocket
  28. if (!win.Proxy || !win.WebSocket) return;
  29. var to_block = [
  30. '||brokeloy.com^',
  31. '||et-code.ru^',
  32. '||hghit.com^',
  33. '||mail.ru^',
  34. '||marketgid.com^',
  35. '||mxtads.com^',
  36. '||torvind.com^',
  37. '||trafmag.com^'
  38. ], masks = [];
  39. to_block.forEach(function(m){
  40. masks.push(new RegExp(
  41. (m.substr(0,2) === '||' ? '^wss?:\/+([^/.]+\\.)*' : '') +
  42. m.replace(/\|\||\^/g,'').replace(/[./]/g, function(ch){
  43. return '\\' + ch;
  44. }) +
  45. (m.substr(-1) === '^' ? '[:/]' : ''), 'i'));
  46. });
  47. var ws = win.WebSocket;
  48. win.WebSocket = new Proxy(ws, {
  49. construct: function(e,i){
  50. console.log('Opening WebSocket on', i[0], '…');
  51. var j = masks.length;
  52. while(j--)
  53. if (masks[j].test(i[0])) {
  54. console.log("Nope! Not gonna happen!");
  55. return {};
  56. }
  57. return new e(i[0],i[1]);
  58. }
  59. });
  60. })();
  61.  
  62. // https://greasyfork.org/scripts/14720-it-s-not-important
  63. (function(){
  64. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  65. rplsf = function(str,grp){return grp;};
  66.  
  67. function unimportanter(el, si) {
  68. if (!imptt.test(si) || el.style.display == 'none')
  69. return 0; // get out if we have nothing to do here
  70. var so = si.replace(imptt, rplsf), ret = 0;
  71. if (si != so) {
  72. ret = 1;
  73. el.setAttribute('style', so);
  74. }
  75. return ret;
  76. }
  77.  
  78. function logger(c) {
  79. if (c) console.log('Some page elements became a bit less important.');
  80. }
  81.  
  82. function checkTarget(m, c) {
  83. var si = m.getAttribute ? m.getAttribute('style') : null;
  84. if (si && si.indexOf('!') > -1)
  85. c+=unimportanter(m, si);
  86. return c;
  87. }
  88.  
  89. function checkNodes(m, c) {
  90. var i = m.length;
  91. while(i--)
  92. c = checkTarget(m[i], c);
  93. return c;
  94. }
  95.  
  96. var observer = new MutationObserver(function(mutations) {
  97. setTimeout(function(m) {
  98. var i = m.length, c = 0;
  99. while(i--) {
  100. if (m[i].target)
  101. c = checkTarget(m[i].target, c);
  102. if (m[i].addedNodes.length)
  103. c = checkNodes(m[i].addedNodes, c);
  104. }
  105. logger(c);
  106. },0,mutations);
  107. });
  108.  
  109. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  110.  
  111. win.addEventListener ("load", function(){
  112. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  113. while(i--) {
  114. c+= checkTarget(imp[i], c);
  115. }
  116. logger(c);
  117. }, false);
  118. })();
  119.  
  120. }
  121.  
  122. // https://greasyfork.org/en/scripts/18847-delay-removal-moonwalk
  123. (function () {
  124. if (!inIFrame)
  125. return;
  126.  
  127. document.addEventListener ("DOMContentLoaded", function() {
  128. if (win.condition_detected !== undefined) {
  129. win.request_host_id = "19804";
  130. var player = document.getElementById('player');
  131. if (player) player.onclick = function(){
  132. win.showVideo();
  133. };
  134. }
  135. },false);
  136. })();
  137.  
  138. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^/]+\/(yand)?search[/?])/i.test(win.location.href))
  139. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  140. document.addEventListener ("DOMContentLoaded", function() {
  141. // Generic ads removal and fixes
  142. (function(s){
  143. if (s) s.style.marginTop='0';
  144. })(document.querySelector('.serp-header'));
  145. (function(s, i){
  146. i = s.length;
  147. while(i--)
  148. s[i].parentNode.removeChild(s[i]);
  149. })(document.querySelectorAll('.serp-adv__head + .serp-item'), 0);
  150. (function(s){
  151. for (var l = 0; l < s.length; l++) s[l].parentNode.removeChild(s[l]);
  152. })(document.querySelectorAll(['#adbanner',
  153. '.serp-adv',
  154. '.b-spec-adv',
  155. 'div[class*="serp-adv__"]'].join(',')));
  156.  
  157. // Search ads
  158. var removeAds = function() {
  159. var s = document.querySelectorAll(['.serp-block',
  160. '.serp-item',
  161. '.search-item'].join(','));
  162. for (var l = 0; l < s.length; l++) {
  163. var i = s[l].querySelector(['.label',
  164. '.serp-item__label',
  165. '.document__provider-name'].join(','));
  166. if (!i) continue;
  167. if (i.textContent.indexOf('Реклама') > -1 || i.textContent.indexOf('Яндекс.Директ') > -1){
  168. s[l].parentNode.removeChild(s[l]);
  169. console.log('Ads removed.');
  170. }
  171. }
  172. };
  173.  
  174. // News ads
  175. var removeNewsAds = function() {
  176. var s = document.querySelectorAll(['.story[id]',
  177. '.document[id]',
  178. '.story__group[id]'].join(','));
  179. for (var l = 0; l < s.length; l++)
  180. if (win.getComputedStyle(s[l]).position === 'absolute') {
  181. s[l].parentNode.removeChild(s[l]);
  182. console.log('Ads removed.');
  183. }
  184. };
  185. // News fixes
  186. var removePageAdsClass = function() {
  187. if (document.body.classList.contains("b-page_ads_yes")){
  188. document.body.classList.remove("b-page_ads_yes");
  189. console.log('Page ads class removed.');
  190. }
  191. };
  192.  
  193. // Attaches observer to the page elements which Yandex updates via AJAX to display new search or news results
  194. var pageUpdateObserver = function(func, obj, params) {
  195. if (obj)
  196. new MutationObserver(func).observe(obj,(params?params:{childList:true}));
  197. };
  198.  
  199. if (win.location.hostname.search(/^news\./i) === 0) {
  200. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  201. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  202. removeNewsAds();
  203. removePageAdsClass();
  204. } else {
  205. pageUpdateObserver(removeAds, document.querySelector('.main__content'));
  206. removeAds();
  207. }
  208. });
  209. else
  210. // all the other cases
  211. document.addEventListener ("DOMContentLoaded", function() {
  212. // function to search and remove nodes by conten
  213. // selector - standard CSS selector to define set of nodes to check
  214. // words - regular expression to check content of the suspicious nodes
  215. // params - object with multiple extra parameters:
  216. // .parent - parent node to remove if content is found in the child node
  217. // .siblings - number of simling nodes to remove (excluding text nodes)
  218. function scissors (selector, words, scope, params) {
  219. var nodes = scope.querySelectorAll(selector),
  220. i = nodes.length,
  221. toRemove = [];
  222.  
  223. while (i--)
  224. if (words.test(nodes[i].innerHTML) || !nodes[i].childNodes.length) {
  225. var node = nodes[i],
  226. siblings = Math.abs(params.siblings) || 0,
  227. iterFunc = params.siblings > 0 ? 'nextSibling' : 'previousSibling';
  228. // drill up to the specified parent node if required
  229. if (params.parent)
  230. while(node !== scope &&
  231. node.tagName.toLowerCase() !== params.parent)
  232. node = node.parentNode;
  233. if (node === scope)
  234. break;
  235. toRemove.push(node);
  236. // add multiple nodes if defined more than one sibling
  237. while (siblings) {
  238. node = node[iterFunc];
  239. toRemove.push(node);
  240. if (node.tagName) siblings--; //don't count text nodes
  241. }
  242. }
  243. i = toRemove.length;
  244. while(i--)
  245. toRemove[i].parentNode.removeChild(toRemove[i]);
  246.  
  247. return toRemove.length;
  248. }
  249.  
  250. // function to perform multiple checks if ads inserted with a delay
  251. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  252. // also does 1 extra check when a page completely loads
  253. // selector and words - passed dow to scissors
  254. // params - object with multiple extra parameters:
  255. // .root - selector to narrow down scope to scan
  256. // .watch - if true then check will be performed continuously
  257. // .parent - passed down to scissors
  258. // .siblings - passed down to scissors
  259. function gardener(selector, words, params) {
  260. params = params || {};
  261. var scope = document.body,
  262. nonstop = false;
  263. // narrow dowsn scope to a specific element
  264. if (params.root) {
  265. scope = scope.querySelector(params.root);
  266. if (!scope) // exit if the root element is not present on the page
  267. return 0;
  268. }
  269. // add watch mode if required
  270. if (params.watch) {
  271. if (win.MutationObserver) {
  272. var o = new MutationObserver(function(ms){
  273. ms.forEach(function(m){
  274. if (m.addedNodes.length)
  275. scissors(selector, words, scope, params);
  276. });
  277. });
  278. o.observe(document.querySelector(params.root),
  279. {childList:true, subtree: true});
  280. } else nonstop = true;
  281. }
  282. // watch for a full page load to do one extra cut
  283. win.addEventListener('load',function(){
  284. scissors(selector, words, scope, params);
  285. });
  286. // do multiple cuts until ads removed
  287. function cut(sci, s, w, sc, p, i) {
  288. if (i > 0) i--;
  289. if (i && !sci(s, w, sc, p))
  290. setTimeout(cut, 100, sci, s, w, sc, p, i);
  291. }
  292. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  293. }
  294.  
  295. var scripts = {};
  296. scripts['fs.to'] = function() {
  297. function skipClicker(i) {
  298. if (!i) return;
  299. var skip = document.querySelector('.b-aplayer-banners__close');
  300. if (skip)
  301. skip.click();
  302. else
  303. setTimeout(skipClicker, 100, i-1);
  304. }
  305. setTimeout(skipClicker, 100, 30);
  306.  
  307. var divs = document.getElementsByTagName('div');
  308. var re = /\w{1,5}\d{1,5}\w{1,5}\d{1,5}/;
  309. for(var i = 0; i < divs.length; i++)
  310. if(re.test(divs[i].className))
  311. divs[i].style.display = 'none';
  312.  
  313. var style = document.head.appendChild( document.createElement('style') );
  314. style.type = 'text/css';
  315.  
  316. style.sheet.insertRule([
  317. '.b-aplayer-teasers > a',
  318. '.b-player-popup__content > div[class][style="position: relative;"]',
  319. 'div[class^="b-adproxy"]',
  320. 'div[id^="admixer_async_"]'
  321. ].join(',')+'{display:none!important}', 0);
  322.  
  323. if (/\/view_iframe\//i.test(document.location.pathname)) {
  324. var p = document.querySelector('#player:not([preload="auto"])'),
  325. m = document.querySelector('.main'),
  326. adStepper = function(p) {
  327. if (p.currentTime < p.duration)
  328. p.currentTime++;
  329. },
  330. cl = function(p) {
  331. function skipListener() {
  332. p.pause();
  333. if (!p.classList.contains('m-hidden'))
  334. p.classList.add('m-hidden');
  335. setTimeout(adStepper, 1000, p);
  336. }
  337. p.addEventListener('timeupdate', skipListener, false);
  338. },
  339. o = new MutationObserver(function (mut) {
  340. mut.forEach(function (e) {
  341. for (var i = 0; i < e.addedNodes.length; i++) {
  342. if (e.addedNodes[i].id === 'player' &&
  343. e.addedNodes[i].nodeName === 'VIDEO' &&
  344. e.addedNodes[i].getAttribute('preload') != 'auto') {
  345. cl(e.addedNodes[i]);
  346. }
  347. }
  348. });
  349. });
  350. if (p.nodeName === 'VIDEO')
  351. cl(p);
  352. else
  353. o.observe(m, {childList: true});
  354. }
  355. };
  356. scripts['brb.to'] = scripts['fs.to'];
  357. scripts['cxz.to'] = scripts['fs.to'];
  358.  
  359. scripts['fishki.net'] = function() {
  360. gardener('.main-post', /543769|Реклама/);
  361. };
  362.  
  363. scripts['hdrezka.me'] = function() {
  364. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  365.  
  366. };
  367.  
  368. scripts['yap.ru'] = function() {
  369. var words = /member1438|Administration/;
  370. gardener('form > table[id^="p_row_"]', words);
  371. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  372. };
  373. scripts['yaplakal.com'] = scripts['yap.ru'];
  374.  
  375. scripts['auto.ru'] = function() {
  376. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  377. var userAdsListAds = [
  378. '.listing-list > .listing-item',
  379. '.listing-item_type_fixed.listing-item'
  380. ];
  381. var catalogAds = [
  382. 'div[class*="layout_catalog-inline"]',
  383. 'div[class$="layout_horizontal"]'
  384. ];
  385. var otherAds = [
  386. '.advt_auto',
  387. '.sidebar-block',
  388. '.pager-listing + div[class]',
  389. '.card > div[class][style]',
  390. '.sidebar > div[class]',
  391. '.main-page__section + div[class]',
  392. '.listing > tbody'];
  393. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', watch:true});
  394. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', watch:true});
  395. gardener(otherAds.join(','), words);
  396. };
  397.  
  398. scripts['online.anidub.com'] = function() {
  399. var script = document.createElement('script');
  400. script.type = "text/javascript";
  401. script.innerHTML = "function ogonekstart1() {}";
  402. document.getElementsByTagName('head')[0].appendChild(script);
  403.  
  404. var style = document.createElement('style');
  405. style.type = 'text/css';
  406. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  407. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  408. document.head.appendChild(style);
  409. };
  410.  
  411. var domain = document.domain;
  412. while (domain.indexOf('.') + 1) {
  413. if (domain in scripts) {
  414. scripts[domain]();
  415. break;
  416. }
  417. domain = domain.slice(domain.indexOf('.') + 1);
  418. }
  419. });
  420. })();