The script uses the Weighted Inclusive Gregory Method for reallocating surplus votes. The quota for election is (number of votes)/(number of seats + 1) rounded up to two decimal places. At each stage of the count, if more than one candidate has surplus votes, the largest surplus will be transfered first. All ties are broken randomly.
You can re-use the Javascript code in this page under the terms of the GNU AGPL. See the licence notice in the source of the page for more details.