2 * Bookmarklet to add annotation tools to AustLII cases.
4 * 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); */
8 load: function(url, cb) {
9 // Load an arbitrary JavaScript file and fire cb.
10 var s = document.createElement("script");
11 s.src = url; s.type = "text/javascript"; s.onload = cb;
12 document.getElementsByTagName('head').item(0).appendChild(s); return;
14 style: function(url) {
15 // dynamically add a new stylesheet
16 var s = document.createElement("link");
17 s.rel = "stylesheet"; s.type = "text/css"; s.href = url;
18 document.getElementsByTagName('head').item(0).appendChild(s); return;
21 austlii.prune("austlii", "jquery");
22 if (window.location.host.slice(-14) != "austlii.edu.au" ||
23 window.location.pathname.slice(0,10) != "/au/cases/" ||
24 window.location.pathname.slice(-5) != ".html")
25 console.log("You're not looking at a case on AustLII.");
30 // Remove all but the newest script tag containing the queries passed in as arguments.
31 for (var i = 0; i < arguments.length; i++) {
32 var $els = $("head script[src*="+arguments[i]+"]");
33 var toRemove = $els.slice(0,-1);
34 if (toRemove.length > 0) {
36 console.log("Removed "+toRemove.length+" stale scripts matching '"+arguments[i]+"'...");
42 austlii.paintMenu = function() {
44 austlii.style("http://splintax.ucc.asn.au/austlii/austlii.css");
46 // remove text nodes ([] surrounding "Download", etc)
47 var textNodes = $("body").contents().filter(function(){return this.nodeType == 3;}).remove();
48 // hide other unnecessary menu elements
49 var $els = $("body").children(); // excludes text nodes
51 while ($els[index].tagName != "H1") {
52 $els[index].style.display = "none"; index++;
55 $("h1").eq(1).wrap('<a name="top">');
57 // highlight case title
58 $("center i").first().parent().addClass("citation");
60 // find and markup judges
61 var judgeExp = /([A-Zc, ]+)(( | )C?JJ?\.)/g;
62 var replacementText = document.body.innerHTML.replace(judgeExp, '<a class="judge" name="$1">$1$2</a>');
63 document.body.innerHTML = replacementText;
66 var $menu = $('<div id="menu"><a href="#top">Top</a></div>');
67 // add jumplinks for each judge
68 var $judges = $('<ol id="judges"></ol>');
69 $("a.judge").each(function(){
70 var $li = $('<li><a href="#' + this.name + '">' + $(this).html() + '</a></li>');
72 }); $menu.append($judges);
73 // add annotation features
74 $menu.append($('<a id="trigger-highlight" href="#">Highlight</a>'));
75 $("body").append($menu);
77 // enable smooth scrolling on anchors
78 austlii.load("http://splintax.ucc.asn.au/cases/jquery.scrollTo-1.4.2-min.js", function() {
79 austlii.load("http://splintax.ucc.asn.au/cases/jquery.localscroll-1.2.7-min.js", function() {
80 $.localScroll({duration: '200'});
85 $("#trigger-highlight").click(austlii.highlight);
89 austlii.highlight = function(event) {
90 event.preventDefault();
91 var sel = document.getSelection();
92 if (sel.type == "Range") {
94 var range = sel.getRangeAt(0);
95 var $note = $('<span style="background-color: yellow;" />');
96 range.surroundContents($note[0]);
99 var $menu = $('<div style="position: absolute;" />');
100 var $removeLink = $('<a href="#">Remove</a>');
102 $menu.append($removeLink);
103 $removeLink.click((function($hilite) {
104 var text = $hilite.text();
105 $hilite.after(text).remove();
108 else {console.log("You haven't highlighted anything.")}
111 console.log("Loaded austlii.js v"+austlii.VERSION+".");
112 austlii.load('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', austlii.main);