BLiC

HTML

<div id="output"></div>

JavaScript

"use strict";

var blic = function(out_target, url, depth, nthreads, nfails){
    if (url === null || url.length < 1){
        window.console.error('usage error: the URL must be provided.')
        return
    }
    this.out_target = out_target
    this.url = url
    this.depth = depth
    this.nthreads = nthreads
    this.nfails = nfails
    this.results = []
}

blic.API_ENDPOINT = ['//localhost/check','//powerful-spire-40053.herokuapp.com/check'][0];

blic.prototype.getUrl = function(){
    var res = [this.API_ENDPOINT]
    res.push('?url='+this.url)
    res.push(this.depth && this.depth.length > 0 ? '&depth='+this.depth : '')
    res.push(this.nthreads && this.nthreads.length > 0 ? '&nthreads='+this.nthreads : '')
    res.push(this.nfails && this.nfails.length > 0 ? '&nfails='+this.nfails : '')
    return res.join('')
}

blic.prototype.check = function(){
    window.console.log('getting data');
    $.get(this.getUrl())
    .done(function(data){
        if (!data || !data.length || data.length < 1){
            $(this.out_target).text('no data!');
            return;
        }
        $(this.out_target).empty();


        this.results = data
        window.console.log('got data:', data)
        $(this.out_target).text(this.results)

    });
}


  (function(){
     var b = new blic('#output', 'http://kylefalconercodes.com')
     b.check()
   })()