Dereferences mail.ru links in emails when clicked. Skips advertisement block displayed when some links are clicked.
当前为
// ==UserScript==
// @name mail.ru: clean links
// @namespace lainscripts_mailru_clean_links
// @description Dereferences mail.ru links in emails when clicked. Skips advertisement block displayed when some links are clicked.
// @author lainverse
// @license CC BY-SA
// @version 4
// @include https://e.mail.ru/*
// @grant none
// ==/UserScript==
var confirmForm = null,
locate_confirmer = function() {
confirmForm = document.querySelector('#MailRuConfirm');
if (!confirmForm) setTimeout(locate_confirmer, 100);
};
locate_confirmer();
var clb = /^https?:\/\/r\.mail\.ru\/cl[a-z][0-9]+\/(.*)/i,
cgi = /&(amp;)?url=([^&]*)/i,
clearLink = function(evt) {
evt.preventDefault();
var i, x, confirmer = function() {
if (confirmForm.style.display !== 'none')
confirmForm.querySelector('.confirm-cancel').click();
};
for (x in this)
if (x.indexOf('__originUrl') > -1) {
var 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]);
window.open(this[x], '_blank').focus();
if (confirmForm) for (i = 0; i < 10; i++) setTimeout(confirmer, i*10);
}
},
task = function () {
var links = document.querySelectorAll('#b-letter A:not(.fixed)');
if (links.length > 0)
for (var l = 0; l < links.length; l++) {
links[l].classList.add("fixed");
links[l].onclick = clearLink;
}
};
function link_monitor() { task(); setTimeout(link_monitor, 100); }
setTimeout(link_monitor, 0);