User:Enterprisey/edit-section-on-hover.js

// vim: ts=4 sw=4 et ai // ( function {    if( mw.config.get( "wgAction" ) === "view" ) {

// Wrap every section in its own div var editSectionSpans = document.querySelectorAll( "span.mw-editsection" ); if( !editSectionSpans.length ) return; var headerEl, currEl, container; for( var i = 0; i < editSectionSpans.length; i++ ) {

headerEl = editSectionSpans[i].parentNode; if( headerEl.matches( "h1.firstHeading" ) ) continue;

// Insert container into DOM container = document.createElement( "div" ); container.className = "edit-section-on-hover"; container.dataset.hoverId = i;           headerEl.parentNode.insertBefore( container, headerEl );

// Insert all elements in the section into our container var currEl = headerEl.nextSibling; container.appendChild( headerEl ); var nextEl; while( currEl && ( currEl.nodeType !== 1 || currEl.tagName.toLowerCase.indexOf( "h" ) !== 0 ) ) { nextEl = currEl.nextSibling; container.appendChild( currEl ); currEl = nextEl; }       }

mw.loader.addStyleTag( "div.edit-section-on-hover { margin-bottom: -1.6em; padding-bottom: 1.1em }" +               "div.edit-section-on-hover .mw-editsection { display: none; }" +                "div.edit-section-on-hover:hover .mw-editsection { display: inline; }" ); } } ); //