# Help with header code

**URL:** <https://discourse.nodered.org/t/help-with-header-code/41835>\
**Category:** General\
**Created:** [1 March 2021 16:25 UTC](https://discourse.nodered.org/t/help-with-header-code/41835 "2021-03-01T16:25:48Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 March 2021 23:58 UTC](https://discourse.nodered.org/t/help-with-header-code/41835/4 "2021-03-01T23:58:11Z")

</div>

> [@Sean-McG](#):
>
> What about the scope part - can /should it be made into one script ?

sure

```auto
<script>
    (function(scope) {
        
        scope.$watch('msg', function(data) {
            var elem = document.getElementById(data.topic)
            if(elem !== null) {
                if (data.hasOwnProperty('fontFamily')) {elem.style.fontFamily = data.fontFamily}
                if (data.hasOwnProperty('fontStyle')) {elem.style.fontStyle = data.fontStyle}
                if (data.hasOwnProperty('color')) {elem.style.color = data.color}
                if (data.hasOwnProperty('fontSize')) {elem.style.fontSize = data.fontSize}
                if (data.hasOwnProperty('fontWeight')) {elem.style.fontWeight = data.fontWeight}
                if (data.hasOwnProperty('payload')) {elem.innerHTML = data.payload};
                if (data.hasOwnProperty('image')) {elem.src = data.image};
                
            }
        });

        var theScope = scope;
        var myButton = document.getElementById("my-refresh-button");
        if(!myButton) {
          var button = document.createElement('BUTTON');
          button.addEventListener('click', sendPayload);
          button.innerHTML ='Refresh'
          button.id = 'my-refresh-button'
          var titleBar = document.getElementById("nr-dashboard-toolbar");
          titleBar.append(button);
        }
        function sendPayload(){
            theScope.send("1");
        }

    })(scope);

</script>

```

---

_[View the full topic](https://discourse.nodered.org/t/help-with-header-code/41835)._
