MediaWiki:Common.js

From Descendants of Darkness Wiki

Revision as of 19:31, 6 April 2024 by Ninja (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: // Save the scroll position before the page unloads window.addEventListener('beforeunload', function() { localStorage.setItem('sidebarScrollPosition', document.getElementById('mw-navigation').scrollTop); }); // Restore the scroll position after the new page loads window.addEventListener('load', function() { var scrollPosition = localStorage.getItem('sidebarScrollPosition'); if (scro...")
(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.
/* Any JavaScript here will be loaded for all users on every page load. */


// Save the scroll position before the page unloads
window.addEventListener('beforeunload', function() {
    localStorage.setItem('sidebarScrollPosition', document.getElementById('mw-navigation').scrollTop);
});

// Restore the scroll position after the new page loads
window.addEventListener('load', function() {
    var scrollPosition = localStorage.getItem('sidebarScrollPosition');
    if (scrollPosition !== null) {
        document.getElementById('mw-navigation').scrollTop = parseInt(scrollPosition);
    }
});

// Save the scroll position when clicking on sidebar links
document.querySelectorAll('#mw-navigation a').forEach(function(link) {
    link.addEventListener('click', function() {
        var scrollPosition = document.getElementById('mw-navigation').scrollTop;
        this.setAttribute('data-scroll-position', scrollPosition);
    });
});