Source for "DirectLink"

By Richard Tingstad
Has no other scripts.


// Direct Link user script
// version 0.21 BETA
// Richard H. Tingstad
//
// For every link on a web page that contains in-link URIs (e.g. 
// "http://foo.com/?u=example.com"), an anchor (link) element which refers to the contained
// URI is created and inserted just after the original link.
//
// What's the point?
// Many web pages have links which either redirect you to another URL, or embeds the target 
// page in their own frame. There may be several reasons to go directly to the target URL; 
// avoiding ugly frames with ads, not wanting to contribute to the statistics, or lowering 
// load times. Even worse is that some pages only deliver the target page with a certain 
// probability.
//
// To use this script with Firefox, you need Greasemonkey. Works with Opera as well.
//
// ==UserScript==
// @name           DirectLink
// @namespace      http://drop.by
// @description    Finds URIs that are in links and displays them (as links)
// @include        *
// ==/UserScript==
(function () {

  var directLinkCaption = "^"; // What you want the created link to be displayed as.

  var links = document.getElementsByTagName("a");
  var link = null;
  var ln = "";
  var len = links.length;

  myRe = /[^\/][%\/\?&=]([a-z\d-]+(:\/\/|%3A%2F%2F))?(\w+:?\w*@)?([a-z\d-]+\.)*((([\d]{1,3}\.){3}[\d]{1,3})|([a-z\d]+[a-z\d-]*\.(AC|AD|AE|AERO|AF|AG|AI|AL|AM|AN|AO|AQ|AR|ARPA|AS|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BIZ|BJ|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CAT|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|COM|COOP|CR|CU|CV|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EDU|EE|EG|ER|ES|ET|EU|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GOV|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|INFO|INT|IO|IQ|IR|IS|IT|JE|JM|JO|JOBS|JP|KE|KG|KH|KI|KM|KN|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|MG|MH|MIL|MK|ML|MM|MN|MO|MOBI|MP|MQ|MR|MS|MT|MU|MUSEUM|MV|MW|MX|MY|MZ|NA|NAME|NC|NE|NET|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|ORG|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PRO|PS|PT|PW|PY|QA|RE|RO|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SU|SV|SY|SZ|TC|TD|TEL|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TP|TR|TRAVEL|TT|TV|TW|TZ|UA|UG|UK|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|YU|ZA|ZM|ZW)))(:\d+)?((\/[^&\?\s]*(\?[^\?\s]*)?)|(%2F[^&\?\s]*)|$|&)/gi;

  for (var i = 0; i < len; i++) {
    link = links[i];
    if (!link) continue;
    if (link.getAttribute('class') == "directlink") continue;
    var linkUrl = link.getAttribute('href');
    var insertBefore = link.nextSibling;
    while ((myArray = myRe.exec(linkUrl)) != undefined) {
        ln = myArray[0];
        ln = ln.substring(2, ln.length);
        ln = unescape(ln);
        if (ln.indexOf('://') < 0) {
          ln = 'http://' + ln;
        }
        else if (ln.indexOf('http://') > 0) {
          ln = ln.substring(ln.indexOf('http://'), ln.length);
        }
        if (ln.charAt(ln.length-1) == '&') {
          ln = ln.substring(0, ln.length-1);
        }
        var newLink = document.createElement("a");
        var textNode = document.createTextNode(directLinkCaption);
        newLink.appendChild(textNode);
        newLink.setAttribute("href", ln);
        newLink.setAttribute("class", "directlink");
        link.parentNode.insertBefore(newLink, insertBefore);
        len++;
    }
  }
})();