MediaWiki:Common.js/User:Fumple/DarkMode.js

if (mw.user.getName == null) { $("#darkmodebox").html("You can't use DarkMode as you aren't logged in. The ability to use DarkMode without an account will come later."); } else { var darkmodestatus = mw.user.options.get("gadget-darkmode"); $("#darkmodebox").html("DarkMode is currently " + (darkmodestatus == "1" ? "enabled" : "disabled") + ". "); $("#darkmodechange").click(function {        new mw.Api.get({ "action": "query", "format": "json", "meta": "tokens" })           .done(function (data) { new mw.Api.post({                   "action": "options",                    "format": "json",                    "optionname": "gadget-darkmode",                    "optionvalue": darkmodestatus == "1" ? "0":"1",                    "token":data.query.tokens.csrftoken                }) .done(function {                        $("#darkmodebox").html("Done! Refreshing the page!");                        window.location.reload;                    }) .fail(function (err) {                       $("#darkmodebox").html("An unexpected error occured!");                        console.log(err)                    }) })           .fail(function (err) { $("#darkmodebox").html("An unexpected error occured while getting a token!"); console.log(err) })   }) }