topical media & game development
mashup-flickr-12-DOMParserExample.user.js / js
// ==UserScript==
// @name DOMParser Example
// @namespace http://www.dopiaza.org/flickr/greasemonkey/
// @description DOMParser Example
// @include http://www.flickr.com/photos/dopiaza/29900246/
// ==/UserScript==
var technoratiAPIKey = 'YOUR-TECHNORATI-API-KEY';
var url = 'http://api.technorati.com/cosmos';
var params = 'key=' + technoratiAPIKey + '&url=' + window.location.href +
'&limit=100';
GM_xmlhttpRequest(
{
method: "GET",
url: url + "?" + params,
headers:
{
"User-Agent": "Flickr-Technorati-Query"
},
onload: function(response)
{
var parser = new unsafeWindow.DOMParser();
var dom = parser.parseFromString(response.responseText, "application/xml");
var errors = dom.getElementsByTagName('error');
if (errors.length > 0)
{
GM_log ("Technorati Error:" + errors[0].firstChild.nodeValue);
}
else
{
var items = dom.getElementsByTagName('item');
if (items.length > 0)
{
for (var i = 0; i < items.length; i++)
{
var name = items[i].getElementsByTagName('name')[0];
GM_log ("Found blog:" + name.firstChild.nodeValue);
}
}
else
{
GM_log ('No blogs found');
}
}
},
onerror: function(response)
{
GM_log ("Error:" + response.status + " " + response.statusText);
GM_log (response.responseText);
}
});
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.