This bookmarklet adds hierarchical section numbers to the section headers on the current confluence page. Note that it does not permanently change the content of the page; it only transforms the displayed HTML until the page is re-loaded. One of these days I'll figure out how to get this to work as a user script .
Confluence numbered section header bookmarklet
Source:
(function() {
function addSectionNumber (elem, sectionNumber, parentSection, level) {
var sectionNumberStr = '';
var sectionSpan;
if (level > 1) {
sectionNumberStr = parentSection + '.' + sectionNumber;
} else if (level > 0) {
sectionNumberStr = sectionNumber.toString();
}
if (level > 0 && jQuery(elem).find('.section-number').length === 0 ) {
sectionSpan = jQuery('<span class="section-number">').text(sectionNumberStr + ' ');
jQuery(elem).prepend(sectionSpan);
}
if ( level === 0 ) {
jQuery(elem).find('h1').each( function(index, element) {
addSectionNumber(element, (index + 1), sectionNumberStr, (level + 1));
});
} else if ( level < 6 ) {
jQuery(elem).nextUntil('h' + level, 'h' + level + ',h' + (level + 1)).each( function(index, element) {
addSectionNumber(element, (index + 1), sectionNumberStr, (level + 1));
});
}
return;
}
addSectionNumber(jQuery('#main-content').first(), 0, '', 0);
})();