Created
October 29, 2022 15:52
-
-
Save emisjerry/6a14b86caebdc37ff963337848709269 to your computer and use it in GitHub Desktop.
Patch to Obsidian fleet.md, using local REST API plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ;; Windows cmd.exe 多行分隔號用 ^ | |
curl -X "POST" ^ | |
"https://127.0.0.1:27124/vault/030-Inbox/fleet.md" ^ | |
-H "accept: */*" ^ | |
-H "Authorization: Bearer 4c1f7a807f92a153944269bfd610571970a887b3952a9b2161b9cb98e9f8708a" ^ | |
-H "Content-Type: text/markdown" ^ | |
-d "## This is my document something else here" | |
*/ | |
#SingleInstance Force | |
^+k:: | |
text = %Clipboard% | |
text := MultiLineInputBox("Your ideas: ", text, "Insert your ideas into fleet note") | |
if (text != "") { | |
URL := "https://127.0.0.1:27124/vault/030-Inbox/fleet.md" | |
;;TEXT := "# 測試筆記`n`nLocal REST API 測試`n" . "Time: " . A_HOUR . A_MIN . A_SEC | |
text = | |
( | |
## %A_YYYY%:%A_MM%:%A_DD% %A_HOUR%:%A_MIN%:%A_SEC% | |
%text% | |
--- | |
) | |
oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
oHTTP.Open("POST", URL , False) | |
oHTTP.SetRequestHeader("Content-Type", "text/markdown") | |
oHTTP.SetRequestHeader("Authorization", "Bearer 4c1f7a807f92a153944269bfd610571970a887b3952a9b2161b9cb98e9f8708a") | |
oHTTP.Send(TEXT) | |
sResponse := oHTTP.ResponseText | |
if (sResponse == "") { | |
oHTTP.Open("GET", URL , False) | |
oHTTP.SetRequestHeader("Content-Type", "text/markdown") | |
oHTTP.SetRequestHeader("Authorization", "Bearer 4c1f7a807f92a153944269bfd610571970a887b3952a9b2161b9cb98e9f8708a") | |
oHTTP.Send() | |
sResponse := oHTTP.ResponseText | |
} | |
MsgBox Response is %sResponse% | |
/*;; w=width, h=height, r=rows | |
Gui, Add, Edit, w400 h100 r10, % sResponse | |
Gui, Add, Edit, w400 h100 r10, % oHTTP.GetAllResponseHeaders | |
Gui, Show, AutoSize Center | |
*/ | |
} | |
return | |
MultiLineInputBox(Text:="", Default:="", Caption:="Multi Line Input Box"){ | |
static | |
ButtonOK:=ButtonCancel:= false | |
if !MultiLineInputBoxGui{ | |
Gui, MultiLineInputBox: Font, s14, Segoe UI | |
Gui, MultiLineInputBox: add, Text, r1 w600 , % Text | |
Gui, MultiLineInputBox: add, Edit, r10 w600 vMultiLineInputBox, % Default | |
Gui, MultiLineInputBox: add, Button, w100 h50 x380 gMultiLineInputBoxOK , &OK | |
Gui, MultiLineInputBox: add, Button, w100 h50 x+10 gMultiLineInputBoxCancel, &Cancel | |
MultiLineInputBoxGui := true | |
} | |
GuiControl,MultiLineInputBox:, MultiLineInputBox, % Default | |
Gui, MultiLineInputBox: Show,, % Caption | |
SendMessage, 0xB1, 0, -1, Edit1, A | |
while !(ButtonOK||ButtonCancel) | |
continue | |
if ButtonCancel | |
return | |
Gui, MultiLineInputBox: Submit, NoHide | |
Gui, MultiLineInputBox: Cancel | |
return MultiLineInputBox | |
;---------------------- | |
MultiLineInputBoxOK: | |
ButtonOK:= true | |
return | |
;---------------------- | |
MultiLineInputBoxGuiEscape: | |
MultiLineInputBoxCancel: | |
ButtonCancel:= true | |
Gui, MultiLineInputBox: Cancel | |
return | |
} | |
encodeURI(Uri, Enc = "UTF-8") | |
{ | |
StrPutVar(Uri, Var, Enc) | |
f := A_FormatInteger | |
SetFormat, IntegerFast, H | |
Loop | |
{ | |
Code := NumGet(Var, A_Index - 1, "UChar") | |
If (!Code) | |
Break | |
If (Code >= 0x30 && Code <= 0x39 ; 0-9 | |
|| Code >= 0x41 && Code <= 0x5A ; A-Z | |
|| Code >= 0x61 && Code <= 0x7A) ; a-z | |
Res .= Chr(Code) | |
Else | |
Res .= "%" . SubStr(Code + 0x100, -1) | |
} | |
SetFormat, IntegerFast, %f% | |
Return, Res | |
} | |
decodeURI(Uri, Enc = "UTF-8") | |
{ | |
Pos := 1 | |
Loop | |
{ | |
Pos := RegExMatch(Uri, "i)(?:%[\da-f]{2})+", Code, Pos++) | |
If (Pos = 0) | |
Break | |
VarSetCapacity(Var, StrLen(Code) // 3, 0) | |
StringTrimLeft, Code, Code, 1 | |
Loop, Parse, Code, `% | |
NumPut("0x" . A_LoopField, Var, A_Index - 1, "UChar") | |
StringReplace, Uri, Uri, `%%Code%, % StrGet(&Var, Enc), All | |
} | |
Return, Uri | |
} | |
StrPutVar(Str, ByRef Var, Enc = "") | |
{ | |
Len := StrPut(Str, Enc) * (Enc = "UTF-16" || Enc = "CP1200" ? 2 : 1) | |
VarSetCapacity(Var, Len, 0) | |
Return, StrPut(Str, &Var, Enc) | |
} | |
GuiClose: | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment