MediaWiki:Common.js
From Descendants of Darkness Wiki
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.
(function () {
var sidebarId = 'mw-navigation';
function saveSidebarScrollPosition() {
var scrollPosition = document.getElementById(sidebarId).scrollTop;
var currentPage = window.location.href;
sessionStorage.setItem(currentPage, scrollPosition);
}
function restoreSidebarScrollPosition() {
var currentPage = window.location.href;
var scrollPosition = sessionStorage.getItem(currentPage);
if (scrollPosition !== null) {
var sidebar = document.getElementById(sidebarId);
sidebar.scrollTop = parseInt(scrollPosition);
}
}
// Save scroll position when the sidebar is scrolled
var sidebar = document.getElementById(sidebarId);
sidebar.addEventListener('scroll', saveSidebarScrollPosition);
// Restore scroll position when the page is loaded
window.addEventListener('load', restoreSidebarScrollPosition);
// Restore scroll position when the history state changes (back/forward navigation)
window.addEventListener('popstate', restoreSidebarScrollPosition);
})();