Jump to content

User:Writ Keeper/Scripts/refTooltips.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(document).ready(addRefTitles);

function addRefTitles()
{
	var refs = $('.reference');
	var reflist = $('li[id^="cite_note"]');
	var i;
	
	for(i =0; i < refs.length; i++)
	{
		var match = findMatches(refs[i], reflist);
		if(match != null)
		{
                        var newTitle = $('#' + match.id + ' > span.reference-text').text()
			refs[i].title = newTitle;
			refs[i].children[0].title = newTitle;
		}
	}
}

function findMatches(ref, reflist)
{
	var i;
	var refId = ref.id.slice(9);
	if(refId.search("_") != -1)
	{
		refId  = refId.slice(0, refId.lastIndexOf('_')) + '-' + refId.slice(refId.lastIndexOf("_")+1, refId.lastIndexOf("-"));
	}
	for(i=0; i < reflist.length; i++)
	{
		var reflistId = reflist[i].id.slice(10);
		
		if(refId == reflistId) 
		{
			return reflist[i];
		}
	}
	return null;
}