How to create default template on "Respond to Customer/Add Internal Comment" textboxes in Javascript?

Hello everyone,

I am currently trying to create a script to set the text boxes to have some sort of default template/signature through TamperMonkey in Jira Service Desk Cloud when responding to customers.

So far, I have the following script and it works:

function checkVariable() {
    var elem = document.querySelector("div.ak-editor-content-area");
    if (elem) {
        var elem2 = elem.querySelector("div[contenteditable]").firstChild.innerHTML = "test";
    } else {
        setTimeout(checkVariable, 1000);

(function() {
    'use strict';
    if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {

However, the script above does not work unless I refresh the page. As soon as I change to a different ticket, the text “test” is not there anymore. Any thoughts on how I can get the button to trigger the script above or any other way that I can achieve this?

Any input would be greatly appreciated, thank you!

Ysfin Tazky