Greasy Fork

mail.ru: clean links

Dereferences mail.ru links in emails when clicked.

目前为 2014-08-26 提交的版本。查看 最新版本

// ==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     3.5
// @include     https://e.mail.ru/*
// @grant       none
// ==/UserScript==

let confirmForm = null,
    locate_confirmer = function() {
      confirmForm = document.querySelector('#MailRuConfirm');
      if (!confirmForm) setTimeout(locate_confirmer, 100);
    }
locate_confirmer();

let clb = /^https?:\/\/r\.mail\.ru\/cl[a-z][0-9]+\/(.*)/i,
    cgi = /&(amp;)?url=([^&]*)/i,
    clearLink = function() {
      for (let x in this)
        if (x.indexOf('__originUrl') > -1) {
          let res = null;

          do {
            res = cgi.exec(this[x]);
            if (res) this[x] = decodeURIComponent(res[2]);
            res = clb.exec(this[x]);
            if (res) this[x] = 'http://' + res[1];
          } while (res);

          this.href = this[x];
          console.log("Dereferenced link:", this[x]);

          if (confirmForm) {
            var url = this[x], i = 10,
                confirmer = function() {
                  if (i<0) return; i--;
                  if (confirmForm.style.display !== 'none') {
                    confirmForm.querySelector('.confirm-cancel').click();
                    window.open(url, '_blank').focus();
                  } setTimeout(confirmer, 10);
                };
            confirmer();
          }
        }
      
    },
    task = function () {
      let links = document.querySelectorAll('#b-letter A:not(.fixed)');
      if (links.length > 0)
        for (let l of links) {
          l.classList.add("fixed");
          l.onclick = clearLink;
        }
    };

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