Ok, fiddled with it more and got it to work. The link is updated
Found that fixed resolution canvas' scale the image when loading pixel data, so left it at automatic. Also changed the line detection to use a tolerance.
Found that pasting repeatedly blurs the lines so I combined the pixel data directly with some javascript.
The only issue now is that the delay from making the mask is noticeable.