Is it possible to make it so that I can select whether to use light or dark mode for a certain wiki instead of having to use light mode for every wiki I go to?
Is it possible to make it so that I can select whether to use light or dark mode for a certain wiki instead of having to use light mode for every wiki I go to?
I know you can change between light or dark but it applies to other wikis.
There is no built-in feature for setting separate theme preferences for each wiki. However, you can set your theme preference to use whatever the wiki's default theme is. Note that if you use the built-in theme toggler, this will set your preference to whichever theme you are changing to and you will have to go back to Special:Preferences to reset it back to using the wiki's default theme.
If you want to be able to toggle themes without changing your preferences, you can use either ThemeToggler or ThemeSelector. ThemeSelector allows you to set a default theme via personal JS so it could be used as a hacky way to set separate theme preferences for each wiki if you really really wanted to. However, using that way is not exactly recommended. The page would still load using your global preference and would change to the local preference only after the JS has loaded and finished running.
I'm already using ThemeToggler. I guess I will just change them manually.
I have exprimented with it a bit. Waiting for an entire script to load and change your theme each time you open a new page is definitely annoying. But if you put some simpler code right away on your JS page it changes your theme fairly quick (especially when continuing browsing the same wiki because the browser caches the CSS). This is the code I used:
if (mw.config.get('skin') === 'fandomdesktop') {
var themeSheet1 = document.createElement('link'),
themeURL1 = '/wikia.php?controller=ThemeApi&method=themeVariables&variant=',
themeSheet2 = document.createElement('link'),
themeURL2 = '/load.php?fandomdesktop=1&lang=en&modules=' +
'ext.fandom.DesignSystem.GlobalNavigation.brand.$1.css%7C' +
'ext.fandom.DesignSystem.brand.$1.css' +
'&only=styles&skin=fandomdesktop';
switch (mw.config.get('wgServerName')) {
// Wikis to switch to dark mode
case 'community.fandom.com':
case 'lost-cities-keeper.fandom.com':
case 'dystopian-fiction.fandom.com':
case 'math.wikia.org':
themeSheet1.rel = "stylesheet";
themeSheet1.href = themeURL1 + 'dark';
document.head.appendChild(themeSheet1);
themeSheet2.rel = "stylesheet";
themeSheet2.href = themeURL2.replace(/\$1/g, 'dark');
document.head.appendChild(themeSheet2);
document.body.classList.remove('theme-fandomdesktop-light');
document.body.classList.add('theme-fandomdesktop-dark');
mw.config.set('isDarkTheme', true);
break;
// Wikis to switch to light mode
case 'wreckit-woodhouse.fandom.com':
themeSheet1.rel = "stylesheet";
themeSheet1.href = themeURL1 + 'light';
document.head.appendChild(themeSheet1);
themeSheet2.rel = "stylesheet";
themeSheet2.href = themeURL2.replace(/\$1/g, 'light');
document.head.appendChild(themeSheet2);
document.body.classList.remove('theme-fandomdesktop-dark');
document.body.classList.add('theme-fandomdesktop-light');
mw.config.set('isDarkTheme', false);
break;
}
}
The lines that start with case are where you put the names of the wikis you want to change the theme for - I just put some as an example.
There is a list for forcing dark theme and a list for forcing light theme (so that you can keep the "wiki's default" for all other wikis).
It works.
Nice. But if that is how we are going to do it, would it work to just use @import in one's local CSS for each wiki. Then you don't even have to use JS or check which wiki you are on.
Edit: Nevermind. I guess there would still be the issue of the body's class and the JS config variable.
I actually tried that first. It could prevent the few seconds of unwanted theme, and the class+config could be handled separately on the JS or just ignored by some users.
Unfortunately, the user stylesheets are loaded above the wiki theme stylesheets, so the wiki theme stylesheets are winning in the competition.
Yeah. I recently helped some other users and that seemed to be the case. I thought that was really odd but I didn't feel like spending the time to investigate. Maybe we should report that to Fandom? It is clearly a bug.
What do you think?