mail.ru: clean links

Dereferences mail.ru links in emails when clicked.

当前为 2014-08-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name mail.ru: clean links
  3. // @namespace lainscripts_mailru_clean_links
  4. // @include https://e.mail.ru/message/*
  5. // @version 1
  6. // @description Dereferences mail.ru links in emails when clicked.
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. let clb = /^http:\/\/r\.mail\.ru\/clb[0-9]+\/(.*)/i,
  11. cgi = /^http:\/\/e\.mail\.ru\/cgi-bin\/link\?.*&(amp;)?url=([^&]*)/i; //http:\/\/r\.mail\.ru\/clb[0-9]+\/(.*)/i,
  12. clearLink = function() {
  13. for (let x in this)
  14. if (x.indexOf('__originUrl') > -1) {
  15. let res = cgi.exec(this[x]);
  16. if (res) this[x] = decodeURIComponent(res[2]);
  17. res = clb.exec(this[x]);
  18. if (res) this[x] = 'http://' + res[1];
  19. this.href = this[x];
  20. }
  21. },
  22. task = function () {
  23. let links = document.querySelectorAll('A[href^="http://r.mail.ru/clb"]:not(.fixed),A[href^="http://e.mail.ru/cgi-bin/link?"]:not(.fixed)');
  24. if (links.length > 0)
  25. for (let l of links) {
  26. l.classList.add("fixed");
  27. l.onclick = clearLink;
  28. console.log(l);
  29. }
  30. };
  31.  
  32. (function link_monitor() { task(); setTimeout(link_monitor, 100); })();