I was initially impressed by the concept of Web Slices but since webpages have to explicitly support this, and most don’t, it ends up fairly useless. I started thinking that arbitrary slices would be much more useful and all it would take would be an AJAX call from jQuery. Recently someone asked me if it would be possible to extract the Perth weather forecast from the BOM and present the data in a HTA or Win7 gadget. A quick inspection of the source:
shows that the relevant data is within a <div id=”content”> tag. Turns out the entire code needed to extract the data and present it in a page is simply:
<html>
<head>
<title>Perth BOM Forecast</title>
<style>
body{ overflow:hidden; } // Hide scrollbars
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var url = "http://www.bom.gov.au/weather/wa/forecasts/perth.shtml";
function loadForecast() {
$.ajax({ url: url, context: document.body, success: function(html){
$bom = $(html).find("DIV#content");
$(this).find("DIV#content").html($bom.html());
}});
}
$(document).ready(function() {
loadForecast();
window.resizeTo(590, 700);
setInterval ( loadForecast, 60*60*1000 );
});
</script>
<body>
<div id="content">
</div>
</body>
</html>
Which, when put into an HTA, looks like this:

The reason for using a HTA is that, unlike HTML, it is full trust and can make the necessary ActiveX cross-site AJAX call without any warnings. A Win7 gadget behaves similarly.
However the data is returned in an inconvenient format so I used some RegEx to parse it into an array of objects and then put that into an HTA which you can download here. (may need to unblock to get it running).
See also: Chrome Extension – Arbitrary Web Slices
One Trackback
[...] see how Chrome Extensions work I revisited my Arbitrary Web Slices post. A great starting point was Google’s own Hello World extension. Indeed all I really [...]