大家好呀!

Typora是我最喜欢使用的写作软件,在我使用Markdown文档写游戏开发笔记的时候,遇到一个问题那就是,很多时候我想给字体变一个好看的颜色

我还得在markdown里面一点一点的敲代码比如

我是一个苹果我是红色的

非常难受,而且我是一个懒懒虫,不想动手指,所以做了这个软件

使用方法一(推荐,最简单)

我的软件都包含在这个 FontColorChange5.zip(点击下载) zip包中了,解压挑选一个你们国家语言的exe版本下载即可,比如简体中文版本FontColorChange5(SimplifiedChinese).exe

这个是我的仓库地址点击跳转github仓库

下载点击exe后再进入Typora软件输入快捷键 Ctrl + Alt +C 可以打开操作界面

使用方法二(不推荐,但原理一样)

所以我听说存在这样一种东西:那就是Autohotkey,一个可以写自动化脚本的软件

点击下载Autohotkey

image-20251213210042947

你们只需要下载那个Autohotkey V2 版本就可以了,那个Autohotkey V1版本有非常多的Bug千万不要用(比如让你的电脑键盘不起作用和让你的电脑死机)

然后使用方法是下载我给你们的脚本(前提是你已经下载了Autohotkey V2)

然后第一步点击其中一个

image-20251213210558067

此时在电脑右下角出现这个东西,绿色的这个,表示脚本已经成功启动啦!

image-20251213210818091

然后打开你的Typora(这个脚本只可以在Typora中运行) 在上面随便写一句话并用鼠标左键选中

image-20251213211341596

按下快捷键Ctrl + Alt + C 如果不小心关掉了窗口还可以用这个快捷键呼唤出来

就会弹出一个窗口,然后你可以从中选择颜色哦

比如我选择 “红色”

image-20251213211535910

我的脚本分为这几代———如下所示

第一代: FontColorChange1.ahk(或exe)

​ 这个非常的简陋,只有单纯的文字,适合喜欢简约风格者

image-20251213211623719

第二代: FontColorChange2.ahk(或exe)

​ 这个添加了简单的颜色和增加了9种颜色,适合喜欢多种颜色者

image-20251213211825880

第三代: FontColorChange3.ahk(或exe)

​ 这个为了让颜色更加直观,每一个选项都添加了颜色,适合所有人

image-20251213212156576

第四代: FontColorChange4.ahk(或exe)

​ 增加自定义颜色的功能,你可以填写你想要的颜色的RBG值或者HEX值来选择颜色

image-20251214124212236

image-20251214124522725

第五代: FontColorChange5.ahk(或exe)

​ 目前为止功能相对完善的一个版本,强烈推荐使用,毕竟修复了前几个版本的一些已知的可更改问题,用起来更加方便的哦,布局更改之后我是觉得挺好看的哈哈哈

image-20251215215058956

image-20251215215127635

image-20251215215153058

这是第五代脚本的源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#Requires AutoHotkey v2.0
#SingleInstance Force
SendMode "Input"

; =========================
; 全局变量
; =========================
global ColorGui := 0
global CustomGui := 0
global InfoGui := 0
global CustomHex := "FF0000"


; =========================
; 仅在 Typora 生效
; =========================
#HotIf WinActive("ahk_exe Typora.exe")
^!c::ShowColorGui()
#HotIf


; =========================
; 预设颜色点击
; =========================
ApplyColorFromText(ctrl, *)
{
WinActivate "ahk_exe Typora.exe"
Sleep 40
AddFontColor(ctrl.Tag)
}


; =========================
; 主颜色窗口
; =========================
ShowColorGui()
{
global ColorGui

if IsObject(ColorGui)
{
ColorGui.Show()
return
}

; 创建窗口
ColorGui := Gui("+AlwaysOnTop +Resize", "字体颜色")
ColorGui.SetFont("s9")

; ===== 顶部按钮 =====
; 按钮宽 120,中间间距 20
infoBtn := ColorGui.AddButton("xm w120", "使用说明(必看)")
customBtn := ColorGui.AddButton("x+20 yp w120", "自定义颜色")

infoBtn.OnEvent("Click", (*) => ShowInfoGui())
customBtn.OnEvent("Click", (*) => ShowCustomColorGui())

; ===== 颜色定义 =====
colors := [
["DarkOrange","焦橙色"], ["Red","红色"], ["LightSkyBlue","天蓝"],
["Turquoise","绿松石"], ["MediumVioletRed","紫红"], ["Teal","蓝绿色"],
["Gold","金黄色"], ["DimGray","灰黑色"], ["DeepPink","亮粉色"],
["DodgerBlue","亮蓝"], ["LimeGreen","鲜绿"], ["OrangeRed","橙红"],
["SlateBlue","岩蓝"], ["Chocolate","巧克力"], ["Crimson","深红"],
["SeaGreen","海绿"], ["SteelBlue","钢蓝"], ["Black","纯黑"]
]

ColorHex := Map(
"DarkOrange","FF8C00","Red","FF0000","LightSkyBlue","87CEFA",
"Turquoise","40E0D0","MediumVioletRed","C71585","Teal","008080",
"Gold","FFD700","DimGray","696969","DeepPink","FF1493",
"DodgerBlue","1E90FF","LimeGreen","32CD32","OrangeRed","FF4500",
"SlateBlue","6A5ACD","Chocolate","D2691E","Crimson","DC143C",
"SeaGreen","2E8B57","SteelBlue","4682B4","Black","000000"
)

; ===== 布局参数 =====
colW := 120 ; 色块宽度(与顶部按钮一致)
rowH := 28 ; 色块高度
gapY := 6 ; 上下间距
startY := 45 ; 第一行颜色的起始Y坐标(稍微拉开一点点与按钮的距离,更好看)

; 这里的 gapX 必须等于顶部两个按钮的间距 (20)
; 计算右列的 X 偏移量:左边距(xm) + 按钮宽(120) + 间距(20) = 140

Loop colors.Length
{
c := colors[A_Index][1]
n := colors[A_Index][2]

; 计算行列 (0为左列, 1为右列)
col := (A_Index <= 9) ? 0 : 1
row := Mod(A_Index - 1, 9)

; >>> 核心修改:X坐标对齐逻辑 <<<
; 如果是左列(0),位置就是 xm
; 如果是右列(1),位置就是 xm+140 (即 xm + 宽度120 + 间距20)
xPosStr := (col == 0) ? "xm" : "xm+140"

; 计算 Y 坐标
yPos := startY + row * (rowH + gapY)

; 添加色块
; 0x200 保证垂直居中
t := ColorGui.AddText(
xPosStr " y" yPos " w" colW " h" rowH
" 0x200 Center Border Background" ColorHex[c],
n
)

t.SetFont(c="Black"||c="Crimson"||c="SlateBlue" ? "cWhite":"cBlack")
t.Tag := c
t.OnEvent("Click", ApplyColorFromText)
}

; 自动调整高度,宽度稍微给点余量避免紧贴边缘,但内容是绝对居中的
ColorGui.Show("w290 h370")
}


; =========================
; 提醒窗口(独立)
; =========================
ShowInfoGui()
{
global InfoGui

if IsObject(InfoGui)
{
InfoGui.Show()
return
}

InfoGui := Gui("+AlwaysOnTop +Resize", "使用说明")
InfoGui.SetFont("s9")

InfoGui.AddEdit(
"xm ym w400 h260 ReadOnly -VScroll Wrap",
"① 点击颜色,在 Typora 中为选中文本设置字体颜色`n`n"
"② 若不小心关闭主窗口,可使用 Ctrl + Alt + C 重新打开`n`n"
"③ 主窗口与所有小窗口均支持自由拉伸`n`n"
"④ 由于我的软件目前存在一个已知的暂时无法修复的Bug可能会导致文字消失,可使用 Ctrl + Z 撤回操作,以及如果你们想要将已经修改颜色的文字换一个颜色,对此我无能为力,你可以可使用 Ctrl + Z 撤回颜色或者删掉重新打字并再次选择颜色"
)

InfoGui.Show("w420 h300")
}


