Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Simple Sheet Worker Question

Greetings! I am aware that you cannot use JavaScript on your character sheet due to security concerns. I'm opting to use Sheet Workers instead, and while I know that it can be used to change values within number fields, can it also serve to change CSS formats? I'm thinking of something along the lines of changing your Status, which gets autocalculated based on your current HP, the values varying from Alive, to Unconscious, to Dead, having the text color change from black to orange to red for their respective conditions. Is this possible? thanks for your time!
1491133869
Lithl
Pro
Sheet Author
API Scripter
Sheet worker scripts are  JavaScript, for the record. They're simply sandboxed. =) As to your question, no, sheet workers cannot modify CSS (either changing the actual CSS, or changing the classes/style of an element). That said, you could  have a sheet worker modify an attribute which is backing a checkbox or radio button, and use that input's :checked pseudo-selector to style other elements. Something along the lines of: <input type="radio" class="sheet-status sheet-alive" name="attr_status-style" value="alive" checked> <input type="radio" class="sheet-status sheet-unconscious" name="attr_status-style" value="unconscious"> <input type="radio" class="sheet-status sheet-dead" name="attr_status-style" value="dead"> <input type="text" class="sheet-status-name" name="attr_status"> <script type="sheet/worker"> on('change:status', function() { getAttrs(['status'], function(values) { setAttrs({'status-style': values.status}); }); }); </script> .sheet-status { display: none; } .sheet-alive:checked ~ .sheet-status-name { color: green; } .sheet-unconscious:checked ~ .sheet-status-name { color: blue; } .sheet-dead:checked ~ .sheet-status-name { color: red; }
Interesting work around -- I'll have to give this a shot! Thanks for your help :D