Error-prone substr() usage

This fixes an issue when a `$gist` value having `.js` is passed.