lisonge / vite-plugin-monkey

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

Add support for auto check for script update #127

Closed ShivamS136 closed 8 months ago

ShivamS136 commented 8 months ago

I believe this plugin is the best place to add this feature, let me know if you agree otherwise I'll create a new plugin.

Feature description

Many times the auto-update gets failed on extension level or user has that turned off. Due to this, critical script updates gets skipped. There must be a feature, which will add a function in the script on build which will check for script update in background.

How will it work

  1. if monkey.autoUpdate is true then a function will be added at the end of the script.
  2. This method will be executed with script load.
  3. This will hit an AJAX to the monkey.userscript.updateUrl || monkey.userscript.downloadUrl || monkey.userscript.download.
  4. It will parse the output of the request and extract Userscript meta for version and downloadUrl.
  5. If a newer version is available then the downloadUrl is opened in new tab to open extension page to update the script.

Usage

export default defineConfig({
  plugins: [
    monkey({
        // ... Other configs
        autoUpdate: {
            checkFrequency: 1800000,
            debug: true
        }
    })
  ]
});

Options

Optimization

If you agree this feature worths to add, I'd like to contribute

lisonge commented 8 months ago

This feature does not seem to be necessary to implement within this plugin project, as it is just simple script self-update logic and has no relevance to build tools.

ShivamS136 commented 8 months ago

Makes sense, should not be part of a build tool. Thanks. I'll check to add it via a separate project.