Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; TODO: ADAPT FILEPATH BELOW
- ; Copies a highlighted words and its context plus browser source URL (Firefox) to a file
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- ; #Warn ; Enable warnings to assist with detecting common errors.
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- ^3::
- tmp := clipboard
- clipboard := ""
- Send, ^c
- ClipWait, 2
- word := RegExReplace( RegExReplace(RegExReplace(clipboard, "\r?\n"," "), "(^\s+|\s+$)"), ";", "," )
- clipboard := ""
- bLength := StrLen(clipboard)
- rRegex := "[\.!?]"
- rReplaceRegex := "(.+[\.!?]+)[^\.!?]*"
- lRegex := "[:\.!?]"
- lReplaceRegex := ".*[:\.!?]\)*\s*(.+)"
- Send, +{Down}
- IfWinActive ahk_exe firefox.exe
- Loop
- {
- Send, ^c
- ClipWait, 2
- aLength := StrLen(clipboard)
- if ( RegExMatch( clipboard, rRegex ) or bLength == aLength )
- break ; Terminate the loop
- else {
- Send, +{Right}
- clipboard := ""
- bLength := aLength
- continue ; Skip the below and start a new iteration
- }
- }
- rContext := RegExReplace(clipboard, rReplaceRegex, "$1" )
- clipboard := ""
- Sleep, 200
- bLength := StrLen(clipboard)
- Send, +{Up}
- IfWinActive ahk_exe firefox.exe
- Loop
- {
- Send, ^c
- ClipWait, 2
- aLength := StrLen(clipboard)
- if ( RegExMatch( clipboard, lRegex ) or bLength == aLength )
- break ; Terminate the loop
- else {
- Send, +{Up}
- clipboard := ""
- bLength := aLength
- continue ; Skip the below and start a new iteration
- }
- }
- context := RegExReplace(clipboard, lReplaceRegex, "$1" ) rContext
- context := RegExReplace( RegExReplace(RegExReplace( context, "\r?\n"," "), "(^\s+|\s+$)"), ";", "," )
- clipboard := ""
- Sleep, 200
- IfWinActive ahk_exe firefox.exe
- Send, ^l
- Sleep, 100
- Send, ^c
- ClipWait, 2
- link := RegExReplace(RegExReplace(clipboard, "\r?\n"," "), "(^\s+|\s+$)")
- clipboard := tmp ; restores original clipboard
- Sleep, 100
- ClipWait
- Sleep, 100
- ClipWait
- FileAppend, %word%;%context%;%link%;`n, C:\Users\TODO\Documents\Anki.txt
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement