Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
snomiao committed Apr 13, 2021
1 parent c29fc58 commit 6ac326c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 145 deletions.
206 changes: 103 additions & 103 deletions Modules/Eval-Javascript.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ EvalJavaScriptByNodeServer(code){
sno.md5("asdf")
; 不存在则启动
if(!nodePID){
ToolTip, 正在启动 NodeJS...
TrayTip, EvalJS 模块, 正在启动 NodeJS...
EnvGet, USERPROFILE, USERPROFILE
escaped_USERPROFILE := RegExReplace(USERPROFILE, "\\", "\\")
; 生成服务端代码
Expand All @@ -135,114 +135,114 @@ EvalJavaScriptByNodeServer(code){
req.on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
let code = Buffer.concat(body).toString() || req.url.split('?').slice(1).join('?');
_eval(code)
.then(res => res?.toString !== ({}).toString && res?.toString() || JSON.stringify(res))
.catch(e => (console.error('错误', e), e.toString()))
.then(s => (console.log(s), res.end(s)))
});
}).listen(%port%)
let code = Buffer.concat(body).toString() || decodeURI(req.url.split('?').slice(1).join('?'))
res.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
_eval(code)
.then(res => res?.toString !== ({}).toString && res?.toString() || JSON.stringify(res))
.catch(e => (console.error('错误', e), e.toString()))
.then(s => (res.end(s), console.log('入:', code, '\n出:', s)))
});
}).listen(%port%)
}
)
serverScriptPath := A_Temp . "\eval-javascript-server.b1fd357f-67fe-4e2f-b9ac-e123f10b8c54.js"
FileDelete %serverScriptPath%
FileAppend, %serverCode%, %serverScriptPath%, UTF-8-Raw
; 最小化启动 nodejs 并启用调试,注意工作目录在用户文件夹
Run, node --inspect "%serverScriptPath%", %USERPROFILE%, Minimize, nodePID
FileDelete, %A_Temp%\EvalNodeJS.pid
FileAppend, %nodePID%, %A_Temp%\EvalNodeJS.pid, UTF-8-Raw
TrayTip, EvalJS 模块, NodeJS 服务已最小化启动。j
}
)
serverScriptPath := A_Temp . "\eval-javascript-server.b1fd357f-67fe-4e2f-b9ac-e123f10b8c54.js"
FileDelete %serverScriptPath%
FileAppend, %serverCode%, %serverScriptPath%, UTF-8-Raw
; 最小化启动 nodejs 并启用调试,注意工作目录在用户文件夹
Run, node --inspect "%serverScriptPath%", %USERPROFILE%, Minimize, nodePID
FileDelete, %A_Temp%\EvalNodeJS.pid
FileAppend, %nodePID%, %A_Temp%\EvalNodeJS.pid, UTF-8-Raw
TrayTip, EvalJS 模块, NodeJS 服务已最小化启动。
}
; 若没有代码需要执行则将进程退出
if(!code){
Process Exist, %nodePID%
if (ErrorLevel == nodePID)
Process Close, %nodePID%
return
; 若没有代码需要执行则将进程退出
if(!code){
Process Exist, %nodePID%
if (ErrorLevel == nodePID)
Process Close, %nodePID%
return
}
; 发送 eval 请求
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", "http://localhost:" port "/", true)
whr.Send(code)
whr.WaitForResponse()
result := whr.ResponseText
return result
}
; 发送 eval 请求
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", "http://localhost:" port "/", true)
whr.Send(code)
whr.WaitForResponse()
result := whr.ResponseText
return result
}
EvalJavaScriptByNodeStdIO(code){
; 定义工作临时文件
inputScriptPath := A_Temp . "\eval-javascript.b1fd357f-67fe-4e2f-b9ac-e123f10b8c54.js"
FileDelete %inputScriptPath%
jsonoutPath := A_Temp . "eval-javascript.b1fd357f-67fe-4e2f-b9ac-e123f10b8c54.json"
FileDelete %jsonoutPath%
EvalJavaScriptByNodeStdIO(code){
; 定义工作临时文件
inputScriptPath := A_Temp . "\eval-javascript.b1fd357f-67fe-4e2f-b9ac-e123f10b8c54.js"
FileDelete %inputScriptPath%
jsonoutPath := A_Temp . "eval-javascript.b1fd357f-67fe-4e2f-b9ac-e123f10b8c54.json"
FileDelete %jsonoutPath%

; 生成代码
realcode := ""
realcode .= "const _require = require;{" "`n"
realcode .= "const require=(m)=>{try{_require.resolve(m)}catch(e){_require('child_process').execSync('cd %USERPROFILE% && npm i -S '+m)};return _require(m)};" "`n"
realcode .= "const 雪 = new Proxy({}, {get: (t, p)=>require(p)}), sno=雪;" "`n"
realcode .= "const code = " EscapeQuoted(code) ";" "`n"
realcode .= "(async () => await eval(code))() `n"
realcode .= " .then(res => res?.toString !== ({}).toString && res?.toString() || JSON.stringify(res)) `n"
realcode .= " .then(s=>process.stdout.write(s)) `n"
realcode .= " .catch(e=>process.stderr.write(e.toString())) `n"
realcode .= "}" "`n"
; 写入纯 UTF8 脚本文件
FileAppend %realcode%, %inputScriptPath%, UTF-8-RAW
if (!FileExist(inputScriptPath)){
ToolTip % inputScriptPath
MsgBox 执行失败,未能写入脚本文件
Return "err"
}
; 执行 node 的指令
nodejsCommand := """" nodejsPath """" " " """" inputScriptPath """"
; 生成代码
realcode := ""
realcode .= "const _require = require;{" "`n"
realcode .= "const require=(m)=>{try{_require.resolve(m)}catch(e){_require('child_process').execSync('cd %USERPROFILE% && npm i -S '+m)};return _require(m)};" "`n"
realcode .= "const 雪 = new Proxy({}, {get: (t, p)=>require(p)}), sno=雪;" "`n"
realcode .= "const code = " EscapeQuoted(code) ";" "`n"
realcode .= "(async () => await eval(code))() `n"
realcode .= " .then(res => res?.toString !== ({}).toString && res?.toString() || JSON.stringify(res)) `n"
realcode .= " .then(s=>process.stdout.write(s)) `n"
realcode .= " .catch(e=>process.stderr.write(e.toString())) `n"
realcode .= "}" "`n"
; 写入纯 UTF8 脚本文件
FileAppend %realcode%, %inputScriptPath%, UTF-8-RAW
if (!FileExist(inputScriptPath)){
TrayTip 错误, % inputScriptPath "执行失败,未能写入脚本文件"
Return "err"
}
; 执行 node 的指令
nodejsCommand := """" nodejsPath """" " " """" inputScriptPath """"

if (0){
RunWait, % nodejsCommand, , Hide
; 读取纯 UTF8 输出
FileRead, out, *P65001 %jsonoutPath%
FileDelete %jsonoutPath%
}else{
shell := ComObjCreate("wscript.shell")
exec := shell.exec(nodejsCommand)
stderr := exec.stderr.readall()
stdout := exec.stdout.readall()
out := stdout
if(stderr){
TrayTip Error, % stderr
if (0){
RunWait, % nodejsCommand, , Hide
; 读取纯 UTF8 输出
FileRead, out, *P65001 %jsonoutPath%
FileDelete %jsonoutPath%
}else{
shell := ComObjCreate("wscript.shell")
exec := shell.exec(nodejsCommand)
stderr := exec.stderr.readall()
stdout := exec.stdout.readall()
out := stdout
if(stderr){
TrayTip Error, % stderr
}
; msgbox % out
}
; msgbox % out
; `清掉垃圾文件`
; run "notepad " %inputScriptPath%
FileDelete %inputScriptPath%
re := out ? out : ""
Return re
}
; `清掉垃圾文件`
; run "notepad " %inputScriptPath%
FileDelete %inputScriptPath%
re := out ? out : ""
Return re
}

#If CapsLockXMode
#If CapsLockXMode

; 使用 JS 计算并替换所选内容
-::
Clipboard =
SendEvent ^c
ClipWait, 1, 1
code := Clipboard
codeWithoutEqualEnding := RegExReplace(code, "\s+$", "")
Clipboard := SafetyEvalJavascript(codeWithoutEqualEnding)
SendEvent ^v
return
; 使用 JS 计算并替换所选内容
-::
Clipboard =
SendEvent ^c
ClipWait, 1, 1
code := Clipboard
codeWithoutEqualEnding := RegExReplace(code, "\s+$", "")
Clipboard := SafetyEvalJavascript(codeWithoutEqualEnding)
SendEvent ^v
return

; 使用 JS 计算并试图追加或替换所选内容
=::
Clipboard =
SendEvent ^c
ClipWait, 1, 1
code := Clipboard
codeWithoutEqualEnding := RegExReplace(code, "=?\s*$", "")
Clipboard := SafetyEvalJavascript(codeWithoutEqualEnding)
; 如果输入代码最后是空的就把结果添加到后面
if (code != codeWithoutEqualEnding){
SendEvent {Right}
}
SendEvent ^v
Return
; 使用 JS 计算并试图追加或替换所选内容
=::
Clipboard =
SendEvent ^c
ClipWait, 1, 1
code := Clipboard
codeWithoutEqualEnding := RegExReplace(code, "=?\s*$", "")
Clipboard := SafetyEvalJavascript(codeWithoutEqualEnding)
; 如果输入代码最后是空的就把结果添加到后面
if (code != codeWithoutEqualEnding){
SendEvent {Right}
}
SendEvent ^v
Return
44 changes: 12 additions & 32 deletions Modules/应用-OneNote2016增强.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -265,44 +265,31 @@ $!-::
Sleep, 200
altSend("jp")
Return
; SendEvent !={AppsKey}p

; 复制纯文本
$^+c::
Clipboard =
SendEvent ^c
ClipWait, 1
Clipboard := Clipboard
Return

; 粘贴纯文本
$^+v::
Clipboard := Clipboard
SendEvent ^v
Return

; ; 选择页面
; ^PgUp:: SendEvent ^{PgUp}^+a
; ^PgDn:: SendEvent ^{PgDn}^+a
; ; 将此页面向上合并
; $!j::
; SendEvent ^+t^a^x
; SendEvent ^{PgUp}^+t^{End}^v
; SendEvent ^{PgDn}^+a{Del}
; SendEvent ^{PgUp}
; Return

$!c::
SetKeyDelay, 1, 1 ; 配置纠错
SendEvent, {AltDown}wi{AltUp}
; 复制段落链接(并清洗成 onenote 链接
$!p::
Clipboard := ""
SendEvent {AppsKey}pp{Enter}
ClipWait, 1
if(ErrorLevel)
Return
Clipboard := Func("SafetyEvalJavascript").Call("``" Clipboard "``.match(/^(onenote:.*)$/mi)?.[0]||""""")
Return

; $!+x::
; Clipboard := ""
; SendEvent {AppsKey}y
; ClipWait 1
; Clipboard := RegExReplace(Clipboard, "([一-龥]) ", "$1")
; SendEvent ^!{Right 3}^v
; Return

; 重命名笔记
$F2:: SendEvent ^+t

Expand All @@ -318,15 +305,8 @@ $F3::
SendEvent {Left}
Return

; 移动笔记(尝试自动填入剪贴板)
$!m::
; SendEvent ^c
SendEvent ^!m
; WinWaitActive, ahk_class NUIDialog ahk_exe ONENOTE.EXE, , 1
; if(ErrorLevel)
; return
; SendEvent ^v
return
; 移动笔记
$!m:: SendEvent ^!m

; 移动分区
$!+m:: SendEvent ^+g{AppsKey}m
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# CapsLockX - 像**黑客**一样操作电脑

**黑客**一样操作电脑!CapsLockX 让你可以轻轻松松像电影里的**黑客**一样,双手不离开键盘,**高效率**地操作电脑。这里有超多一摸就懂超好上手的功能:编辑增强、虚拟桌面与窗口管理、鼠标模拟、应用内热键增强、JS 数学表达式计算、等超多功能等你来定义
**黑客**一样操作电脑!CapsLockX 是一款基于 AutoHotkey 的热键脚本合集。让你可以轻轻松松像电影里的**黑客**一样,双手不离开键盘,**高效率**地操作电脑。这里有超多一摸就懂超好上手的功能:编辑增强、虚拟桌面与窗口管理、鼠标模拟、应用内热键增强、JS 数学表达式计算、等超多功能等你来亲自定义

[![jsdelivr](https://data.jsdelivr.com/v1/package/npm/capslockx/badge)](https://www.jsdelivr.com/package/npm/capslockx)
[![Publish](https://github.com/snomiao/CapsLockX/actions/workflows/publish.yml/badge.svg)](https://github.com/snomiao/CapsLockX/actions/workflows/publish.yml)
Expand Down
1 change: 1 addition & 0 deletions Tools/setup_repos.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ REM [Working with Git remotes and pushing to multiple Git repositories | Jigariu
git remote remove remote
git remote add remote git@github.com:snomiao/CapsLockX.git
git remote set-url --add --push remote git@github.com:snomiao/CapsLockX.git
git remote set-url --add --push remote git@github.com:snolab/CapsLockX.git
git remote set-url --add --push remote git@gitlab.com:snomiao/CapsLockX.git
git remote set-url --add --push remote git@gitee.com:snomiao/CapslockX.git
git remote set-url --add --push remote git@bitbucket.org:snomiao/capslockx.git
Expand Down
18 changes: 9 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
| 在 Anki-学习界面 | 5 或 NumPad5 | 撤销 |
| 在 Anki-学习界面 | 6 或 NumPad6 | 暂停卡片 |
| 在 Anki-学习界面 | Alt + i | 快速导入剪贴版的内容(按 Tab 分割) / 比如可以从 Excel 复制 |
| 在 Anki-添加卡片界面 | Alt + s | 按下 添加 按钮 |
| 在 Anki-添加卡片界面 | Alt + s | 按下 添加 按钮 |

> 此插件可配合手柄使用,使用 XPadder 配置手柄摇杆映射到方向键即可。
>
Expand Down Expand Up @@ -304,21 +304,21 @@

### TIM添加常驻功能模块

| 模式 | 按键 | 功能 |
| ----------- | :---------: | ---------------------- |
| 在Tim窗口内 | Alt + f | 焦点定位到左上角搜索框 |
| 在Tim窗口内 | Ctrl + PgUp | 切换上一个窗口 |
| 在Tim窗口内 | Ctrl + PgDn | 切换下一个窗口 |
|模式|按键|功能|
| - | :-: | - |
| 在Tim窗口内 |Alt + f| 焦点定位到左上角搜索框|
| 在Tim窗口内 |Ctrl + PgUp| 切换上一个窗口|
| 在Tim窗口内 |Ctrl + PgDn| 切换下一个窗口|

<!-- 模块文件名:应用-讯飞输入法语音悬浮窗.ahk-->

### 讯飞输入法悬浮窗插件

#### 用法

| 作用于 | 按键 | 功能说明 |
| ------ | :-----: | --------------------- |
| 全局 | Win + H | 启动/切换讯飞语音输入 |
| 作用于 | 按键| 功能说明 |
| - | :-: | - |
| 全局 | Win + H | 启动/切换讯飞语音输入 |

####

Expand Down

0 comments on commit 6ac326c

Please sign in to comment.