Skip to main content
2 of 7
added 14 characters in body
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

Usage examples while waiting for docs

JavaScript Site Monitor in 20 lines of code or less....

alt text http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=soapi&DownloadId=125356

$(document).ready(function siteMonitor() {

    var apiKey = '';
    var sites = ["stackoverflow", "serverfault", "superuser", "meta.stackoverflow", "stackapps"];
    var siteIndex = 0;
    var delay = 10;

    $.each(sites,
        function(idx, itm) {
            $('<div/>').addClass('stats').attr('id', itm.replace('.', '')).appendTo(document.body);
        });

    function update() {
        var client = new Soapi.Client(sites[siteIndex], apiKey)
            .Stats()
            .getResult(function(data) {
                var id = sites[siteIndex].replace('.', '');
                $('#' + id).hide().fadeIn(100).jqotesub("#template", data.statistics[0]);
-

                siteIndex++;
                if (siteIndex == sites.length) {
                    siteIndex = 0;
                    delay = 5000;
                }
                window.setTimeout(update, delay);
            });
    }

    update();
});
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60