Link Changer

by Couto

HTML

<a href="/about.html" >link</a>
<a href="/lol.html" >link</a>
<a href="/zwame.html" >link</a>
<a href="/1.html" >link</a>
<a href="/3.html" >link</a>
<a href="/4324ewdasdasd.html" >link</a>
<a href="/link.html" >link</a>

JavaScript

var ChangeLinks = function() {
    var d = document,
        that = this;

    this.pageLinks = d.getElementsByTagName('a');
    this.hostname = window.location.hostname;
    this.port = 8080;

    for (var i = that.pageLinks.length; i--;) {
        var currentSrc = that.pageLinks[i].href,
            decodedSrc = currentSrc.split('/'),
            targetFile = decodedSrc[decodedSrc.length - 1];

        that.pageLinks[i].setAttribute('href', 'http://' + that.hostname + ':' + that.port + '/' + targetFile);

        //apagar linha de baixo
        that.pageLinks[i].innerHTML = 'http://' + that.hostname + ':' + that.port + '/' + targetFile;
    }
};

window.onload = new ChangeLinks();