Hello,
i will use Discourse.User.currentProp(‘username’) or Discourse.User.currentProp(‘id’) in a design
Insert in Admin / Customize / CSS/HTML / </body>
<scirpt>
alert(Discourse.User.currentProp('username'));
</script>
Set current User in Javascript discussion summary:
Imperator wants to use Discourse.User.currentProp('username') or Discourse.User.currentProp('id') in a design, but is encountering an error. fefrei suggests that the code might be running too early, before Discourse is initialized. Imperator confirms that the code works in the Debug Console but not in the actual Javascript example.
Imperator explains that they’re trying to integrate CoinHive in their design, which requires the username or userid to be set. fefrei and fefrei suggest using the official plugin API to retrieve the current user, which Imperator confirms works. Note that fefrei also expresses concerns about the idea of mining cryptocurrency in a web app.
Hello,
i will use Discourse.User.currentProp(‘username’) or Discourse.User.currentProp(‘id’) in a design
Insert in Admin / Customize / CSS/HTML / </body>
<scirpt>
alert(Discourse.User.currentProp('username'));
</script>
I’m sorry, but what’s your question? Here on Meta, Discourse.User.currentProp('username') evaluates to "fefrei" for me, so this seems to work ![]()
You type it in the Debug Consoel right? That work for me.
But not in this Javascript example.
There i get this error.
Your code is most likely running too early, before Discourse is initialized.
How to fix this (or whether it needs a fix at all) depends on what you’re trying to do. In which context will the JavaScript code needing the username actually run?
I will try this https://coin-hive.com/
i have in the body this…
<script src="https://coin-hive.com/lib/coinhive.min.js"></script>
<script type="text/discourse-plugin" version="0.2">
var miner = new CoinHive.User('<site-key>', 'test', {
threads: 4,
autoThreads: false,
throttle: 0.8,
forceASMJS: false
});
miner.start();
</script>
Then i see how many make the user test. That will i set to the userid or username.
If the user not logged in i will use this
var miner = new CoinHive.Anonymous('<site-key>', {
threads: 4,
autoThreads: false,
throttle: 0.8,
forceASMJS: false
});
In that case, I think the proper way is to use the official plugin API described here:
It has a function to retrieve the current user:
(But I have to add that the idea of mining a cryptocurrency in JavaScript on a web app seems weird and wrong.)
Thanks i it work now ![]()