function linkPreview(){
    var links = document.getElementsByTagName("a");

    for (i=0; i<links.length; i++){
        var currentLink = links[i];
        var images = currentLink.getElementsByTagName("img");

        // Check if the link is an image. We don't want icons next to images.
        if (images.length == 0){
            var linkHref = currentLink.href;

            // Find all links directed to amazon.com 
            if (linkHref.match(/amazon.com/)){
                append(currentLink, "amazon");
            }
            else{
                checkLinks(linkHref, currentLink)
            }
        }
    }
}

function checkLinks(linkHref, currentLink){
    var linkHrefParts = linkHref.split(".");

    // extension is the last element in the LinkSplit array
    var extension = linkHrefParts[linkHrefParts.length - 1];

    // In some browsers there is a "/" placed after the link. removes the "/"
    extension = extension.replace("/","");
    if( extension in { doc:1, pdf:1, ppt:1, txt:1, xls:1, zip:1 } ){
        append(currentLink, extension );
    }
}

function append(currentLink, extension){
    var span = document.createElement('span');
    span.innerHTML = "&nbsp;";
    currentLink.parentNode.insertBefore(span,currentLink.nextSibling);
    span.className = extension;
}