Unfortunately I don't have any code (javascript or otherwise) that I can offer you.
Regarding the 4th point, in many cases you will find that you can't balance the number of times people sit out. Say you have 35 players, so 8 tables of 4 and 3 byes per round. Since 35 is not divisible by 3, you would need to play 35 rounds before you can have balanced byes.
I am not sure how many rounds you plan, but for multiples of 4 you might find the
file that I link to here called Foursome-Tournaments-v4 useful. Just ignore the A vs B stuff and when 4 people meet assign them to partners and opponents at random. It doesn't matter how you do this as no two people meet more than once, so all partners and opponents will be different.
For 20, 24, 28 and 32, you will get more rounds if you use the
foursome golf schedules here in a similar way.