Thanks for sharing, I just do the same with an improved code on a similar topic, because origin.indexOf(domain) === -1 can be bypassed.
If your domain is example.com, a malicious link to badexample.com would match because indexOf finds the substring and returns a position (not -1)
Perhaps the topics can be merged mixing the different techniques and detailing their pro/cons.