/* masspasteandgo.ahk クリップボード内の全てのURLを新しいタブで開く ;keyboard.ini [Application] v ctrl shift = Execute program, "C:\ahk\AutoHotkey.exe", "C:\ahk\masspasteandgo.ahk" ;menu.ini [Edit Go Widget Popup Menu] Item, "貼り付けて全て開く" = Execute program, "C:\ahk\AutoHotkey.exe", "C:\ahk\masspasteandgo.ahk" */ #NoTrayIcon IfWinNotActive, ahk_class OpWindow Exit WinGet, OperaPID, PID, ahk_class OpWindow OperaPath := getPEName( OperaPID ) position = 1 urls = ClipText = %Clipboard% Loop { url_match := RegExMatch( ClipText, "(h?t?t?p?s?:?//|www)((ja\.wikipedia\.org/wiki/[^\s]+)|([-_.!~*'()a-zA-Z0-9;/?:@&=+$,`%#]+))", $, position ) ;マッチしなかったらループを抜ける If url_match = 0 break ;次の検索開始位置を設定 StringLen, length, $ position += length If $1 = www $2 = %$1%%$2% IfInString, $2, ja.wikipedia.org/wiki/ { encode := RegExMatch( $2, "ja\.wikipedia\.org/wiki/(%[0-9a-fA-F][0-9a-fA-F])+" ) If encode = 0 { StringReplace, mbtext, $2, ja.wikipedia.org/wiki/, , All encodeurl := mbUrlEncode( mbtext ) $2 = ja.wikipedia.org/wiki/%encodeurl% } } ;重複防止 IfInString, urls, <%$2%> Continue Run, "%OperaPath%" "http://%$2%" urls = %urls%<%$2%> ;for SDI ;Clipboard = http://%$1% ;wait( 10 ) ;Send, {LCtrl Down}t{LCtrl Up} ;新しいタブ ;wait( 40 ) ;Send, {LCtrl Down}b{LCtrl Up} ;貼り付けて移動 ;wait( 40 ) } ;実行前のクリップボードに戻す Clipboard = %ClipText% mbUrlEncode( text ) { url = Clipboard = %text% ;Unicodeに変換して1バイトずつurlにしていく Transform, UniText, Unicode, Loop, Parse, UniText { ascii := Asc( A_LoopField ) SetFormat, integer, hex ascii += 0 SetFormat, integer, d url = %url%`%%ascii% } StringUpper, url, url StringReplace, url, url, 0X, , All return url } wait( time ) { begin := A_TickCount Loop { if A_TickCount - begin > time break } } ;http://lukewarm.s101.xrea.com/ getPEName(pid){ hModule=0 dwNeed=0 l=0 max:=VarSetCapacity(s,256,0) hProcess:=getProcessHandle(pid,0x410) ;ぬるいアクセス権でないと拒否られることがある if(DllCall("psapi\EnumProcessModules","Int",hProcess,"Int*",hModule,"Int",4,"UInt*",dwNeed,"Int")<>0){ l:=DllCall("psapi\GetModuleFileNameExA","Int",hProcess,"Int",hModule,"Str",s,"Int",max,"Int") } releaseProcessHandle(hProcess) return s } getProcessHandle(pid,mode=0x001F0FFF){ return DllCall("OpenProcess",UInt,mode,UInt,0,UInt,pid,UInt) } releaseProcessHandle(hProcess){ DllCall("psapi\CloseProcess","Int",hProcess) }