All pastes #1042263 Raw Edit

Unnamed

public text v1 · immutable
#1042263 ·published 2008-06-08 19:54 UTC
rendered paste body
var Fotolog = {	loadFlog: function(username, callback) {		if(!username.match(/^[a-z0-9]+$/)) {			throw new Error("Invalid username");		}		var xhr = new ActiveXObject("MSXML2.XMLHTTP");		xhr.onreadystatechange = function() {			if (xhr.readyState == 4) {				var html = Fotolog._loadHTML(xhr.responseText);				var flog = Fotolog._parseFlog(html);				callback(flog);			}		};		xhr.open("GET", "http://www.fotolog.com/"+escape(username), true);		xhr.send();	},	getLastPost: function(username, callback) {		if (!username.match(/^[a-z0-9]+$/)) {			throw new Error("Invalid username");		}		var xhr = new ActiveXObject("MSXML2.XMLHTTP");		var url = "http://www.fotolog.com/" + username + "/feed/main/rss20";		if (callback) {			xhr.open("GET", url, true);			xhr.onreadystatechange = function() {				if (xhr.readyState == 4) {					callback(Fotolog._parseRSSFlog(xhr.responseText);				}			};			xhr.send();		} else {			xhr.open("GET", url, true);			xhr.send();			return Fotolog._parseRSSFlog(xhr.responseText);		}	},	_parseRSSFlog: function(text) {		var xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");		xmldoc.loadXML(text);		xmldoc.setProperty("SelectionNamespaces", "xmlns:m='http://search.yahoo.com/mrss'");		var post = {};		var item = xmldoc.selectSingleNode("/rss/channel/item[1]");		if (item == null) {			return null;		}		var titles = item.getElementsByTagName('title');		if (titles.length < 1 || titles.item(0).text.length == 0) {			post.title == null;		} else {			post.title = titles.item(0).text;		}		var dt = item.selectSingleNode('pubDate').text;		var m = dt.match(/^(\d+)\/(\d+)\/(\d+)$/);		post.date = new Date(parseInt(m[3])+1900, parseInt(m[2])+1, parseInt(m[1]));		post.postURL = item.selectSingleNode('link').text;		post.imageURL = item.selectSingleNode('m:content').getAttribute('url');		post.description = item.selectSingleNode('m:content/m:text').text;		return post;	},	_loadHTML: function(text) {		var html = new ActiveXObject("htmlfile");		html.write(text);		html.close();		return html;	},	_parseFlog: function(dom) {		return dom.body.outerHTML;	}};var post = Fotolog.getLastPost('insertcoiiin');WScript.Echo("Fotolog: insertcoiiin");WScript.Echo("Ultimo post: " + (post.title.length > 0 ? post.title : "[sin titulo]") 			 ", fecha " + post.date.toLocaleString());WScript.Echo("Descripcion:");WScript.Echo(post.description);WScript.Echo("URL del posteo: " + post.postURL);WScript.Echo("URL directo de la imagen: " + post.imageURL);/* vim: set ts=4 sw=4 noet: */