// ==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.0 // @include https://e.mail.ru/* // @grant none // @downloadURL none // ==/UserScript== let clb = /^https?:\/\/r\.mail\.ru\/cl[a-z][0-9]+\/(.*)/i, cgi = /&(amp;)?url=([^&]*)/i, lastLink = null, 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]); } while (res); res = clb.exec(this[x]); if (res) this[x] = 'http://' + res[1]; this.href = this[x]; lastLink = this[x]; console.log("Dereferenced link:", this[x]); } }, 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; } }, confirmerObserver = new MutationObserver(function(mt) { for (let m of mt) { if (m.target.style.display !== 'none') { console.log('pop'); m.target.querySelector('.confirm-cancel').click(); window.open(lastLink, '_blank').focus(); break; } } }); function link_monitor() { task(); setTimeout(link_monitor, 100); }; setTimeout(link_monitor, 0); (function locate_confirmer() { let confirmer = document.querySelector('#MailRuConfirm'); if (confirmer) confirmerObserver.observe(confirmer, {attributes:true}); else setTimeout(locate_confirmer, 100); })();