Whats is wrong with this js code?!? MAss PageRank Analyzer

Discussion in 'JavaScript' started by articuno, Feb 2, 2010.

  1. #1
    var url_list = new Array();
    var active_request = null;
    var canceled = false;
    var active_xhr = null;
    var total_urls = 0, current_result = 0, successful_results = 0, failed_results = 0;
    var hours = 0, minutes = 0, seconds = 0;

    function init () {
    $('#form').submit(convert_urls);
    $('#cancel').click(cancel_operation);
    $('#submit').attr('disabled', false);
    }

    function convert_urls () {
    clear_stats();
    clear_time();
    canceled = false;
    $('#submit').attr('disabled', true);
    $('#cancel').css('display', 'inline-block');
    $('#status').html('Analyzing URLs...');
    $.post('index.php', $(this).serialize(), convert_urls_callback, 'json');
    return false;
    }

    function convert_urls_callback (data, status) {
    if (data.error) {
    alert('You did not enter any URLs');
    } else {
    $('#results').css('display', 'block');
    for (i = 0; i < data.urls.length; i++) {
    total_urls++;
    var url = new Array();
    url['url'] = data.urls['url'];
    url['converted_url'] = data.urls['converted_url'];
    url_list[url_list.length] = url;
    }
    check_urls(3);
    }
    update_stats();
    update_time();
    }

    function check_urls (count) {
    var urls = new Array();
    var converted_urls = new Array();
    count = count > url_list.length ? url_list.length : count;
    for (i = 0; i < count; i++) {
    urls[urls.length] = url_list['url'];
    converted_urls[converted_urls.length] = url_list['converted_url'];
    }
    if (count) {
    url_list = url_list.slice(count);
    active_request = $.ajax({
    url: 'index.php?action=check_pagerank',
    success: result_callback,
    dataType: 'json',
    xhr: set_active_xhr
    });
    }
    }

    function set_active_xhr (xhr) {
    active_xhr = new XMLHttpRequest();
    return active_xhr;
    }

    function result_callback (data, status, obj) {
    if (canceled) {
    data.abort();
    return false;
    }
    if (data.results.length) {
    for (i = 0; i < data.results.length; i++) {
    current_result++;
    successful_results++;
    var result = data.results;
    $('#live_results').append(<'option>' + result.url + ' - PageRank: ' + result.pagerank);
    }
    if (data.check_more) {
    window.setTimeout('check_urls(3)', 500);
    } else {
    cancel_operation();
    }
    }
    if (data.failed.length) {
    for (i = 0; i < data.failed.length; i++) {
    current_result++;
    failed_results++;
    var url = data.failed;
    $('#live_results').append('<option value="' + url + '" ondblclick="check_banned(this.value);" class="red">' + url + ' failed to check after 5 attempts &mdash; Most likely banned (dbl click here to check)');
    }
    }
    }

    function check_banned (url) {
    window.open('http://onlinealley.com/seotools/googlebannedchecker/check_banded_checker.php?url=' + escape(url) + '&Submit=View+%2F+Check');
    }


    function cancel_operation () {
    active_xhr.abort();
    canceled = true;
    delete(active_request);
    active_request = null;
    $('#submit').attr('disabled', false);
    $('#cancel').css('display', 'none');
    $('#status').html('Operation stopped');
    }

    function update_stats () {
    $('#current').html(current_result);
    $('#total').html(total_urls);
    $('#percent').html(Math.ceil(current_result / total_urls * 100) + '%');
    $('#time').html(get_time());
    $('#successful').html(successful_results);
    $('#failed').html(failed_results);
    if (!canceled) {
    window.setTimeout('update_stats()', 1000);
    }
    }

    function clear_stats () {
    total_urls = 0;
    current_result = 0;
    successful_results = 0;
    failed_results = 0;
    }

    function update_time () {
    if (++seconds == 60) {
    seconds = 0;
    if (++minutes == 60) {
    minutes = 0;
    ++hour;
    }
    }
    if (!canceled) {
    window.setTimeout('update_time()', 1000);
    }
    }

    function clear_time () {
    hours = 0;
    minutes = 0;
    seconds = 0;
    }

    function get_time () {
    return (hours ? hours + ':' : '') + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
    }

    $(document).ready(init);
     
    articuno, Feb 2, 2010 IP
  2. deuterium

    deuterium Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have got to be kidding me.....
     
    deuterium, Feb 3, 2010 IP
  3. Bween

    Bween Peon

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ^ ^ I agree with this
     
    Bween, Feb 3, 2010 IP
  4. deuterium

    deuterium Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not just that, but I am working on a script that uses this code, so where did you get this from...
     
    deuterium, Feb 3, 2010 IP
  5. articuno

    articuno Well-Known Member

    Messages:
    261
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #5
    It was for a client I was working with. We had problems with this code
     
    articuno, Feb 4, 2010 IP
  6. deuterium

    deuterium Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well from what I can see, there seems to be no issue with the javascript code.

    What issue did you see?
     
    deuterium, Feb 5, 2010 IP