Skip to content

Instantly share code, notes, and snippets.

@ItsOnlyBinary
Last active February 12, 2020 22:14
Show Gist options
  • Save ItsOnlyBinary/21935c2ff083505a624e2dedea03121b to your computer and use it in GitHub Desktop.
Save ItsOnlyBinary/21935c2ff083505a624e2dedea03121b to your computer and use it in GitHub Desktop.
<script>
kiwi.plugin('user-colour', function(kiwi, log) {
var nextRender = false;
// listen for first message to render
// this changes colour at startup
listenRender();
kiwi.on('active.component', function() {
// When returning from other components like settings
// listen for first message to render
listenRender();
});
kiwi.on('active.component.toggle', function() {
// When returning from other components like settings
// listen for first message to render
listenRender();
});
kiwi.state.$watch('ui.active_buffer', function() {
// When the active_buffer is changed try to set the colour
setColour();
});
function listenRender() {
if (nextRender) {
return;
}
nextRender = true;
kiwi.once('message.render', function() {
// The first message is being rendered on screen
// try to set the colour on the next tick
kiwi.Vue.nextTick(function () {
nextRender = false;
setColour();
});
});
}
function setColour() {
// Check for the elements existance and try to set its colour
var el = document.querySelector('.kiwi-controlinput-user-nick');
var enable = kiwi.state.getActiveBuffer().setting('coloured_nicklist');
if (!el || !enable) {
return;
}
el.style.color = kiwi.state.getActiveNetwork().currentUser().getColour();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment