RU AdList JS Fixes

try to take over the world!

当前为 2016-08-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 1.0.32
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var win = unsafeWindow || window;
  16. function inIFrame() {
  17. try {
  18. return win.self !== win.top;
  19. } catch (e) {
  20. return true;
  21. }
  22. }
  23.  
  24. if (!(/firefox/i.test(navigator.userAgent))) { // scripts for non-Firefox browsers
  25.  
  26. // https://gf.qytechs.cn/scripts/19144-websuckit/
  27. (function() {
  28. var to_block = [
  29. '||bgrndi.com^',
  30. '||brokeloy.com^',
  31. '||dreadfula.ru^',
  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. '||recreativ.ru^',
  44. '||regpole.com^',
  45. '||torvind.com^',
  46. '||trafmag.com^',
  47. '||xxuhter.ru^'
  48. ];
  49. var masks = [];
  50. to_block.forEach(function(m){
  51. masks.push(new RegExp(
  52. m.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  53. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  54. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  55. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  56. 'i'));
  57. });
  58. var ws = window.WebSocket;
  59. function wsGetter(tgt, nm) {
  60. console.log('[WSI] Registered call to property "', nm, '"');
  61. var closingFunctions = ['close', 'send'];
  62. try {
  63. if (typeof ws.prototype[nm] === 'function') {
  64. if (closingFunctions.indexOf(nm) > -1) {
  65. tgt.readyState = ws.CLOSED;
  66. }
  67. return function(){};
  68. }
  69. if (typeof ws.prototype[nm] === 'number') {
  70. return ws[nm];
  71. }
  72. } catch(e) {}
  73. return tgt[nm];
  74. }
  75. window.WebSocket = new Proxy(ws, {
  76. construct: function(e,i) {
  77. var url = i[0];
  78. console.log('[WSI] Opening socket on', url, '…');
  79. var j = masks.length;
  80. while(j--) {
  81. if (masks[j].test(url)) {
  82. console.log("[WSI] Blocked.");
  83. return new Proxy({url: url, readyState: ws.OPEN}, {
  84. get: wsGetter
  85. });
  86. }
  87. }
  88. return new e(i[0],i[1]);
  89. }
  90. });
  91. })();
  92.  
  93. // https://gf.qytechs.cn/scripts/14720-it-s-not-important
  94. (function(){
  95. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  96. rplsf = function(str,grp){return grp;};
  97.  
  98. function unimportanter(el, si) {
  99. if (!imptt.test(si) || el.style.display == 'none')
  100. return 0; // get out if we have nothing to do here
  101. if (el.nodeName === 'IFRAME' && el.src &&
  102. el.src.slice(0,17) === 'chrome-extension:')
  103. return 0; // Web of Trust uses this method to add their frame
  104. var so = si.replace(imptt, rplsf), ret = 0;
  105. if (si != so) {
  106. ret = 1;
  107. el.setAttribute('style', so);
  108. }
  109. return ret;
  110. }
  111.  
  112. function logger(c) {
  113. if (c) console.log('Some page elements became a bit less important.');
  114. }
  115.  
  116. function checkTarget(m, c) {
  117. var si = m.getAttribute ? m.getAttribute('style') : null;
  118. if (si && si.indexOf('!') > -1)
  119. c+=unimportanter(m, si);
  120. return c;
  121. }
  122.  
  123. function checkNodes(m, c) {
  124. var i = m.length;
  125. while(i--)
  126. c = checkTarget(m[i], c);
  127. return c;
  128. }
  129.  
  130. var observer = new MutationObserver(function(mutations) {
  131. setTimeout(function(m) {
  132. var i = m.length, c = 0;
  133. while(i--) {
  134. if (m[i].target)
  135. c = checkTarget(m[i].target, c);
  136. if (m[i].addedNodes.length)
  137. c = checkNodes(m[i].addedNodes, c);
  138. }
  139. logger(c);
  140. },0,mutations);
  141. });
  142.  
  143. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  144.  
  145. win.addEventListener ("load", function(){
  146. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  147. while(i--) {
  148. c+= checkTarget(imp[i], c);
  149. }
  150. logger(c);
  151. }, false);
  152. })();
  153.  
  154. }
  155.  
  156. // https://gf.qytechs.cn/en/scripts/21937-moonwalk-hdgo-kodik-fix
  157. (function () {
  158. if (!inIFrame)
  159. return;
  160.  
  161. document.addEventListener ("DOMContentLoaded", function() {
  162. var player;
  163. if (win.iframe_adv_enabled !== undefined) {
  164. win.iframe_adv_enabled = false;
  165. } else if (win.banner_second !== undefined) {
  166. win.banner_second = 0;
  167. player = document.getElementById('play-player-hd');
  168. if (player) player.onclick = function() {
  169. var adsdiv = document.getElementById("ads-player-hd");
  170. adsdiv.parentNode.removeChild(adsdiv);
  171. win.setPlayer();
  172. };
  173. } else if (win.MXoverrollCallback !== undefined) {
  174. player = document.getElementsByClassName('play_button')[0];
  175. if (player) player.onclick = function() {
  176. win.MXoverrollCallback();
  177. };
  178. }
  179. },false);
  180. })();
  181.  
  182. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href))
  183. // https://gf.qytechs.cn/en/scripts/809-no-yandex-ads
  184. document.addEventListener ("DOMContentLoaded", function() {
  185. // Generic ads removal and fixes
  186. (function(s){
  187. if (s) s.style.marginTop='0';
  188. })(document.querySelector('.serp-header'));
  189. (function(s, i){
  190. i = s.length;
  191. while(i--)
  192. s[i].parentNode.removeChild(s[i]);
  193. })(document.querySelectorAll('.serp-adv__head + .serp-item'), 0);
  194. (function(s){
  195. for (var l = 0; l < s.length; l++) s[l].parentNode.removeChild(s[l]);
  196. })(document.querySelectorAll(['#adbanner',
  197. '.serp-adv',
  198. '.b-spec-adv',
  199. 'div[class*="serp-adv__"]'].join(',')));
  200.  
  201. // Search ads
  202. var removeAds = function() {
  203. var s = document.querySelectorAll(['.serp-block',
  204. '.serp-item',
  205. '.search-item'].join(','));
  206. for (var l = 0; l < s.length; l++) {
  207. var i = s[l].querySelector(['.label',
  208. '.serp-item__label',
  209. '.document__provider-name'].join(','));
  210. if (!i) continue;
  211. if (i.textContent.indexOf('Реклама') > -1 || i.textContent.indexOf('Яндекс.Директ') > -1){
  212. s[l].parentNode.removeChild(s[l]);
  213. console.log('Ads removed.');
  214. }
  215. }
  216. };
  217.  
  218. // News ads
  219. var removeNewsAds = function() {
  220. var s = document.querySelectorAll(['.story[id]',
  221. '.document[id]',
  222. '.story__group[id]'].join(','));
  223. for (var l = 0; l < s.length; l++)
  224. if (win.getComputedStyle(s[l]).position === 'absolute') {
  225. s[l].parentNode.removeChild(s[l]);
  226. console.log('Ads removed.');
  227. }
  228. };
  229. // News fixes
  230. var removePageAdsClass = function() {
  231. if (document.body.classList.contains("b-page_ads_yes")){
  232. document.body.classList.remove("b-page_ads_yes");
  233. console.log('Page ads class removed.');
  234. }
  235. };
  236.  
  237. // Attaches observer to the page elements which Yandex updates via AJAX to display new search or news results
  238. var pageUpdateObserver = function(func, obj, params) {
  239. if (obj)
  240. new MutationObserver(func).observe(obj,(params?params:{childList:true}));
  241. };
  242.  
  243. if (win.location.hostname.search(/^news\./i) === 0) {
  244. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  245. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  246. removeNewsAds();
  247. removePageAdsClass();
  248. } else {
  249. pageUpdateObserver(removeAds, document.querySelector('.main__content'));
  250. removeAds();
  251. }
  252. });
  253. else
  254. // all the other cases
  255. document.addEventListener ("DOMContentLoaded", function() {
  256. // function to search and remove nodes by conten
  257. // selector - standard CSS selector to define set of nodes to check
  258. // words - regular expression to check content of the suspicious nodes
  259. // params - object with multiple extra parameters:
  260. // .parent - parent node to remove if content is found in the child node
  261. // .siblings - number of simling nodes to remove (excluding text nodes)
  262. function scissors (selector, words, scope, params) {
  263. var nodes = scope.querySelectorAll(selector),
  264. i = nodes.length,
  265. toRemove = [];
  266.  
  267. while (i--)
  268. if (words.test(nodes[i].innerHTML) || !nodes[i].childNodes.length) {
  269. var node = nodes[i],
  270. siblings = Math.abs(params.siblings) || 0,
  271. iterFunc = params.siblings > 0 ? 'nextSibling' : 'previousSibling';
  272. // drill up to the specified parent node if required
  273. if (params.parent)
  274. while(node !== scope &&
  275. node.tagName.toLowerCase() !== params.parent)
  276. node = node.parentNode;
  277. if (node === scope)
  278. break;
  279. toRemove.push(node);
  280. // add multiple nodes if defined more than one sibling
  281. while (siblings) {
  282. node = node[iterFunc];
  283. toRemove.push(node);
  284. if (node.tagName) siblings--; //don't count text nodes
  285. }
  286. }
  287. i = toRemove.length;
  288. while(i--)
  289. toRemove[i].parentNode.removeChild(toRemove[i]);
  290.  
  291. return toRemove.length;
  292. }
  293.  
  294. // function to perform multiple checks if ads inserted with a delay
  295. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  296. // also does 1 extra check when a page completely loads
  297. // selector and words - passed dow to scissors
  298. // params - object with multiple extra parameters:
  299. // .root - selector to narrow down scope to scan;
  300. // .observe - if true then check will be performed continuously;
  301. // .parent - passed down to scissors;
  302. // .siblings - passed down to scissors;
  303. function gardener(selector, words, params) {
  304. params = params || {};
  305. var scope = document.body,
  306. nonstop = false;
  307. // narrow dowsn scope to a specific element
  308. if (params.root) {
  309. scope = scope.querySelector(params.root);
  310. if (!scope) // exit if the root element is not present on the page
  311. return 0;
  312. }
  313. // add observe mode if required
  314. if (params.observe) {
  315. if (typeof MutationObserver == 'function') {
  316. var o = new MutationObserver(function(ms){
  317. ms.forEach(function(m){
  318. if (m.addedNodes.length)
  319. scissors(selector, words, scope, params);
  320. });
  321. });
  322. o.observe(document.querySelector(params.root),
  323. {childList:true, subtree: true});
  324. } else nonstop = true;
  325. }
  326. // wait for a full page load to do one extra cut
  327. win.addEventListener('load',function(){
  328. scissors(selector, words, scope, params);
  329. });
  330. // do multiple cuts until ads removed
  331. function cut(sci, s, w, sc, p, i) {
  332. if (i > 0) i--;
  333. if (i && !sci(s, w, sc, p))
  334. setTimeout(cut, 100, sci, s, w, sc, p, i);
  335. }
  336. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  337. }
  338.  
  339. function preventBackgroundRedirect() {
  340. console.log("Background redirect prevention enabled.");
  341. var orgOpen = win.open;
  342. win.open = function(){
  343. var loc = arguments[0];
  344. if (loc.indexOf(win.location.host) > -1 ||
  345. loc.indexOf('://') == -1) {
  346. win.addEventListener('unload',function(e){
  347. win.close();
  348. },true);
  349. }
  350. orgOpen.apply(window, arguments);
  351. };
  352. }
  353.  
  354. var scripts = {};
  355. scripts['fs.to'] = function() {
  356. function skipClicker(i) {
  357. if (!i) return;
  358. var skip = document.querySelector('.b-aplayer-banners__close');
  359. if (skip)
  360. skip.click();
  361. else
  362. setTimeout(skipClicker, 100, i-1);
  363. }
  364. setTimeout(skipClicker, 100, 30);
  365.  
  366. var divs = document.getElementsByTagName('div');
  367. var re = /\w{1,5}\d{1,5}\w{1,5}\d{1,5}/;
  368. for(var i = 0; i < divs.length; i++)
  369. if(re.test(divs[i].className))
  370. divs[i].style.display = 'none';
  371.  
  372. var style = document.head.appendChild( document.createElement('style') );
  373. style.type = 'text/css';
  374.  
  375. style.sheet.insertRule([
  376. '.b-aplayer-teasers > a',
  377. '.b-player-popup__content > div[class][style="position: relative;"]',
  378. 'div[class^="b-adproxy"]',
  379. 'div[id^="admixer_async_"]'
  380. ].join(',')+'{display:none!important}', 0);
  381.  
  382. if (/\/view_iframe\//i.test(document.location.pathname)) {
  383. var p = document.querySelector('#player:not([preload="auto"])'),
  384. m = document.querySelector('.main'),
  385. adStepper = function(p) {
  386. if (p.currentTime < p.duration)
  387. p.currentTime++;
  388. },
  389. adSkipper = function(f, p) {
  390. f.click();
  391. p.waitAfterSkip = false;
  392. console.log('Пропущена.');
  393. },
  394. cl = function(p) {
  395. var faster = document.querySelector('.b-aplayer__html5-desktop-skip');
  396.  
  397. function skipListener() {
  398. if (p.waitAfterSkip) {
  399. console.log('Доступен быстрый пропуск рекламы…');
  400. return;
  401. }
  402. p.pause();
  403. if (!p.classList.contains('m-hidden'))
  404. p.classList.add('m-hidden');
  405. if (faster &&
  406. window.getComputedStyle(faster).display == 'block' &&
  407. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  408. p.waitAfterSkip = true;
  409. setTimeout(adSkipper, 1000, faster, p);
  410. } else
  411. setTimeout(adStepper, 1000, p);
  412. }
  413.  
  414. p.addEventListener('timeupdate', skipListener, false);
  415. },
  416. o = new MutationObserver(function (mut) {
  417. mut.forEach(function (e) {
  418. for (var i = 0; i < e.addedNodes.length; i++) {
  419. if (e.addedNodes[i].id === 'player' &&
  420. e.addedNodes[i].nodeName === 'VIDEO' &&
  421. e.addedNodes[i].getAttribute('preload') != 'auto') {
  422. cl(e.addedNodes[i]);
  423. }
  424. }
  425. });
  426. });
  427. if (p.nodeName === 'VIDEO')
  428. cl(p);
  429. else
  430. o.observe(m, {childList: true});
  431. }
  432. };
  433. scripts['brb.to'] = scripts['fs.to'];
  434. scripts['cxz.to'] = scripts['fs.to'];
  435.  
  436. scripts['drive2.ru'] = function() {
  437. gardener('.g-column-wide > .c-block', /Реклама|\.relap\./i);
  438. };
  439.  
  440. scripts['pikabu.ru'] = function() {
  441. gardener('.story', /story__sponsor|profile\/ads"/i, {root:'.stories,.page-story', observe: true});
  442. };
  443.  
  444. scripts['fishki.net'] = function() {
  445. gardener('.main-post', /543769|Реклама/);
  446. };
  447.  
  448. scripts['hdrezka.me'] = function() {
  449. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  450. };
  451.  
  452. scripts['naruto-base.tv'] = function() {
  453. gardener('div[id^="entryID"],center', /\/goo.gl\//i);
  454. };
  455.  
  456. scripts['pb.wtf'] = function() {
  457. gardener('a[href^="/exit/"]', /data:image|<img\s.*<br>/i, {root:'#page_container', observe:true, parent:'div'});
  458. };
  459. scripts['piratbit.org'] = scripts['pb.wtf'];
  460. scripts['piratbit.ru'] = scripts['pb.wtf'];
  461.  
  462. scripts['sports.ru'] = function() {
  463. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  464. };
  465.  
  466. scripts['rustorka.com'] = function() {
  467. var s = document.head.childNodes, i = s.length;
  468. if (i < 5)
  469. while(i--)
  470. if (s[i].httpEquiv && s[i].httpEquiv=='refresh')
  471. win.close();
  472. gardener('span[class],ul[class],span[id],ul[id]', /\/\d{12,}\.php/i, {root:'#sidebar1', observe:true});
  473. gardener('div[id][style*="!important"]', /!important/i);
  474. };
  475. scripts['rumedia.ws'] = scripts['rustorka.com'];
  476.  
  477. scripts['yap.ru'] = function() {
  478. var words = /member1438|Administration/;
  479. gardener('form > table[id^="p_row_"]', words);
  480. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  481. };
  482. scripts['yaplakal.com'] = scripts['yap.ru'];
  483.  
  484. scripts['reactor.cc'] = preventBackgroundRedirect;
  485. scripts['joyreactor.cc'] = preventBackgroundRedirect;
  486. scripts['pornreactor.cc'] = preventBackgroundRedirect;
  487.  
  488. scripts['auto.ru'] = function() {
  489. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  490. var userAdsListAds = [
  491. '.listing-list > .listing-item',
  492. '.listing-item_type_fixed.listing-item'
  493. ];
  494. var catalogAds = [
  495. 'div[class*="layout_catalog-inline"]',
  496. 'div[class$="layout_horizontal"]'
  497. ];
  498. var otherAds = [
  499. '.advt_auto',
  500. '.sidebar-block',
  501. '.pager-listing + div[class]',
  502. '.card > div[class][style]',
  503. '.sidebar > div[class]',
  504. '.main-page__section + div[class]',
  505. '.listing > tbody'];
  506. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  507. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  508. gardener(otherAds.join(','), words);
  509. };
  510.  
  511. scripts['online.anidub.com'] = function() {
  512. var script = document.createElement('script');
  513. script.type = "text/javascript";
  514. script.innerHTML = "function ogonekstart1() {}";
  515. document.getElementsByTagName('head')[0].appendChild(script);
  516.  
  517. var style = document.createElement('style');
  518. style.type = 'text/css';
  519. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  520. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  521. document.head.appendChild(style);
  522. };
  523.  
  524. scripts['rsload.net'] = function() {
  525. win.addEventListener('load', function() {
  526. var dis = document.querySelector('.cb-disable');
  527. if (dis) dis.click();
  528. });
  529. document.addEventListener('click',function(e){
  530. var t = e.target;
  531. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  532. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  533. }
  534. });
  535. };
  536.  
  537. var domain = document.domain;
  538. while (domain.indexOf('.') + 1) {
  539. if (domain in scripts) {
  540. scripts[domain]();
  541. break;
  542. }
  543. domain = domain.slice(domain.indexOf('.') + 1);
  544. }
  545. });
  546. })();

QingJ © 2025

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