RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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