// Moodle List Links user script
// version 0.1
// 2006-05-15
// Copyright (c) 2006, Sebastian Gfeller
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// ------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Moodle List Links", and click Uninstall.
//
// ------------------------------------------------------------
//
// ==UserScript==
// @name         Moodle List Links
// @namespace    http://icwww.epfl.ch/~sgfeller/gm/
// @description  Script to list all the resources of a moodle course at the bottom of its page.
// @include      http*://moodle.epfl.ch*
// ==/UserScript==

var allLinks, thisLink;
allLinks = document.evaluate(
		"//a[@title='Resource']",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);
// add an UL at the top of the moodle page with a list of all linked urls
var div = document.createElement('div');
div.id = 'linkbar-div';
var desc = '<h2>Resources dans cette page</h2><ul>';
for (var i = 0; i < allLinks.snapshotLength; i++) {
	thisLink = allLinks.snapshotItem(i);
	desc = desc + '<li><a href="';
	desc = desc + thisLink;
	desc = desc + '">' + thisLink + '</a>';
	desc = desc + '</li>';
}
desc = desc + '</ul>';
div.innerHTML = desc;
window.addEventListener(
		"load",
		function() {
			document.body.appendChild(div);
		},
		true);


