/* austlii.js
* Bookmarklet to add annotation tools to AustLII cases.
* Invoke with:
* javascript:var d=document;var s=d.createElement("script");s.src="http://splintax.ucc.asn.au/austlii/austlii.js";s.type="text/javascript";d.getElementsByTagName('head').item(0).appendChild(s); */
window.austlii = {
VERSION: '0.1',
load: function(url, cb) {
// Load an arbitrary JavaScript file and fire cb.
var s = document.createElement("script");
s.src = url; s.type = "text/javascript"; s.onload = cb;
document.getElementsByTagName('head').item(0).appendChild(s); return;
},
style: function(url) {
// dynamically add a new stylesheet
var s = document.createElement("link");
s.rel = "stylesheet"; s.type = "text/css"; s.href = url;
document.getElementsByTagName('head').item(0).appendChild(s); return;
},
init: function() {
if (window.location.host.slice(-14) != "austlii.edu.au" ||
window.location.pathname.slice(0,10) != "/au/cases/" ||
window.location.pathname.slice(-5) != ".html")
console.log("You're not looking at a case on AustLII.");
else
austlii.main();
},
prune: function() {
// Remove all but the newest script tag containing the queries passed in as arguments.
for (var i = 0; i < arguments.length; i++) {
var $els = $("head script[src*="+arguments[i]+"]");
var toRemove = $els.slice(0,-1);
if (toRemove.length > 0) {
toRemove.remove();
console.log("Removed "+toRemove.length+" stale scripts matching '"+arguments[i]+"'...");
}
}
},
};
austlii.main = function() {
// grab austlii.css from the same directory as this JavaScript
var cssUrl = $('script[src$="austlii.js"]').attr('src').replace(/austlii\.js/, "austlii.css");
austlii.style(cssUrl);
austlii.cleanup();
austlii.addMarkup();
austlii.paintMenu();
};
austlii.cleanup = function() {
// remove text nodes ([] surrounding "Download", etc)
// var textNodes = $("body").contents().filter(function(){return this.nodeType == 3;}).remove();
// remove unnecessary
s
$("br").remove();
};
austlii.addMarkup = function() {
// add back to top around header
$("h1").eq(1).wrap('');
// highlight case title
$("center i").first().parent().addClass("citation");
// find and markup judges
// var judgeExp = /([A-Zc]+\s)([A-Zc,\s]+\sC?JJ?\.)/g;
var judgeExp = /([A-Z]{3})((?:[A-Z\s,]| )+C?J?J\.)/g
var replacementText = document.body.innerHTML.replace(judgeExp, '$1$2');
document.body.innerHTML = replacementText;
};
austlii.paintMenu = function() {
// create menu
var $menu = $('