User:Vuccala/minerva.js

mw.loader.using('skins.minerva.scripts', function {   if (mw.config.get('wgNamespaceNumber') !== 0 || mw.config.get('wgAction') !== 'view') {        return;    }    var expandedLanguages = mw.storage.getObject('expandedLanguages') || {        'English': 1,        'Translingual': 1    };    $('h2.collapsible-heading').on('click', function { var lang = $(this).find('.mw-headline').text; if ($(this).hasClass('open-block')) { expandedLanguages[lang] = 1; } else { delete expandedLanguages[lang]; }       mw.storage.setObject('expandedLanguages', expandedLanguages); });   if ($('h2.collapsible-heading').length <= 1) {        return;    }    var hash = location.hash.substring(1);    if (hash) {        var el = document.getElementById(hash);        var all = $('*');        var index = all.index($(el));    }    var headers = $('h2.collapsible-heading');    for (var i = 0; i < headers.length; i++) {        var lang = $(headers[i]).find('.mw-headline').text;        if (expandedLanguages.hasOwnProperty(lang)) {            // pass        } else if (hash && all.index($(headers[i])) < index && (i === headers.length - 1 || all.index($(headers[i + 1])) > index)) {            // pass        } else {            $(headers[i]).click;        }    }    if (hash) {        // https://stackoverflow.com/a/36033643        window.location.hash = '';        window.location.hash = hash;    } });