; =========================
; 自定义颜色窗口
; =========================
ShowCustomColorGui()
{
global CustomGui, CustomHex, ColorGui

if IsObject(CustomGui)
{
CustomGui.Show()
return
}

CustomGui := Gui("+AlwaysOnTop +Resize", "自定义颜色")
CustomGui.SetFont("s9")

; ===== HEX =====
CustomGui.AddText("xm", "HEX(不带 #)")
HexEdit := CustomGui.AddEdit("xm w260", CustomHex)

; ===== RGB =====
CustomGui.AddText("xm y+10", "RGB")
R := CustomGui.AddEdit("xm w80", "255")
G := CustomGui.AddEdit("x+10 yp w80", "0")
B := CustomGui.AddEdit("x+10 yp w80", "0")

; ===== 预览 =====
Preview := CustomGui.AddText(
"xm y+10 w260 h40 0x200 Center Border Background" CustomHex,
"颜色预览"
)

R.OnEvent("Change", (*) => UpdateFromRGB(R, G, B, HexEdit, Preview))
G.OnEvent("Change", (*) => UpdateFromRGB(R, G, B, HexEdit, Preview))
B.OnEvent("Change", (*) => UpdateFromRGB(R, G, B, HexEdit, Preview))
HexEdit.OnEvent("Change", (*) => UpdateFromHex(HexEdit, Preview))

refresh := CustomGui.AddButton("xm y+10 w260", "刷新预览")
refresh.OnEvent("Click", (*) => RefreshPreview(R, G, B, HexEdit, Preview))

apply := CustomGui.AddButton("xm y+6 w260", "使用该颜色")
apply.OnEvent("Click", (*) => ApplyCustomColor())

back := CustomGui.AddButton("xm y+6 w260", "返回")
back.OnEvent("Click", (*) => (CustomGui.Hide(), ColorGui.Show()))

CustomGui.Show("w300 h360")
}


; =========================
; 颜色逻辑
; =========================
UpdateFromRGB(R, G, B, HexEdit, Preview)
{
global CustomHex
CustomHex := Format("{:02X}{:02X}{:02X}", Clamp(R.Value), Clamp(G.Value), Clamp(B.Value))
HexEdit.Value := CustomHex
Preview.Opt("Background" CustomHex)
}

UpdateFromHex(HexEdit, Preview)
{
global CustomHex
if RegExMatch(HexEdit.Value, "^[0-9A-Fa-f]{6}$")
{
CustomHex := HexEdit.Value
Preview.Opt("Background" CustomHex)
}
}

ApplyCustomColor()
{
global CustomHex
WinActivate "ahk_exe Typora.exe"
Sleep 40
AddFontColor("#" CustomHex)
}

RefreshPreview(R, G, B, HexEdit, Preview)
{
global CustomHex, CustomGui

if RegExMatch(HexEdit.Value, "^[0-9A-Fa-f]{6}$")
CustomHex := HexEdit.Value
else
CustomHex := Format("{:02X}{:02X}{:02X}", Clamp(R.Value), Clamp(G.Value), Clamp(B.Value))

CustomGui.Hide()
Preview.Opt("Background" CustomHex)
CustomGui.Show()
}

Clamp(v)
{
if (v = "" || !IsNumber(v))
return 0
v := Integer(v)
return v < 0 ? 0 : v > 255 ? 255 : v
}

AddFontColor(color)
{
ClipSaved := ClipboardAll()
A_Clipboard := ""

Send "^c"
ClipWait 0.5

if (A_Clipboard != "")
{
A_Clipboard := "<font color='" color "'>" A_Clipboard "</font>"
Send "^v"
}
else
{
A_Clipboard := "<font color='" color "'></font>"
Send "^v"
Send "{Left 7}"
}

Sleep 30
A_Clipboard := ClipSaved
}

; =========================
; 启动即显示
; =========================
ShowColorGui()

所有脚本都存在一个明显的问题,那就是需要先启用脚本再鼠标左键选择要变色的文字,否则先选择文字再启用脚本点击颜色选项就会让文字消失或者出现乱码

未来我可能会再增加一个类似Photoshop的调色盘的功能,毕竟颜色不应该只局限于这18种,希望你们使用愉快!