I try to do that all the time to disable or modify annoying JS features but it's so hard now that everybody minimizes their libraries. Any tips to deal with this?
Change the id/classes on the element that code applies to.
Make a copy of the elements, delete the original, and insert the copy. Then reimplement any JS that's actually needed yourself. Use fetch API if you need an original version of the HTML before JS.
Override getters/setters of properties on elements/nodes. The offending JS can make all the calls it wants but that doesn't matter if you control what the calls do. (Or similar redefinition/extension/hooking of base JS classes).
Web 2.0/widespread use of closures/minification/libraries like React made userscripting a lot more work. It was nice when you could easily hook/wrap anything :(
var a,a2,aa,b,c,z,x,c,cc,l2,ll,$_2, $_3;
Which is, unfortunately, a popular option minifiers offer (renaming variables and function names to shorter ones).