Remove Yandex Redirect

Remove Yandex redirect in search, news and mail

  1. // ==UserScript==
  2. // @name Remove Yandex Redirect
  3. // @name:ru Удаление редиректов на Яндексе
  4. // @namespace FIX
  5. // @version 0.4
  6. // @description Remove Yandex redirect in search, news and mail
  7. // @description:ru Удаление редиректов на Яндексе в поисковой выдаче, новостях и почте
  8. // @author raletag
  9. // @include *://yandex.*/*
  10. // @include *://*.yandex.*/*
  11. // @grant unsafeWindow
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. var win = unsafeWindow || window;
  17. if (win.top !== win.self) return;
  18.  
  19. console.time('Remove Yandex Redirect load');
  20.  
  21. function remove (e) {
  22. var links = e.querySelectorAll('a[onmousedown*="/clck/jsredir"]'), i;
  23. for (i = links.length - 1; i >= 0; --i) {
  24. links[i].removeAttribute('onmousedown');
  25. }
  26. links = e.querySelectorAll('a[data-counter]');
  27. for (i = links.length - 1; i >= 0; --i) {
  28. links[i].removeAttribute('data-counter');
  29. links[i].removeAttribute('data-bem');
  30. }
  31. links = e.querySelectorAll('a[data-vdir-href]');
  32. for (i = links.length - 1; i >= 0; --i) {
  33. links[i].removeAttribute('data-vdir-href');
  34. links[i].removeAttribute('data-orig-href');
  35. }
  36. }
  37.  
  38. remove (document.body);
  39.  
  40. var o = new MutationObserver(function(ms){
  41. ms.forEach(function(m){
  42. m.addedNodes.forEach(function(n){
  43. if (n.nodeType !== Node.ELEMENT_NODE) {
  44. return;
  45. }
  46. remove(n);
  47. });
  48. });
  49. });
  50. o.observe(document.body, {childList: true, subtree: true});
  51.  
  52. console.timeEnd('Remove Yandex Redirect load');
  53. })();