The mathematics for this calculation is explained here:
What is the formula for calculating the total cost of a loan with extra payments towards the principal?
First calculating for loan without extra repayments
n is the number of periods
s is the principal
r is the periodic interest rate
d is the periodic repayment
n = 40*52 = 2080
s = 123500
r = 9/100/52
d = r (1 + 1/(-1 + (1 + r)^n)) s = 219.774
Check
n = -(Log[1 - (r s)/d]/Log[1 + r]) = 2080
interest = n d - s = 333629.405
Now adding m and d2
m is the number of periods after which extra repayments are made
d2 is the repayment including the extra amount
m = 29*52 = 1508
d2 = d + 566 = 785.774
The formula for a loan with extra repayment towards the end is

∴ n = -(Log[((1 + r)^-m (-d + d2 + (1 + r)^m (d - r s)))/d2]/Log[1 + r]) = 1619.72
With the extra repayment the loan is repaid in 1619.72/51 = 31.15 years. Treatment of the incomplete week is up to the lender, who may require a larger payment on week 1619 to complete repayment or take a smaller repayment in week 1620. (This can slightly affect the total interest.)
interest = m d + (n - m) d2 - s = 295703.813
interest saving = 333629.405 - 295703.813 = 37925.59
Rounded to the dollar the saving calculate with a partial week is 37926.
Comparison with website results
8 year 10 months is (8*12) + 10 = 106 months
40 year loan less 106 months is 40*12 - 106 = 374 months
Calculated term is 1619.72*12/52 = 373.782 months
Website interest saved is 37925.
Amortization amortization table
Using an amortization table calculates the interest saving minutely differently due to the treatment of the incomplete week. In the table the final week's balance is held for the full week whereas the formula uses a fraction of a week for a linear solution.
Saving by formula: 2080 d - (m d + (n - m) d2) = 37925.59
Amortization table: 2080 d - s - 295703.950225 = 37925.46
Amortization table showing figures and formulas

Whole final week calculation without amortisation table
The following calculates the interest saving assuming the final week carries a whole week's interest and matches the website, (rounded to the dollar).
n = 40*52 = 2080
s = 123500
r = 9/100/52
d = r (1 + 1/(-1 + (1 + r)^n)) s = 219.774
interest for loan with no extra payments
i1 = n d - s = 333629.405
increased payment
d2 = d + 566
number of week at initial payment d
m = 1508
time needed to repay (as linear calculation)
n = -(Log[((1 + r)^-m (-d + d2 + (1 + r)^m (d - r s)))/d2]/Log[1 + r]) = 1619.72
number of whole weeks
n2 = 1619
present value of amount repaid up to and including week 1508
s2 = (d - d (1 + r)^-m)/r = 117621.856
present value remaining
s3 = s - s2 = 5878.144
future value of remainder at week 1508
s4 = s3 (1 + r)^m = 79757.043
number of weeks from 1508 to 1619
n3 = 1619 - 1508 = 111
amount paid by d2 in 111 weeks
s5 = (d2 - d2 (1 + r)^-n3)/r = 79292.149
future value remaining in week 1508
s6 = s4 - s5 = 464.894
future value remaining in week 1619 (note this matches the amortisation table)
s7 = s6 (1 + r)^n3 = 563.2699
interest from week 1619 to week 1620
i3 = s7 r = 0.97489
interest paid with extra payments
i2 = m d + n3 d2 + s7 + i3 - s = 295703.950
interest saving
i1 - i2 = 37925.455
Rounded to the dollar, 37925.
Addendum re. zero interest rate
When the interest rate is zero the standard loan equation becomes

∴ d = s/n
and the equation for a loan with extra payments becomes

∴ n = (s + d2 m - d m)/d2
Rerunning the calculation as described above
n = 40*52
s = 123500
r = 0
d = s/n = 59.375
i1 = n d - s = 0
d2 = d + 566
m = 1508
n = (s + d2 m - d m)/d2 = 1562.307
n2 = 1562
s2 = d m = 89537.5
s3 = s - s2 = 33962.5
s4 = s3 (1 + r)^m = 33962.5
n3 = 1562 - 1508 = 54
s5 = d2 n3 = 33770.25
s6 = s4 - s5 = 192.25
s7 = s6 (1 + r)^n3 = 192.25
i3 = s7 r = 0
i2 = m d + n3 d2 + s7 + i3 - s = 0
i1 - i2 = 0