MediaWiki:Common.js: Difference between revisions
From EQOA Sandstorm Wiki
Jump to navigationJump to search
RenodorDev (talk | contribs) No edit summary |
RenodorDev (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
(function () { | |||
( function () { | function rawPage(title) { | ||
return mw.config.get('wgScript') + | |||
'?title=' + encodeURIComponent(title) + | |||
'&action=raw&ctype=text/javascript'; | |||
} | |||
function loadScript(title) { | |||
return mw.loader.getScript(rawPage(title)); | |||
} | } | ||
function applyWikiTheme(theme) { | function applyWikiTheme(theme) { | ||
var isLight = theme === 'light'; | var isLight = theme === 'light'; | ||
| Line 190: | Line 15: | ||
document.documentElement.classList.toggle('eqoa-theme-light', isLight); | document.documentElement.classList.toggle('eqoa-theme-light', isLight); | ||
document.documentElement.classList.toggle('eqoa-theme-dark', !isLight); | document.documentElement.classList.toggle('eqoa-theme-dark', !isLight); | ||
document.body.classList.toggle('eqoa-theme-light', isLight); | |||
if (document.body) { | |||
document.body.classList.toggle('eqoa-theme-light', isLight); | |||
document.body.classList.toggle('eqoa-theme-dark', !isLight); | |||
} | |||
try { | try { | ||
localStorage.setItem('eqoa-wiki-theme', isLight ? 'light' : 'dark'); | localStorage.setItem('eqoa-wiki-theme', isLight ? 'light' : 'dark'); | ||
} catch (e) {} | } catch (e) {} | ||
var button = document.getElementById('eqoa-theme-toggle'); | var button = document.getElementById('eqoa-theme-toggle'); | ||
if (button) { | if (button) { | ||
button.innerHTML = isLight ? '☾' : '☼'; | button.innerHTML = isLight ? '☾' : '☼'; | ||
| Line 250: | Line 77: | ||
applyWikiTheme(getSavedWikiTheme()); | applyWikiTheme(getSavedWikiTheme()); | ||
}); | }); | ||
mw. | mw.loader.using('mediawiki.util').then(function () { | ||
loadScript('MediaWiki:CharacterBuilderData.js') | |||
.then(function () { | |||
return $.when( | |||
loadScript('MediaWiki:LZString.js'), | |||
loadScript('MediaWiki:QRCode.js'), | |||
loadScript('MediaWiki:Html2Canvas.js') | |||
); | |||
}) | |||
.then(function () { | |||
return loadScript('MediaWiki:CharacterBuilder.js'); | |||
}) | |||
.catch(function (error) { | |||
console.error('Character Builder failed to load:', error); | |||
}); | |||
loadScript('MediaWiki:ClassMasteryData.js') | |||
.then(function () { | |||
return loadScript('MediaWiki:ClassMasteryRawData.js'); | |||
}) | |||
.then(function () { | |||
return loadScript('MediaWiki:ClassMasteryCalculator.js'); | |||
}) | |||
.catch(function (error) { | |||
console.error('Class Mastery failed to load:', error); | |||
}); | |||
} | |||
}); | }); | ||
}); | })(); | ||
Revision as of 19:11, 16 May 2026
(function () {
function rawPage(title) {
return mw.config.get('wgScript') +
'?title=' + encodeURIComponent(title) +
'&action=raw&ctype=text/javascript';
}
function loadScript(title) {
return mw.loader.getScript(rawPage(title));
}
function applyWikiTheme(theme) {
var isLight = theme === 'light';
document.documentElement.classList.toggle('eqoa-theme-light', isLight);
document.documentElement.classList.toggle('eqoa-theme-dark', !isLight);
if (document.body) {
document.body.classList.toggle('eqoa-theme-light', isLight);
document.body.classList.toggle('eqoa-theme-dark', !isLight);
}
try {
localStorage.setItem('eqoa-wiki-theme', isLight ? 'light' : 'dark');
} catch (e) {}
var button = document.getElementById('eqoa-theme-toggle');
if (button) {
button.innerHTML = isLight ? '☾' : '☼';
button.title = isLight ? 'Switch to Dark Theme' : 'Switch to White Theme';
button.setAttribute(
'aria-label',
isLight ? 'Switch to Dark Theme' : 'Switch to White Theme'
);
}
if (window.dispatchEvent) {
window.dispatchEvent(new CustomEvent('eqoa-wiki-theme-change', {
detail: {
theme: isLight ? 'light' : 'dark'
}
}));
}
}
function getSavedWikiTheme() {
try {
return localStorage.getItem('eqoa-wiki-theme') === 'light'
? 'light'
: 'dark';
} catch (e) {
return 'dark';
}
}
window.EQOA_APPLY_WIKI_THEME = applyWikiTheme;
window.EQOA_GET_WIKI_THEME = getSavedWikiTheme;
mw.hook('wikipage.content').add(function () {
var button = document.getElementById('eqoa-theme-toggle');
if (!button) {
button = document.createElement('button');
button.id = 'eqoa-theme-toggle';
button.type = 'button';
button.className = 'eqoa-theme-toggle';
button.addEventListener('click', function () {
var isLight = document.body.classList.contains('eqoa-theme-light');
applyWikiTheme(isLight ? 'dark' : 'light');
});
document.body.appendChild(button);
}
applyWikiTheme(getSavedWikiTheme());
});
mw.loader.using('mediawiki.util').then(function () {
loadScript('MediaWiki:CharacterBuilderData.js')
.then(function () {
return $.when(
loadScript('MediaWiki:LZString.js'),
loadScript('MediaWiki:QRCode.js'),
loadScript('MediaWiki:Html2Canvas.js')
);
})
.then(function () {
return loadScript('MediaWiki:CharacterBuilder.js');
})
.catch(function (error) {
console.error('Character Builder failed to load:', error);
});
loadScript('MediaWiki:ClassMasteryData.js')
.then(function () {
return loadScript('MediaWiki:ClassMasteryRawData.js');
})
.then(function () {
return loadScript('MediaWiki:ClassMasteryCalculator.js');
})
.catch(function (error) {
console.error('Class Mastery failed to load:', error);
});
});
})();