I have no clue about Javascript, but I know a thing or two about DOM and CSS. And I enjoy digging through documentation.
What I learned so far in the forum, is that scripts for desktop and Publish work differently. AFAIK on desktop you need a plugin to run a script, whereas in Publish you can add it to publish.js. So I’d approach the scripting for Publish separately from desktop.
How to add content with Javascript on Publish?
I found a script that adds Cookie banners. Apparently it is possible to trigger a script just by opening a page and to target a particular location in the page for the output:
Then I searched for “publish.js tags:publish”.
It shows other examples of publish.js adding content to a webpage, like a donation button.
Triggering a script on Publish seems straight-forward. But the difficult part seems to find useful selectors for parameters and output.
The way I understand it, you don’t call scripts in Markdown.