Greasy Fork 支持简体中文。

RU AdList JS Fixes

try to take over the world!

目前為 2016-06-29 提交的版本,檢視 最新版本

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