右键长按超过 200ms, 高亮选中的typora内容, win+a换颜色
可执行文件:
markdown语法通用无侧键版本适配.rar - 蓝奏云
源代码:
#NoEnv
#SingleInstance force; 配置文件路径
configFile := A_ScriptDir "\config.ini"; 定义样式方案
styles := {}
styles["秋日暖阳"] := "<span style=""background:#FFF8E1; color:#BF360C; padding:0.2em 0.5em; border:1px solid #FFE082; border-radius:3px"">{text}</span>"
styles["石墨文档"] := "<span style=""background:#F5F5F5; color:#424242; padding:0.15em 0.3em; border-left:3px solid #9E9E9E"">{text}</span>"
styles["深海蓝调"] := "<span style=""background:#E3F2FD; color:#1565C0; padding:0.15em 0.4em; box-shadow:0 1px 3px rgba(21,101,192,0.1)"">{text}</span>"
styles["午夜模式"] := "<span style=""background:#37474F; color:#ECEFF1; padding:0.15em 0.35em; text-shadow:0 1px 1px rgba(0,0,0,0.3)"">{text}</span>"
styles["春意盎然"] := "<span style=""background:#E8F5E9; color:#2E7D32; padding:0.15em 0.4em; border-radius:12px; box-shadow:0 2px 4px rgba(46,125,50,0.1)"">{text}</span>"
styles["蜜桃宣言"] := "<span style=""background:#FFE0E0; color:#8B0000; padding:0.2em 0.6em; border:2px solid #FFB3BA; font-weight:600"">{text}</span>"
styles["石墨文档(合同条款)"] := "<span style=""background:#F0F0F0; color:#000000; padding:0.1em 0.3em; border-left:4px solid #808080; font-family:等线"">{text}</span>"; 读取配置文件中的当前样式,默认使用“秋日暖阳”
IniRead, currentStyle, %configFile%, Settings, Style, 秋日暖阳; 确保 currentStyle 存在于 styles 中
if !styles.HasKey(currentStyle)currentStyle := "秋日暖阳"; 鼠标右键按下热键
RButton::; 记录按下时间downTime := A_TickCount; 等待右键松开KeyWait, RButton; 记录松开时间upTime := A_TickCount; 计算按住时间pressDuration := upTime - downTime; 如果按住时间超过 300 毫秒,则触发if (pressDuration > 300){; 确保在 Typora 中操作; if !WinActive("ahk_exe Typora.exe"); {; MsgBox, 请在 Typora 中使用此快捷键。; return; }; 使用当前样式if !styles.HasKey(currentStyle)currentStyle := "秋日暖阳"; 获取选中文字Send, ^c ; 复制选中的文字Sleep, 100 ; 等待 100 毫秒,确保剪贴板同步ClipWait, 2 ; 等待剪贴板内容,最多 2 秒if ErrorLevel{MsgBox, 未能获取选中文字,请重试。return}selectedText := clipboardtemplate := styles[currentStyle]highlightedText := StrReplace(template, "{text}", selectedText)clipboard := highlightedTextSleep, 100 ; 等待 100 毫秒Send, ^v ; 粘贴回去Sleep, 100 ; 延时Send, {Space} ; 加个空格,快速显示原文Sleep, 100 ; 延时Send, ^s ; 保存原文Sleep, 100 ; 延时}else{; 如果按住时间不足 300 毫秒,模拟右键单击以保留默认行为Send, {RButton}}
return; 快捷键 Ctrl+Alt+D:选择样式
#a::Gui, StyleSelector:New, , 选择样式Gui, Add, Text, , 请选择一个样式:for styleName in styles{Gui, Add, Button, gSelectStyle, %styleName%}Gui, Show
return; 选择样式后更新 currentStyle 并保存到配置文件
SelectStyle:Gui, SubmitselectedStyle := A_GuiControlcurrentStyle := selectedStyleIniWrite, %currentStyle%, %configFile%, Settings, StyleGui, DestroyMsgBox, 已选择样式: %currentStyle%
return