dsh-whale-bridge: A Bridge Plugin Connecting Desktop Pets and Whale Charms

DeepSeek Harness (DSH) adopts a plugin-based architecture, allowing developers to combine features. However, existing desktop pet plugins (such as pet-whale) and widget plugins (such as dsh-whale-widget) usually run independently and lack direct interaction logic. The dsh-whale-bridge plugin solves this problem. It does not modify the source files of either plugin; instead, it observes their DOM structures and simulates user clicks at appropriate moments to coordinate the two plugins.

Core Capabilities

The plugin mainly provides the following features:

  1. Plugin chain: Connects pet-whale and dsh-whale-widget.
  2. Auto “pretend-to-work”: The desktop pet automatically enters its built-in mode when it approaches the widget, and automatically exits when it moves away.
  3. Orientation interaction: The desktop pet turns and tilts its head toward the widget, with real-time orientation calculation during dragging.
  4. Bubble broadcast: When the widget detects the desktop pet, it uses the default bubble to deliver lines.
  5. Stylesheet guard: Prevents the DSH client from accidentally deleting the pet-whale stylesheets.
  6. Runtime API: Provides the window.__dshWhaleBridge interface for debugging and configuration.

Technical Implementation Details

Synthetic Events and Interaction Simulation

The plugin triggers the target plugin’s logic by dispatching synthetic events (contextmenu, pointerdown, click) rather than directly manipulating internal variables. This approach avoids page repaint flicker that native DOM manipulation may cause, ensuring that menus and bubbles appear smoothly. For example, the “pretend-to-work” mode is triggered by dispatching a context menu event; bubble broadcasting is implemented by simulating clicks on the whale sprite and bubble frame.

Orientation and Head-tilt Control

The desktop pet’s orientation is controlled by the pet-whale animation, but that animation overrides inline transform properties. The plugin overrides the animated effect by directly injecting an inline style.transform into the internal <svg> element of the sprite. This method can simultaneously achieve mirroring, rotation, and tilting, while remaining decoupled from the parent drag logic. The tilt angle is dynamically calculated based on the vertical distance between the desktop pet and the widget, with a dead zone to avoid jitter.

Stylesheet Guard Mechanism

The DSH client module system claims <style> tags in the document that lack the data-plugin attribute as belonging to the current plugin and removes them during plugin reloads. Because pet-whale does not add this marker, styles may be lost. The plugin ensures that stylesheets can be automatically restored after a plugin reload by supplementing the data-plugin="pet-whale" attribute, caching the stylesheet text, and “mining” the source code from window.__ModuleLoader__.

Configuration Guide

Configuration is located in the dsh-whale-bridge namespace. Priority order: settings page > localStorage > built-in defaults.

Field Default Description
enabled true Master switch; when disabled, immediately exits “pretend-to-work” mode and stops broadcasting.
faceWidget true Whether the desktop pet sprite should face the widget during “pretend-to-work” mode.
leanMaxDeg 26 Maximum head-tilt angle (degrees).
leanRangePx 240 Vertical deviation in pixels considered “full tilt”.
leanDeadPx 12 Do not tilt when the vertical deviation is less than this value.
nearGapPx 140 The gap between the desktop pet and widget ≤ this value is considered “near”.
releaseGapPx 300 Gap > this value is considered “far”; between the two values is the hysteresis zone.
scanGapPx 200 The gap between the widget’s sightline and the desktop pet ≤ this value is considered “seen”.
faceWhileDragging true Whether to continue taking over orientation while dragging.
speakIntervalMs 25000 Minimum interval between broadcasts (anti-flicker).

Runtime API

// Get the currently effective configuration
window.__dshWhaleBridge.getConfig()

// Dynamically modify the configuration
window.__dshWhaleBridge.setConfig({ ... })

// View the current status (orientation, dragging state, stylesheet state, etc.)
window.__dshWhaleBridge.status()

Notes

  • Violates development guidelines: The plugin reads information from other plugins through DOM operations, violating the official DSH plugin development guideline requirement to “not read other plugins’ DOM”. This is a compromise to enable interaction when the counterpart does not provide an API.
  • Version dependency: Strictly depends on specific versions: pet-whale 1.2.6 and dsh-whale-widget 0.3.16. If a target plugin is upgraded and changes class names or text, update the selector constants in lib/client.js.
  • License: Uses the MIT License.

Summary

dsh-whale-bridge is a bridge tool tailored for specific versions of pet-whale and dsh-whale-widget. It solves the problem of two independent plugins being unable to work together, provides automatic “pretend-to-work” and orientation interaction features, and includes a robust automatic stylesheet self-repair mechanism.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye