User:Most2dot0/common.js

From Angelina Jordan Wiki
Revision as of 13:18, 6 January 2026 by Most2dot0 (talk | contribs) (Move cargo helper loader to Gadget)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
//syntax highlighter
mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-DotsSyntaxHighlighter.js&action=raw&ctype=text/javascript');
syntaxHighlighterConfig = { parameterColor: "#FFDD99" }


// Auto-reload page content if marker element is present
$(document).ready(function() {
    const marker = document.getElementById('auto-reload-trigger');
    if (!marker) return;

    const period = Math.max(5, parseInt(marker.dataset.period || "30", 10)); // seconds
    const limit = parseInt(marker.dataset.limit || "10", 10); // max reloads
    let count = 0;

    // Create and insert status display
    const statusBox = $('<div id="auto-reload-status" style="margin:10px 0;padding:5px;border:1px solid #ccc;font-size:90%;width:fit-content;background:#f8f8f8;"></div>');
    statusBox.text(`Reloads done: ${count} / ${limit}`);
    $('#mw-content-text').before(statusBox);

    function reloadContent() {
        if (count >= limit) {
            statusBox.text(`Reload complete (${count}/${limit})`);
            return;
        }
        count++;
        statusBox.text(`Reloads done: ${count} / ${limit}`);

        $.ajax({
            url: location.href,
            cache: false,
            success: function(data) {
                const newContent = $(data).find('#mw-content-text');
                if (newContent.length) {
                    $('#mw-content-text').replaceWith(newContent);
                    mw.hook('wikipage.content').fire($('#mw-content-text'));
                }
            }
        });
    }

    setInterval(reloadContent, period * 1000);
});



/* === Development code below === */