Difference between revisions of "User:Tobias Alcaraz/common.js"

From Mine Blocks Wiki
Jump to navigation Jump to search
If you find a typo, inconsistency, or error, please sign up and help out the wiki! We can't do it without your help! :D Thank you!

 
Line 25: Line 25:
 
     }
 
     }
 
}
 
}
 +
 +
/* Add true amount of displayed elements in a list page. */
 +
(function() {
 +
    const isSpecialPage = mw.config.get('wgNamespaceNumber') === -1,
 +
        isInWhatLinksHere = mw.config.get('wgCanonicalSpecialPageName') === 'Whatlinkshere';
 +
 +
    if (!isSpecialPage && !isInWhatLinksHere) return;
 +
 +
    const list = document.getElementById('mw-whatlinkshere-list'),
 +
        listElements = list.children,
 +
        limit = Number(document.querySelector('input[name="limit"]').value),
 +
        listLength = listElements.length === limit ? `>=${listElements.length}` : listElements.length,
 +
        totalElem = document.createElement('div'),
 +
        totalCounterElem = document.createElement('b');
 +
 +
    totalElem.classList.add('list-total-elements');
 +
    totalElem.style.margin = '7px 0';
 +
 +
    totalElem.innerText = 'Total amount of pages: ';
 +
    totalCounterElem.innerText = listLength;
 +
 +
    list.insertAdjacentElement('beforebegin', totalElem);
 +
    totalElem.insertAdjacentElement('beforeend', totalCounterElem);
 +
}());

Latest revision as of 22:33, 7 July 2023

/* Since there's no personal JS in this wiki, this code is run through an browser extension. */

/* Syntax highlight script. */
if (document.body.classList.contains('action-edit')) {

    mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-DotsSyntaxHighlighter.js&action=raw&ctype=text/javascript');

    syntaxHighlighterConfig = {
        timeout: 500,
        boldOrItalicColor: '#44466d',
        wikilinkColor: '#245477',
        externalLinkColor: '#244d491',
        headingColor: '#44466d',
        listOrIndentColor: '#4d1a19',
        signatureColor: '#66331e',
        tableColor: '#5e5129',
        templateColor: '#5e5129',
        parameterColor: '#66331e',
        hrColor: '#44466d',
        tagColor: '#662946',
        commentColor: '#4d1a19',
        entityColor: '#474d23',
        backgroundColor: '#212121',
        foregroundColor: '#eee'
    }
}

/* Add true amount of displayed elements in a list page. */
(function() {
    const isSpecialPage = mw.config.get('wgNamespaceNumber') === -1,
        isInWhatLinksHere = mw.config.get('wgCanonicalSpecialPageName') === 'Whatlinkshere';

    if (!isSpecialPage && !isInWhatLinksHere) return;

    const list = document.getElementById('mw-whatlinkshere-list'),
        listElements = list.children,
        limit = Number(document.querySelector('input[name="limit"]').value),
        listLength = listElements.length === limit ? `>=${listElements.length}` : listElements.length,
        totalElem = document.createElement('div'),
        totalCounterElem = document.createElement('b');

    totalElem.classList.add('list-total-elements');
    totalElem.style.margin = '7px 0';

    totalElem.innerText = 'Total amount of pages: ';
    totalCounterElem.innerText = listLength;

    list.insertAdjacentElement('beforebegin', totalElem);
    totalElem.insertAdjacentElement('beforeend', totalCounterElem);
}());