TamperDAV

repository·master·Indexed 42 days ago

https://github.com/tampermonkey/tamperdav

A NodeJS-based WebDAV-like server version 1.0.0 designed to synchronize Tampermonkey scripts, enabling users to edit them using external desktop editors. It supports Basic Authentication, real-time syncing via a cursor system, and a cloud editor feature to open files in a local IDE.

Tokens
1.7K
Snippets
8
Records
12
Agent score
5%

What's inside TamperDAV

  1. Use TamperDAV with Tampermonkey

    master

    To use the full TamperDAV feature set, ensure the TamperDAV server is running before starting Tampermonkey.

    Tampermonkey syncs scripts into a subfolder of your configured path (e.g., Tampermonkey/sync) using internally generated UUIDs for filenames.

    To locate a specific script file:

    1. Via CLI: Run node find_script_in_meta.js --name="My Script Name".
    2. Via UI: Navigate to the script in the Tampermonkey UI and retrieve the UUID from the browser's address bar.
  2. Run TamperDAV

    master

    TamperDAV is a WebDAV-like server used to sync Tampermonkey scripts and edit them with an external editor. It requires Node.js version 4.9 or greater.

    Windows

    Execute the batch file:

    TamperDAV.bat

    Linux

    Execute the shell script:

    ./tamperdav.sh
  3. Configure TamperDAV

    master

    TamperDAV can be configured using a config.json file, command line arguments, or environment variables.

    Environment Variables

    Use TD_USERNAME and TD_PASSWORD to set authentication credentials via the environment.

    Command Line Example

    TD_USERNAME=derjanb TD_PASSWORD=secret node server.js --path=dav/ --port=6000

    Config File Example (config.json)

    {
        "path": "dav",
        "no-auth-warning": false,
        "username": "derjanb",
        "password": "secret",
        "port": "7000",
        "host": "localhost",
        "max-cursors": 512,
        "open-in-editor": "sublime_text",
        "meta-touch": true,
        "debug": true
    }
  4. How the TamperDAV WebDAV server works

    master

    TamperDAV implements a subset of the WebDAV protocol to allow clients (like Tampermonkey) to manage scripts.

    Key Features

    • Authentication: Supports Basic Authentication via --username and --password.
    • Real-time Syncing: Uses a SUBSCRIBE method and a cursor system to notify clients of file changes immediately. When a file is changed, the server uses chokidar to watch the directory and pushes updates to active subscribers.
    • Cloud Editor: Supports an EDITOR method. When triggered, the server uses the configured --open-in-editor to open the file locally on the host machine, allowing for a seamless transition from browser to local IDE.
    • Meta-touching: When --meta-touch is enabled, changing a .user.js file will trigger a write to its corresponding .meta.json file. This ensures that connected browsers detect the change via file timestamp updates.
  5. Run the TamperDAV server

    master

    TamperDAV is a WebDAV server that can be started via a shell script (./tamperdav.sh) or a batch file (TamperDAV.bat) on Windows. It serves files from a specified directory and supports authentication and real-time file watching.

    Configuration Precedence

    Options are applied in the following order of priority (highest to lowest):

    1. Command line parameters
    2. Environment variables (TD_USERNAME, TD_PASSWORD)
    3. Configuration file (config.json by default)

    Basic Usage

    To start the server with default settings (listening on localhost:7000):

    ./tamperdav.sh --path=./my-scripts

    To use a custom configuration file:

    ./tamperdav.sh --config=my-config.json
    #!/usr/bin/env nodejs
    # (Example of how the entrypoint is invoked via shell/bat)
  6. Configure TamperDAV via environment variables

    master

    For security or automated environments, you can set credentials using environment variables. These take precedence over the config.json file but are overridden by command-line arguments.

    • TD_USERNAME: The username for client authentication.
    • TD_PASSWORD: The password for client authentication.
  7. Configure TamperDAV via config.json

    master

    You can define server settings in a JSON file named config.json located in the same directory as server.js.

    Example config.json:

    {
        "path": "dav",
        "meta-touch": true,
        "username": "foo",
        "password": "bar",
        "port": 1234
    }
    {
        "path": "dav",
        "meta-touch": true,
        "username": "foo",
        "password": "bar",
        "port": 1234
    }
  8. TamperDAV Configuration Options Reference

    master

    The following options are available for configuration via config.json or command line arguments:

    OptionDescription
    pathA relative path from where the files should be served
    no-auth-warningDon't show a warning if no username and password is set
    usernameUsername for authentication (basic auth)
    passwordPassword
    portTCP port to listen at
    hostNetwork address to bind on
    max-cursorsNumber of cached changes
    open-in-editorIf "true" then if Windows "notepad" editor is used, else xgd-open; or the executable as string i.e. "gedit", "notepad", ...
    meta-touchTouch a sync entries's meta file automatically to make Tampermonkey start a sync on script changes
    no-dialogDisables the use of a dialog to show messages to the user
    headlessImplies --no-dialog and disables editor opening
    debugPrint debug information
  9. Configure TamperDAV via CLI options

    master

    You can configure the server behavior using command-line flags. All options except --help can also be provided in a config.json file.

    OptionDescription
    --helpShows this information
    --config=[path]Path to config file (default: config.json)
    --no-auth-warningDisables warning if username/password are missing
    --meta-touchUpdates .meta.json files when a .user.js script changes
    --debugEnables detailed debug output
    --open-in-editor=[editor]Specifies the editor for the Tampermonkey cloud editor icon. If omitted, uses system default.
    --username=[username]Authentication username
    --password=[password]Authentication password
    --host=[host]Network address to bind (default: localhost)
    --port=[port]Port to listen on (default: 7000)
    --path=[path]Relative path to the storage directory
    --max-cursors=[amount]Max number of cached changes to store (default: 512)
    --no-dialogDisables UI dialogs for messages
    --headlessImplies --no-dialog and disables editor opening
    {
        "path": "dav",
        "meta-touch": true,
        "username": "foo",
        "password": "bar",
        "port": 1234
    }