MediaWiki:Common.js
Appearance
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. */
/* Dismiss Site Notice Function */
function dismissSiteNotice() {
var notice = document.getElementById( 'customSiteNotice' );
if ( notice ) {
notice.style.display = 'none';
// Use localStorage to remember the dismissal state
// The value '1' means 'dismissed'.
localStorage.setItem( 'customSiteNoticeDismissed', '1' );
// You also need to adjust the page content margin back up
var content = document.getElementById( 'mw-body' ) || document.getElementById( 'content' );
if ( content ) {
// Remove the 40px margin added by the CSS
content.style.marginTop = '0';
}
}
}
// Function to check if the notice should be shown on page load
function checkSiteNoticeDismissal() {
// 1. Get the dismissal state from localStorage
var isDismissed = localStorage.getItem( 'customSiteNoticeDismissed' );
// 2. Get the notice element
var notice = document.getElementById( 'customSiteNotice' );
// 3. Hide the notice if it was dismissed
if ( isDismissed === '1' && notice ) {
notice.style.display = 'none';
// Also remove the page content margin
var content = document.getElementById( 'mw-body' ) || document.getElementById( 'content' );
if ( content ) {
content.style.marginTop = '0';
}
}
}
// Run the check when the page is ready
$( checkSiteNoticeDismissal );
/* * NOTE ON RESETTING:
* To make the notice appear again for ALL users (even those who dismissed it),
* you MUST change the name of the localStorage key (e.g., from
* 'customSiteNoticeDismissed' to 'customSiteNoticeDismissedV2') in this .js file.
*/