JS injection for Dashboard

Short answer, yes, it can be done. Long answer, you need to know how to use JS to manipulate the DOM. Jquery is not loaded by default in the Dashboard, so you have plain JS to contend with, unless you load in Jquery, which I'm at this point not sure can be done without unforeseen consequences.

EDIT: @Angus_M For a more complete answer, in the source code, there is an example. What you basically need to do is write whatever JS you want, put it inside a field named customJS in the JSON for the Dashboard (after escaping it, there is no code included that does that). I did it in a simple Python script:

 # Prepare the HTML
 my_html = my_html.replace('"', '\\"').replace('</', '<\/').replace(' />', '/>').replace('/>', ' />')
 my_html = my_html.encode('ascii', 'xmlcharrefreplace').decode("ascii")
 my_html = ''.join([line.strip() for line in my_html.splitlines()])
 print("my_html = '" + my_html + "'")
 
 # Now the JS
 my_js = my_js.replace('"', '\\"')
 my_js = '\\n'.join([line.strip() for line in my_js.splitlines()]).replace("\r", "").replace("\t", "")
 print("my_js = '" + my_js + "'")

This really isn't a complete thing, it is a proof of concept, it can be used, but it is not user friendly. It requires a lot (or at least some) of JS knowledge. A way to use this in a user-friendly manner is being worked on, but it will take time before the amount of time needed to get there has been spent. I'd be happy to try to give more pointers, but it is as I said, not yet very user friendly.
If I would add some way of auto-escaping the JS code and pointers on where to begin with manipulating the DOM maybe it would be better, just that I have too much going on as it is. If any dev wants to use this, please do! This I put here for devs who wants to use it to do cool stuff with the Dashboard. I think for, at least, a few of the devs they knew they could do this, just never got around to it, yet.
I hope this helps you, I don't mean to be short, it's just that it really isn't as much a release as it is just some code that can be used to get the JS in there. If you have some more specific questions on the way to get this to work, ask here and I will try to answer.

3 Likes