(function () {
const sw = JSON.parse( localStorage.getItem("SimonWikt") );
if( !sw || !sw.collapseDisabled ) {
const openLangs = ;
const openDets =
[ "Conjugation",
"Declension",
"Etymology 1", "Etymology 2", "Etymology 3", "Etymology 4",
"Adjective", "Adverb",
"Conjunction",
"Determiner",
"Interjection",
"Letter",
"Numeral", "Noun",
"Particle", "Participle", "Prefix", "Preposition", "Pronoun", "Proper noun",
"Suffix",
"Translations",
"Verb"
];
if( document.querySelector("section") ) {
/* Mobile Wiktionary has 'section's */
/* and collapsible languages */
/* Headings are now in DIVs */
document.querySelectorAll("#mw-content-text > div .mw-heading3").forEach(
(h3)=>{ createDetailsLevel(h3) }
);
document.querySelectorAll("#mw-content-text > div .mw-heading2").forEach(
(h2)=>{
/* collapse unwanted languages */
const headingName = h2.querySelector( "H2" ).innerText;
if( ! openLanguage( headingName ) ) h2.click();
}
);
} else
/* Collapse 'H2's and above, except wanted languages and headings */
document.querySelectorAll("#mw-content-text > div .mw-heading2").forEach(
(h2)=>{ createDetailsLevel(h2) }
);
function openLanguage( lang ) {
return openLangs.indexOf( lang ) >= 0;
}
function openDet( det ){
return openLanguage( det ) || openDets.indexOf( det ) >= 0;
}
function createDetailsLevel( heading ) {
function getHeadingInfo( heading ) {
const headings = ;
/* Mobile and Desktop headings are in a DIV */
let id = ""; let name = "";
let i = headings.indexOf( heading.nodeName );
if( heading.nodeName == "DIV" && heading.classList.contains("mw-heading") ) {
heading = heading.children;
i = headings.indexOf( heading.nodeName );
id = heading.id;
name = heading.innerText;
}
else if ( i > 0 ) {
let span = heading.querySelector( "span" );
id = span.id;
name = span.innerText;
}
return { level: i, id: id, name: name };
}
const headingInfo = getHeadingInfo( heading );
const level = headingInfo.level;
let sib = heading.nextSibling;
const dets = document.createElement( "details" );
heading.after( dets );
const summary = document.createElement( "summary" );
dets.appendChild( summary );
summary.appendChild( heading );
dets.open = openDet( headingInfo.name );
dets.title = headingInfo.id + " details";
while( sib ) {
let nsib = sib.nextSibling;
let sibLevel = getHeadingInfo( sib ).level;
if( sibLevel > 0 ) {
if( sibLevel > level ) {
let subDets = createDetailsLevel( sib );
nsib = subDets.nextSibling;
dets.appendChild( subDets );
}
else break;
}
else dets.appendChild( sib );
sib = nsib;
}
return dets;
}
}
})();
SimonWikt = {
sw: function() { return JSON.parse( localStorage.getItem("SimonWikt") ) },
collapsible: function() { return !this.sw() || !this.sw().collapseDisabled },
disableCollapse: function () {
localStorage.setItem( "SimonWikt",JSON.stringify( {collapseDisabled:true} ) );
},
enableCollapse: function() {
localStorage.setItem( "SimonWikt",JSON.stringify( {collapseDisabled:false} ) );
}
}
if( document.querySelector("#mw-content-text > div .mw-heading2") )
document.querySelector("#mw-content-text").insertAdjacentHTML(
"afterbegin",
'<a id="p-visibility-collapse" href="#visibility-collapse" ' +
'onclick="javascript:SimonWikt.' +
( SimonWikt.collapsible() ? 'disableCollapse()' : 'enableCollapse()' ) +
';location.reload();return false;">' +
( SimonWikt.collapsible() ? 'Expand sections' : 'Collapse sections' ) +
'</a>'
);