User:LinguistAtLarge/custom user links.js

// ################################################################### var add_custom_user_links = function {	if (!custom_user_links || !custom_user_links.length || custom_user_links.length < 1) {		return; }

var insertion_point_cache = {}, insertion_point, i, li, link;

for (i = 0; i < custom_user_links.length; ++i) {		link = custom_user_links[i]; // cache insertion points if (insertion_point_cache[link.insert]) {			insertion_point = insertion_point_cache[link.insert]; }		else {			insertion_point = document.getElementById((link.insert == 'end' ? 'pt-logout' : link.insert)); insertion_point_cache[link.insert] = insertion_point; }		if (insertion_point && link.url && link.anchor) // url and anchor are req'd		{ li = document.createElement('li'); if (document.location.href == link.url) {				li.setAttribute('class', 'active'); }			if (link.id) {				li.setAttribute('id', link.id); }			li.innerHTML = '' + link.anchor + ''; if (link.insert == 'end') {				insertion_point.appendChild(li); }			else {				insertion_point.parentNode.insertBefore(li, insertion_point); }		}	} }; addOnloadHook(add_custom_user_links);