User:SitX/vector-2022.js: Difference between revisions
Jump to navigation
Jump to search
Created page with "mw.loader.using('mediawiki.util').then(function() { function expandSidebar() { document.body.classList.add('is-menu-expanded'); localStorage.setItem("vector-sidebar-visible", "true"); } if (document.readyState === "complete") { expandSidebar(); } else { window.addEventListener("load", expandSidebar); } const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) {..." |
No edit summary |
||
Line 3: | Line 3: | ||
document.body.classList.add('is-menu-expanded'); | document.body.classList.add('is-menu-expanded'); | ||
localStorage.setItem("vector-sidebar-visible", "true"); | localStorage.setItem("vector-sidebar-visible", "true"); | ||
} | |||
function forceSidebarForAnonymous() { | |||
if (mw.config.get("wgUserName") === null) { // User is anonymous | |||
expandSidebar(); | |||
} | |||
} | } | ||
if (document.readyState === "complete") { | if (document.readyState === "complete") { | ||
expandSidebar(); | expandSidebar(); | ||
forceSidebarForAnonymous(); | |||
} else { | } else { | ||
window.addEventListener("load", expandSidebar); | window.addEventListener("load", function() { | ||
expandSidebar(); | |||
forceSidebarForAnonymous(); | |||
}); | |||
} | } | ||
Line 16: | Line 26: | ||
if (!document.body.classList.contains('is-menu-expanded')) { | if (!document.body.classList.contains('is-menu-expanded')) { | ||
expandSidebar(); | expandSidebar(); | ||
forceSidebarForAnonymous(); | |||
} | } | ||
} | } |
Latest revision as of 01:06, 25 March 2025
mw.loader.using('mediawiki.util').then(function() {
function expandSidebar() {
document.body.classList.add('is-menu-expanded');
localStorage.setItem("vector-sidebar-visible", "true");
}
function forceSidebarForAnonymous() {
if (mw.config.get("wgUserName") === null) { // User is anonymous
expandSidebar();
}
}
if (document.readyState === "complete") {
expandSidebar();
forceSidebarForAnonymous();
} else {
window.addEventListener("load", function() {
expandSidebar();
forceSidebarForAnonymous();
});
}
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === "class") {
if (!document.body.classList.contains('is-menu-expanded')) {
expandSidebar();
forceSidebarForAnonymous();
}
}
});
});
observer.observe(document.body, { attributes: true });
});