These two methods are mostly similar.  It'd be better to extract the parts that vary into their own methods instead of having them in an if/else here.

In fact, this whole getSelection section should be it's own object, function or at the very least, method.