MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 45: | Line 45: | ||
} ); | } ); | ||
} ); | } ); | ||
// --- Start: Random Background Image --- | |||
var randomBackgrounds = [ | |||
'https://cdnb.artstation.com/p/assets/images/images/067/057/459/large/jordan-grimmer-thhfgh.jpg', | |||
'https://cdna.artstation.com/p/assets/images/images/080/057/226/large/jordan-grimmer-jordan-grimmer-fdoigjhfdigdg.jpg', | |||
'https://cdnb.artstation.com/p/assets/images/images/046/925/487/large/johannes-bohm-bh-scr-annouce-batch1-redlight-3840x2160px-copy.jpg' | |||
]; | |||
// Choose a random index from the array | |||
var randomIndex = Math.floor(Math.random() * randomBackgrounds.length); | |||
var chosenImageUrl = randomBackgrounds[randomIndex]; | |||
// Apply the chosen image to the <body> background | |||
if (chosenImageUrl) { | |||
document.body.style.backgroundImage = 'url("' + chosenImageUrl + '")'; | |||
// --- Optional: Add styles for better background appearance --- | |||
document.body.style.backgroundSize = 'cover'; // Stretches/shrinks image to cover the whole background | |||
document.body.style.backgroundRepeat = 'no-repeat'; // Prevents the image from tiling | |||
document.body.style.backgroundPosition = 'center center'; // Centers the image | |||
document.body.style.backgroundAttachment = 'fixed'; // Makes the background stay fixed when scrolling (remove if you don't like this effect) | |||
// --- End Optional Styles --- | |||
// Log to console for debugging (visible in browser's F12 tools) | |||
console.log('Set random background:', chosenImageUrl); | |||
} | |||
// --- End: Random Background Image --- | |||
Latest revision as of 00:29, 16 April 2025
mw.loader.using( 'jquery' ).then( function () {
$( function() { // Document ready shorthand
var classList = document.documentElement.classList;
var appliedTheme = false; // Flag to track if we made changes
// --- Force Dark Mode ---
// Remove potentially conflicting light mode classes
if (classList.contains('vector-theme-light')) {
classList.remove('vector-theme-light');
appliedTheme = true;
}
if (classList.contains('vector-feature-night-mode-disabled')) {
classList.remove('vector-feature-night-mode-disabled');
appliedTheme = true;
}
if (classList.contains('skin-theme-clientpref-day')) {
classList.remove('skin-theme-clientpref-day');
appliedTheme = true;
}
// Add required dark mode classes if not already present
if (!classList.contains('vector-theme-dark')) {
classList.add('vector-theme-dark');
appliedTheme = true;
}
// Hypothesis: Need to add the 'enabled' and 'night' counterparts
if (!classList.contains('vector-feature-night-mode-enabled')) {
classList.add('vector-feature-night-mode-enabled');
appliedTheme = true;
}
if (!classList.contains('skin-theme-clientpref-night')) {
classList.add('skin-theme-clientpref-night');
appliedTheme = true;
}
// --- End Force Dark Mode ---
if (appliedTheme) {
console.log( 'Attempted to force dark theme classes via Common.js' );
} else {
console.log( 'Dark theme classes may have already been present; no changes made by Common.js script.' );
}
} );
} );
// --- Start: Random Background Image ---
var randomBackgrounds = [
'https://cdnb.artstation.com/p/assets/images/images/067/057/459/large/jordan-grimmer-thhfgh.jpg',
'https://cdna.artstation.com/p/assets/images/images/080/057/226/large/jordan-grimmer-jordan-grimmer-fdoigjhfdigdg.jpg',
'https://cdnb.artstation.com/p/assets/images/images/046/925/487/large/johannes-bohm-bh-scr-annouce-batch1-redlight-3840x2160px-copy.jpg'
];
// Choose a random index from the array
var randomIndex = Math.floor(Math.random() * randomBackgrounds.length);
var chosenImageUrl = randomBackgrounds[randomIndex];
// Apply the chosen image to the <body> background
if (chosenImageUrl) {
document.body.style.backgroundImage = 'url("' + chosenImageUrl + '")';
// --- Optional: Add styles for better background appearance ---
document.body.style.backgroundSize = 'cover'; // Stretches/shrinks image to cover the whole background
document.body.style.backgroundRepeat = 'no-repeat'; // Prevents the image from tiling
document.body.style.backgroundPosition = 'center center'; // Centers the image
document.body.style.backgroundAttachment = 'fixed'; // Makes the background stay fixed when scrolling (remove if you don't like this effect)
// --- End Optional Styles ---
// Log to console for debugging (visible in browser's F12 tools)
console.log('Set random background:', chosenImageUrl);
}
// --- End: Random Background Image ---