Efficiently pick a largest set of non-intersecting line segments
EDIT: Falk Hüffner gave a reduction in his comment to the question, the problem is in fact NP hard. What follows is pretty useless for that reason. I'll leave it up anyway so the answer doesn't look butchered.



This might be an NP-hard problem (as Teepeemm rightly pointed out, I did the reduction in the wrong direction, and I can't come up with one in the right direction), which would mean no one knows a subexponential algorithm. Brute force approach: check all sets whether some segments in them intersect, pick the largest one. This will cost you exponential time.

You can speed it up somewhat. Let n be the number of segments you have, then you can do a binary search like this: start out with checking whether there is a set with k1 := n/2 segments. If there is, check k2 := n*3/4, if there isn't, check k2 := n*1/4. Always remember all sets of the largest size for which you know that there exists something, because going up only supersets of those can work.

But to be completely honest, your best bet is to reduce this to SAT and use a SAT-solver. Anything you whip up yourself will pale in comparison to the finely tuned tools that SAT-solvers are nowadays. I don't know whether there is a SAT-solver you can easily use in Javascript though, you might have to use one on your server and let Javascript deal with the interpretation of results.
Another option would be to look into the algrithms mentioned on the sites that @MvG linked to in his comment to your question.