All pastes #420635 Raw Edit

Untitled

public javascript v1 · immutable
·published 2007-04-02 09:12 UTC
rendered paste body
<html><head>	<script type="text/javascript">		<!--/*1. determine random comic number   => get total count2. retrieve from random page:   - image URL   - title   - alt text3. write to document:	<h1><a href="%comicURL%">%title%</a></h1>	<img src="%imgURL%"/>	<h2>%altText%</h2>RegExMatch(pageContents, "i)<h3>URL for this image:\s(?P<URL>.*?)</h3>", img)RegExMatch(latestPage, "i)<h3>Permalink to this comic:\s(?P<URL>.*?)</h3>", page)RegExMatch(pageURL, "\d+", latestNumber)*/function initialize() {	var latestURL = "http://www.xkcd.com";	var item = getRandom(1, totalCount(latestURL));	alert(item);}function totalCount(URL) {	// initialize XmlHttp	if (typeof XMLHttpRequest != 'undefined') { // Mozilla, Opera, Safari and Internet Explorer 7	XmlHttp = new XMLHttpRequest();	}	if (!XmlHttp) { // Internet Explorer 6 and older		try {			XmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");		} catch(e) {			try {				XmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");			} catch(e) {				XmlHttp  = null;			}		}	}	// get remote document	if (XmlHttp != false) {		XmlHttp = new XMLHttpRequest();		if (XmlHttp) {			// establish connection			XmlHttp.open('GET', URL, false);			XmlHttp.send(null);			// get URL			var extract = XmlHttp.responseText.match(/<h3>Permalink to this comic:\s(.*?)<\/h3>/i);			alert(extract);			extract = extract..match(/\d+/i);			alert(extract);		}	} 	return ;}function getRandom(min, max) {			var randomNum = Math.random() * (max - min); 	return Math.round(randomNum) + min;}		-->	</script></head><body onLoad="initialize()"></body></html>