Refactoring $ method so same source can work with chrome extension