why not use
background-blend-mode: overlay ;
in CSS?
https://developer.mozilla.org/en-US/docs/Web/CSS/blend-mode