Участник:Bezik/rfd-closed-backlighter.js
![](http://upload.wikimedia.org/wikipedia/commons/thumb/2/25/OOjs_UI_icon_userActive.svg/15px-OOjs_UI_icon_userActive.svg.png)
После сохранения очистите кэш браузера.
closedRFDsHiglighter = {
'init' : function() {
// Function to set up uncollapser
addUncollapser = function( targetNode, id ) {
var uncollapser = document.createElement( "div" )
uncollapser.setAttribute( "class", "closedRFD-uncollapse" );
uncollapser.innerHTML = '[<a href="javascript:closedRFDsHiglighter.uncollapse(' + id + ')">развернуть</a>]';
targetNode.appendChild( uncollapser );
}
// Setup CSS
mw.loader.load( '//ru.wikipedia.org/w/index.php?title=User:Bezik/rfd-closed-backlighter.css&action=raw&ctype=text/css', 'text/css' );
// Create divs. If targetDiv is set, all nodes will be added to it
// until the header of targetLevel (or larger) will be encountered
var root = $( "#mw-content-text" )[0];
var targetDiv = null;
var targetLevel = null;
var targetID = 0;
for( var i = 0; i < root.childNodes.length; i++ ) {
var cur = root.childNodes[i];
var isHeader = cur.nodeType == Node.ELEMENT_NODE && /H\d/.test( cur.tagName );
if( targetDiv ) {
// Addition mode
if( isHeader && parseInt( cur.tagName[1] ) <= targetLevel ) {
// End div
addUncollapser( targetDiv, targetID );
targetDiv = null;
targetLevel = null;
i--;
} else {
// Move node to div
root.removeChild( cur );
targetDiv.appendChild( cur );
$(cur).addClass( "closedRFD-collapsible" );
i--;
}
} else {
// Search mode
if( !isHeader )
continue;
if( !$( "s", cur ).length )
continue;
targetID++;
targetDiv = document.createElement( "div" );
targetDiv.setAttribute( "class", "closedRFD" );
targetDiv.setAttribute( "id", "closedRFD-div" + targetID );
targetLevel = parseInt( cur.tagName[1] );
root.insertBefore( targetDiv, cur );
root.removeChild( cur );
targetDiv.appendChild( cur );
}
}
// Handle case when last section is closed
if( targetDiv ) {
addUncollapser( targetDiv, targetID );
}
// Hide all uncollapse links
$( ".closedRFD-uncollapse" ).hide();
// Add "collapse all" link
var controlLink = document.createElement( "div" );
controlLink.setAttribute( "class", "closedRFD-control" );
controlLink.innerHTML = '[<a id="closedRFD-collapselink" href="javascript:closedRFDsHiglighter.collapseAll()">свернуть все закрытые секции</a>]'
+ ' • [<a id="closedRFD-hidelink" href="javascript:closedRFDsHiglighter.hideAll()">скрыть закрытые секции</a>]';
root.insertBefore( controlLink, root.childNodes[0] );
// If we were given a section link, it is probably screwed up now. Fix this
if( location.hash != null && location.hash != '' ) {
var tmp = location.hash;
location.hash = '';
location.hash = tmp;
}
},
'collapse' : function( id ) {
var nodeID = "#closedRFD-div" + id;
$( nodeID + " .closedRFD-collapsible" ).hide();
$( nodeID + " .closedRFD-uncollapse" ).show();
},
'uncollapse' : function( id ) {
var nodeID = "#closedRFD-div" + id;
$( nodeID + " .closedRFD-collapsible" ).show();
$( nodeID + " .closedRFD-uncollapse" ).hide();
},
'collapseAll' : function() {
$( ".closedRFD-collapsible" ).hide();
$( ".closedRFD-uncollapse" ).show();
var controlLink = $( "#closedRFD-collapselink" )[0]
controlLink.setAttribute( "href", "javascript:closedRFDsHiglighter.uncollapseAll()" );
controlLink.innerHTML = "развернуть все закрытые секции";
},
'uncollapseAll' : function() {
$( ".closedRFD-collapsible" ).show();
$( ".closedRFD-uncollapse" ).hide();
var controlLink = $( "#closedRFD-collapselink" )[0]
controlLink.setAttribute( "href", "javascript:closedRFDsHiglighter.collapseAll()" );
controlLink.innerHTML = "свернуть все закрытые секции";
},
'hideAll' : function() {
$( ".closedRFD" ).hide();
var controlLink = $( "#closedRFD-hidelink" )[0]
controlLink.setAttribute( "href", "javascript:closedRFDsHiglighter.showAll()" );
controlLink.innerHTML = "показать закрытые секции";
},
'showAll' : function() {
$( ".closedRFD" ).show();
var controlLink = $( "#closedRFD-hidelink" )[0]
controlLink.setAttribute( "href", "javascript:closedRFDsHiglighter.hideAll()" );
controlLink.innerHTML = "скрыть закрытые секции";
}
}
if( /^Википедия:К_(удалению|переименованию)\//.test(wgPageName) && wgAction == 'view' )
addOnloadHook( closedRFDsHiglighter.init );