// ==UserScript== // @name Direct links // @name:ru Прямые ссылки // @namespace FIX // @version 0.0.3 // @description Direct links out // @description:ru Замена ссылок на прямые // @author raletag // @match *://*/* // @grant unsafeWindow // @downloadURL none // ==/UserScript== (function() { 'use strict'; console.time('Direct links load'); var win = unsafeWindow || window; var impCodes = '%3B%2C%2F%3F%3A%40%26%3D%2B%24%23', impRegex = new RegExp((impCodes.replace(/%/g,'|%').replace('|','')), 'gi'), impDecoded = decodeURIComponent(impCodes), impReplacer = function(ch) { return impDecoded[impCodes.indexOf(ch.toUpperCase())/3]; }; function decodeImportant(text) { return text.replace(impRegex, impReplacer); } function Handler (e) { console.time('HandlerTime'); try { var link = e.target, url = link.href, tourl; if (!url) { while (!url && link !== this) { link = link.parentNode; url = link.href; } } link.removeEventListener('mouseenter', Handler, false); if (!url) { return true; } tourl = ((url.match(/[?&](url|r|z|to|u|go|st.link)=([^&]*)(&|$)/i)||url.match(/(\/leech_out\.php\?.:|\/phpBB2\/goto\/|\/go\/\?)(.*)/i)||[])[2]); if (!tourl) { return true; } try { tourl = decodeURIComponent(tourl); tourl = win.atob(tourl); tourl = decodeURIComponent(tourl); tourl = escape(tourl); } catch (err) { } tourl = decodeImportant(tourl); if (tourl.match(/^http(|s):\/\/([^&]*)/i)) { console.group("Direct links"); console.info(url); console.info(tourl); link.href = tourl; console.timeEnd('HandlerTime'); console.groupEnd(); } } catch (err) { console.error('Direct links error: ' + err); console.timeEnd('HandlerTime'); alert('Direct links error: ' + err); return true; } return true; } function attachEvent (e) { var links = e.querySelectorAll('a[href]'); for (var i = links.length - 1; i >= 0; --i) { links[i].addEventListener('mouseenter', Handler, false); } } attachEvent(document); document.addEventListener('DOMNodeInserted',function(e){ if (e.currentTarget) attachEvent(e.currentTarget); }); console.timeEnd('Direct links load'); })();