Make read preference work in scripts

Fakes a global `g` object when needed.