lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.39k stars 71 forks source link

unsafeWindow.stop(); isn't executing at document-start while in dev mode #130

Closed Thorvarium closed 9 months ago

Thorvarium commented 9 months ago

Hi, thanks for this awesome work!

I am having one little issue that I haven't been able to figure out:

When I have a regular user script, I can use window.stop() and // @run-at document-start and the page will stop loading even before rendering.

But, if I put inside main.tsx:

import { unsafeWindow} from "$"; unsafeWindow.stop();

the page only stops after loading and after a bunch of native scripts from the website executed.

Is there a way to create a small script file that will make that content be bundled together in the userscript instantly? Without having to wait for the dev server to load by entryScript.src? That is the only thing that I would like to have executed instantly before loading the dev server.

I am using the react-ts template.

lisonge commented 9 months ago
    monkey({
      entry: 'src/main.tsx',
      format: {
        generate(uOptions) {
          if (uOptions.mode === 'serve') {
            return (
              `
            // your code
            ` +
              '\n' +
              uOptions.userscript
            );
          }
          return uOptions.userscript;
        },
      },
Thorvarium commented 9 months ago

@lisonge awesome! I've inverted the concatenation to show under the headers