Advice on how to correctly integrate more complex Javascript code - C#