Usuari:Vriullop/minerva.js

De Viccionari

Nota: Després de publicar, possiblement necessitareu refrescar la memòria cau del vostre navegador per a veure'n els canvis.

  • Firefox / Safari: Premeu Majús i alhora cliqueu el botó Actualitzar, o pressioneu Ctrl+F5 o Ctrl+R (⌘+R en un Mac)
  • Google Chrome: Premeu Ctrl+Majús+R (⌘+Shift+R en un Mac)
  • Internet Explorer / Edge: Premeu Ctrl i alhora cliqueu a Actualitza o pressioneu Ctrl+F5
  • Opera: Premeu Ctrl-F5.
// Collapsing sections except the first one
// https://en.wiktionary.org/wiki/Wiktionary:Grease_pit/2023/February#Collapsing_sections_on_the_mobile_site
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') || {
        'Català': 1,
        'Multilingüe': 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;
    }
});