mail.ru: clean links

Dereferences mail.ru links in emails when clicked.

נכון ליום 24-08-2014. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        mail.ru: clean links
// @namespace   lainscripts_mailru_clean_links
// @description Dereferences mail.ru links in emails when clicked.
// @author      lainverse
// @license     CC BY-SA
// @version     1.1
// @include     https://e.mail.ru/message/*
// @grant       none
// ==/UserScript==

let clb = /^http:\/\/r\.mail\.ru\/clb[0-9]+\/(.*)/i,
    cgi = /^http:\/\/e\.mail\.ru\/cgi-bin\/link\?.*&(amp;)?url=([^&]*)/i; //http:\/\/r\.mail\.ru\/clb[0-9]+\/(.*)/i,
    clearLink = function() {
      for (let x in this)
        if (x.indexOf('__originUrl') > -1) {
          let res = cgi.exec(this[x]);
          if (res) this[x] = decodeURIComponent(res[2]);
          res = clb.exec(this[x]);
          if (res) this[x] = 'http://' + res[1];
          this.href = this[x];
        }
    },
    task = function () {
      let links = document.querySelectorAll('A[href^="http://r.mail.ru/clb"]:not(.fixed),A[href^="http://e.mail.ru/cgi-bin/link?"]:not(.fixed)');
      if (links.length > 0)
        for (let l of links) {
          l.classList.add("fixed");
          l.onclick = clearLink;
          console.log(l);
        }
    };

(function link_monitor() { task(); setTimeout(link_monitor, 100); })();