RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址