Sunday, 4 November 2012

// Calculate wordiness of blog authors: function onLoadFeed(data) { if (data.rc != 200) { w(["Error loading blog data"]); return; } var feed = data.data.feed; var word_counts = new Array(); var wordiness = new Array(); for (var i = 0; i < feed.entry.length; i++) { var entry = feed.entry[i]; var word_count = entry.content.$t.split(/\s/).length; var osid = getOpenSocialId(entry.author[0]); var author = entry.author[0].name.$t; var authorid = getOpenSocialId(entry.author[0]); var key = [author,authorid]; if (wordiness[key]==undefined) wordiness[key] = word_count; else wordiness[key] += word_count; } var disp = new Array(); for (var k in wordiness) { disp.push(k + " : " + wordiness[k] + " words"); } w(disp); } // Return the OpenSocial ID for an author if available function getOpenSocialId(person) { var extendedProperty = person.gd$extendedProperty; if (extendedProperty && extendedProperty.name == "OpenSocialUserId") { return extendedProperty.value; } else { return null; } } // Write output to a display element on the gadget function w(arr) { var str = "
    "; for (var e in arr) { str += "
  • "+arr[e]+"
  • "; } str += "
"; document.getElementById('display').innerHTML = str; }

No comments:

Post a Comment