Zeronet: [Question] How can zites detect if theme is dark or light?

Created on 20 Oct 2018  路  4Comments  路  Source: HelloZeroNet/ZeroNet

All 4 comments

you can use Page.server_info.user_settings.theme variable

This is something that should go in the Documentation :D

...in fact user settings isn't even in the documentation lol

Thanks @anoadragon453 for this script:

/Detect ZeroNet theme and apply the style according to it/
zeroFrame.cmd("serverInfo", {}, (server_info) => {
// Print server_info to the console
console.log("Server info:", server_info)

// Retrieve the document body
const body = document.body

// Check user_settings exists
if (!server_info.user_settings) {
    // Exit this function if it doesn't
    return
}

// Depending on user theme settings, set the theme
switch(server_info.user_settings.theme) {
case "light":
    body.innerHTML = '<style>lighttheme</style>' + body.innerHTML
    break
case "dark":
    body.innerHTML = '<style>darktheme</style>' + body.innerHTML
    break
default:
    console.log("Theming not supported. Please upgrade your ZeroNet version.")
}

})

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trenta3 picture trenta3  路  3Comments

yurkobb picture yurkobb  路  3Comments

iShift picture iShift  路  3Comments

sergei-bondarenko picture sergei-bondarenko  路  3Comments

blurHY picture blurHY  路  3Comments