Actions

MediaWiki

Common.js: Difference between revisions

An Avatar.Global Resource

Created page with "Any JavaScript here will be loaded for all users on every page load.: $(document).ready(function() { // Get the last visited page from localStorage var lastPage = localStorage.getItem('lastVisitedPage'); // Get the current page title var currentPage = mw.config.get('wgPageName').replace(/_/g, ' '); // Store the current page in localStorage for the next visit if (currentPage !== "Main_Page") { // Avoid setting breadcrumbs for the main page..."
 
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
$(document).ready(function() {
     // Get the last visited page from localStorage
     // Get the last visited page from localStorage

Revision as of 16:37, 15 March 2025

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
    // Get the last visited page from localStorage
    var lastPage = localStorage.getItem('lastVisitedPage');

    // Get the current page title
    var currentPage = mw.config.get('wgPageName').replace(/_/g, ' ');

    // Store the current page in localStorage for the next visit
    if (currentPage !== "Main_Page") { // Avoid setting breadcrumbs for the main page
        localStorage.setItem('lastVisitedPage', currentPage);
    }

    // Display the breadcrumb if a last visited page exists
    if (lastPage && lastPage !== currentPage) {
        var breadcrumbHtml = `<div class="breadcrumb" style="margin-bottom:10px;">
            <a href="/wiki/${encodeURIComponent(lastPage)}">← Back to ${lastPage}</a>
        </div>`;

        // Insert breadcrumb at the top of the page content
        $('#content').prepend(breadcrumbHtml);
    }
});