MediaWiki:Common.js

From Raychev Wiki
Revision as of 03:27, 29 November 2026 by Delyan (talk | contribs) (Add the migrated homepage font picker)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* The font picker on the Delyan Raychev homepage. */
mw.hook('wikipage.content').add(function ($content) {
    if (mw.config.get('wgPageName') !== 'Main_Page' ||
        mw.config.get('wgAction') !== 'view' ||
        document.getElementById('raychev-page-font')) {
        return;
    }

    const fontChoices = {
        'Default': '',
        'American Typewriter': '"American Typewriter", "Courier New", serif',
        'Calibri': 'Calibri, Carlito, "Segoe UI", sans-serif',
        'Calibri Light': '"Calibri Light", Calibri, "Segoe UI", sans-serif',
        'Consolas': 'Consolas, "Liberation Mono", monospace',
        'Geneva': 'Geneva, Verdana, sans-serif',
        'Georgia': 'Georgia, "Times New Roman", serif',
        'GlassTTY': 'GlassTTY, "Glass TTY VT220", monospace',
        'Lucida Grande': '"Lucida Grande", "Lucida Sans Unicode", sans-serif',
        'Menlo': 'Menlo, "DejaVu Sans Mono", monospace',
        'Monaco': 'Monaco, "Lucida Console", monospace',
        'Nouveau IBM': '"Nouveau IBM", "Liberation Mono", monospace'
    };

    const picker = document.createElement('label');
    picker.append('Page font ');
    const select = document.createElement('select');
    select.id = 'raychev-page-font';
    for (const name of Object.keys(fontChoices)) {
        select.add(new Option(name, name));
    }

    picker.append(select);
    const controls = document.createElement('p');
    controls.append(picker);
    $content[0].append(controls);
    select.addEventListener('change', function () {
        $content[0].style.fontFamily = fontChoices[select.value];
    });
});