I'm not completely clear on what you're trying to do, but this might be what you want:
Put the JS in a chunk, let's call it 'MyJsChunk' with placeholders for the dynamic stuff.
Then put a snippet at the top of the page with code like this (the values on the left are the names of the placeholders, the ones on the right are the values you want to replace them with):
<?php
$fields = array(
'pagetitle' = $modx->resource->get('pagetitle'),
'longtitle' = $modx->resource->get('longtitle'),
/* etc. */
);
$tpl = $modx->getChunk('MyJsChunk', $fields);
$modx->regClientStartupScript($tpl);
return '';
If all the fields are resource fields from the current resource (No TVs), you can replace the $fields array with this:
$fields = $modx->resource->toArray();