Cleanup some codes of script/dom

This pull request is based on #1063.