Tldraw Chinese Font Support

Wenchao Cai (wallen)
2024-12-19T09:20:21Z

为Tldraw添加中文字体支持，自动监听字体变化

Tldraw Chinese Font Support Tampermonkey Script

Overview

This Tampermonkey script is designed to enhance the Tldraw web application by adding support for Chinese fonts. It automatically listens for font changes and applies the corresponding Chinese font styles.

Features

Automatic Font Change Detection: The script uses MutationObserver to monitor changes in the data-font attribute, ensuring that any font changes are immediately reflected with the correct Chinese font.

Four Font Styles Supported:

Draw: Corresponds to a cursive style, using "字语青梅硬笔" or "LXGW WenKai".

Sans: Maps to a sans-serif style, using "仓耳玄三01简繁" or "PingFang SC".

Serif: Aligns with a serif style, using "FZYouSongS 509R" or "宋体".

Mono: Targets a monospace style, using "等距更纱黑体 SC" or "LXGW WenKai Mono".

Installation

To use this script, you will need to have the Tampermonkey extension installed in your browser. Follow these steps to install and use the script:

1. Install the Tampermonkey extension from your browser's extension store.

2. Click on the Tampermonkey icon in your browser toolbar and select "Create a new script..."

3. Copy and paste the provided script into the editor.

4. Save the script.

Usage

Once installed, the script will run automatically on any page that matches the specified @match pattern (https://www.tldraw.com/*). It will monitor for font changes and apply the appropriate Chinese font styles without any further intervention.

Author

Your Name

Version

0.1

Notes

This script is intended for use with Tldraw and may not work as expected on other websites.

Ensure that the fonts listed are installed on your system or available for web use to benefit from this script.