-
Notifications
You must be signed in to change notification settings - Fork 17
/
smpic.ahk
162 lines (146 loc) · 3.99 KB
/
smpic.ahk
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
;###########################################################
; @author ob
; @version 2.0.1
; @date 20220305
; http://github.com/kookob/smpic
;###########################################################
#SingleInstance,Force
#NoEnv
SendMode,Input
DetectHiddenWindows,On
SetWinDelay,0
SetKeyDelay,0
SetControlDelay,0
SetBatchLines,10ms
CoordMode,Mouse,Screen
applicationname=smpic
Gosub,READINI
Gosub,TRAYMENU
#Include %A_ScriptDir%\CreateFormData.ahk
#Include %A_ScriptDir%\JSON.ahk
;上传图片
upload(file, secretToken){
IfExist % file
{
objParam := {"format":"json", "smfile": [file]}
CreateFormData(PostData, hdr_ContentType, objParam)
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", "https://sm.ms/api/v2/upload", True)
whr.SetRequestHeader("Content-Type", hdr_ContentType)
whr.SetRequestHeader("Authorization", secretToken)
whr.Send(PostData)
whr.WaitForResponse()
return whr.ResponseText
}
}
IniRead, key, %applicationname%.ini, Settings, key, ^!s
IniRead, urlType, %applicationname%.ini, Settings, urlType, 0
IniRead, secretToken, %applicationname%.ini, Settings, secretToken, ReplaceWithYourSecretToken
Hotkey, %key%, UploadLabel, On
return
UploadLabel:
clipboard =
send,^c
ClipWait
filepathList = %clipboard%
clipboard =
Loop, parse, filepathList, `n, `r
{
filepath = %A_LoopField%
SplitPath, filepath, filename
result := upload(filepath, secretToken)
if(result <> ""){
resultJson := JSON.Load(result)
if(resultJson.code = "success"){
if(clipboard <> "") {
clipboard := clipboard . "`n"
}
if(urlType = 1) {
clipboard := clipboard . "![" . filename . "](" . resultJson.data.url . ")" ;markdown地址
} else {
clipboard := clipboard . resultJson.data.url ;原始地址
}
ToolTip, (%A_Index%)上传成功,url已复制到剪切板, A_CaretX, A_CaretY+20
Sleep 1000
ToolTip,
} else if(resultJson.code = "image_repeated"){
msg := "(" . A_Index . ")" . resultJson.error . "`n上传图片已存在,原有url已复制到剪切板"
msgbox % msg
if(clipboard <> "") {
clipboard := clipboard . "`n"
}
clipboard := clipboard . resultJson.images ;原始地址
} else {
msgbox % resultJson.error
}
} else {
msgbox 上传失败,请稍候再试!
}
}
return
TRAYMENU:
Menu,Tray,NoStandard
Menu,Tray,DeleteAll
Menu,Tray,Add,启用(&E),TOGGLE
Menu,Tray,Add,
Menu,Tray,Add,设置(&S),SETTINGS
Menu,Tray,Add,重启(&R),RESTART
Menu,Tray,Add,
Menu,Tray,Add,关于(&A),ABOUT
Menu,Tray,Add,退出(&Q),EXIT
Menu,Tray,ToggleCheck,启用(&E)
Menu,Tray,Tip,%applicationname%
Return
TOGGLE:
Menu,Tray,ToggleCheck,启用(&E)
Pause,Toggle
Return
SETTINGS:
Gosub,READINI
Run,%applicationname%.ini
Return
RESTART:
Reload
Return
EXIT:
ExitApp
READINI:
IfNotExist,%applicationname%.ini
{
ini=;%applicationname%.ini
ini=%ini%`n`;key: 快捷键设置:对应按键win(#),ctrl(^),alt(!),shitf(+),默认是(^!s)
ini=%ini%`n`;urlType: 返回结果url:0-原始地址(默认),1-markdown地址
ini=%ini%`n`;secretToken: sm.ms账号登录获取: https://sm.ms/home/apitoken
ini=%ini%`n`;(改完配置,重启生效)
ini=%ini%`n
ini=%ini%`n[Settings]
ini=%ini%`nkey=^!s
ini=%ini%`nurlType=0
ini=%ini%`nsecretToken=请配置自己的Secret Token
ini=%ini%`n
FileAppend,%ini%,%applicationname%.ini
ini=
}
Return
ABOUT:
Gui,99:Destroy
Gui,99:Margin,15,15
Gui,99:Font,Bold
Gui,99:Add,Text,y+10, %applicationname% v2.0.1 (20220305)
Gui,99:Font
Gui,99:Add,Text,y+10,选中图片(可多选)按快捷键(默认:Ctrl+Alt+S)上传图片到sm.ms,保存图片地址到剪切板
Gui,99:Font,CBlue Underline
Gui,99:Font
Gui,99:Font,Bold
Gui,99:Add,Text,y+20,github地址(★)
Gui,99:Font
Gui,99:Font,CBlue Underline
Gui,99:Add,Link,y+5, <a href="http://github.com/kookob/smpic">http://github.com/kookob/smpic</a>
Gui,99:Font,Bold
Gui,99:Add,Text,y+20,致谢
Gui,99:Font
Gui,99:Add,Text,y+10,感谢 https://sm.ms 提供的图床
Gui,99:Show,,%applicationname% About
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt")
OnMessage(0x200,"WM_MOUSEMOVE")
Return