How to override anonymous function in JavaScript with Tampermonkey?

190 views Asked by At

I have a function I want to override in an anonymous function with Tampermonkey.

(()=>{
     /* other stuff */
     function Zm(e) {
            let {visible: t, onCancel: n} = e;
            const {windowWidth: a} = la((e=>e))
              , {isMobile: i} = a
              , o = Jm({
                isMobile: i
            });
            return (0,
            r.jsx)(Ga.Z, {
                width: 512,
                open: t,
                footer: null,
                className: o.modal,
                onCancel: n,
                children: (0,
                r.jsx)(r.Fragment, {
                    children: (0,
                    r.jsxs)("div", {
                        className: o.modalTop,
                        children: [(0,
                        r.jsx)("div", {
                            className: o.modalTopIcon,
                            children: (0,
                            r.jsx)(Za.Z, {
                                style: {
                                    fontSize: 65,
                                    marginRight: 5,
                                    color: "#FFAA00"
                                }
                            })
                        }), (0,
                        r.jsx)("div", {
                            className: o.modalDesc,
                            children: (0,
                            r.jsx)("span", {
                                className: o.greenText,
                                children: "Change me."
                            })
                        }), (0,
                        r.jsx)(Qa.Z, {
                            size: "large",
                            className: o.button,
                            type: "primary",
                            onClick: n,
                            children: "Got it"
                        })]
                    })
                })
            })
        }

     /* lots of other code */

    const ev = function() {        
    /* 1,000 other lines in function */
    /* Zm function called here */
    ), (0,
                r.jsx)(Zm, {
                    visible: _,
                    onCancel: ()=>{
                        ge(S(a.disabledModal))
                    }
                }), N && (0,
                r.jsx)(Dm, {}), false]
            })
        };
})();

How can I intercept to change the code?

I tried adding break points so I could manually intervene, and just rewrite the Zm function before execution. However, that does not work. The website just ends up running the unedited script in Brave still. There might be other code that can be intercepted, but this is close to 121,000 lines of Javascript total. How can I override this function with my own version?

For now, I'm just trying to change the line in the Zm function, which I've labeled Change Me.

I see I can use puppeteer to do this from this, but I'd prefer to not have to add additional plugins to my browser.

1

There are 1 answers

1
Dimava On

You may use https://chrome.google.com/webstore/detail/resource-override/pkoacgokdfckfpndoffpifphamojphii extension to override file content with modified one on the fly