by Wecoc May 13th 2018, 12:42 am
If there aren't many changes this can be done, but it's a bit tedious.
Here's the javascript:
- Code:
/*
* Theme Picker
* Version: 1.0 EN (2018-05-13)
* Author: Wecoc
* Description: Simple theme (format) picker without Hitskin links
*/
$(function() {
var themes = [
// Default
["Default", ''],
// Dark
["Dark", '<style type="text/css">' +
'body, #wrap { background-color: #000; }' +
'.lastpost-avatar img { border-radius: 32px; }' +
'</style>']
];
var a = document.createElement('DIV'), b = document.createElement('SELECT');
a.id = "theme-picker";
for (i = 0; i < themes.length; i++) {
var c = document.createElement('OPTION');
c.value = themes[i][0];
c.innerHTML = themes[i][0];
b.appendChild(c);
};
a.appendChild(b);
document.querySelector('.navbar').after(a);
loadStoredThemeInfo();
b.onchange = function() {
localStorage.currentTheme = this.value;
updateThemeOnChange();
};
function loadStoredThemeInfo() {
if (!localStorage.currentTheme) return;
$('#theme-picker option[value="' + localStorage.currentTheme + '"]').attr('selected','true');
updateThemeOnChange();
}
function updateThemeOnChange() {
if (!localStorage.currentTheme) return;
var current_theme = localStorage.currentTheme;
var theme_id = themes.findIndex(x => x[0] == current_theme);
$('head .theme-data').remove();
$('head').append('<div class="theme-data">' + themes[theme_id][1] + '</div>');
}
});
Title: Theme picker
Placement: In all the pages
This is the only part you have to worry:
- Code:
// Default
["Default", ''],
// Dark
["Dark", '<style type="text/css">' +
'body, #wrap { background-color: #000; }' +
'.lastpost-avatar img { border-radius: 32px; }' +
'</style>']
There you define the available themes (in my example 'Default' and 'Dark') and the CSS for each one.
- Spoiler:
This is the format, beware the last theme shouldn't have a comma, but the others must have it.
- Code:
[Theme Name, Theme Code],
[Theme Name, Theme Code],
[Theme Name, Theme Code],
[Theme Name, Theme Code]
As you can see the default one has nothing defined, because of course it uses the default CSS only.
The Dark one modifies the forum's background to black and the lastpost avatars are rounded.