Created
March 18, 2011 14:19
-
-
Save nhitze/876137 to your computer and use it in GitHub Desktop.
a Gadget for listing all GTUGs from gtugs.org/directory includes using YQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<Module> | |
<ModulePrefs title="GTUGs Directory Grabber" /> | |
<Content type="html"> | |
<![CDATA[ | |
<div id="content_div"></div> | |
<script type="text/javascript"> | |
function makeJSONRequest() { | |
var params = {}; | |
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; | |
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.gtugs.org%2Fdirectory.jsp%22%20and%20xpath%3D%22%2F%2Fdiv%5B%40class%3D'column'%5D%22&format=json&callback="; | |
gadgets.io.makeRequest(url, response, params); | |
}; | |
function response(obj) { | |
var jsondata = obj.data; | |
var result = jsondata.query.results.div; | |
var html = ''; | |
for (var key in result) { | |
var countries = result[key].h3; | |
var chapters = result[key].ul; | |
for(var country in countries) { | |
html += '<h3>' + countries[country] + '</h3>'; | |
html += '<ul>'; | |
if(chapters[country].li.a == undefined) { | |
for(chapter in chapters[country].li) { | |
html += '<li>' + chapters[country].li[chapter].a.content + '</li>'; | |
} | |
} else { | |
html += '<li>' + chapters[country].li.a.content + '</li>'; | |
} | |
html += '</ul>'; | |
} | |
} | |
document.getElementById('content_div').innerHTML = html; | |
}; | |
gadgets.util.registerOnLoadHandler(makeJSONRequest); | |
</script> | |
]]> | |
</Content> | |
</Module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment