#FindTextJ.mscr ver.2008.1.15 ################ #Operaで閲覧した最後のページ(=最新のhtmlキャッシュ)を #テキスト検索し、マッチした文字列を強調して表示するスクリプト #W-ZERO3 WS003SH、Opera 8.65 で動作確認 #for MortScript 4.1 Release # #by モバイル板MortScriptスレの1 #ref. to http://pc11.2ch.net/test/read.cgi/mobile/1172140262/l50 # #・起動すると、検索キーワード入力ダイアログが現れます。 # 入力したキーワードでhtmlキャッシュファイルを検索し、 # 別ウィンドウで強調して表示します。 #・"\Application Data\Opera" ディレクトリ内に"Found" というディレクトリを作り、 # その中に "oprfound.htm" "oprsjis.htm" という2つのファイルを生成します。 # #<別途必要なファイル> #・"MatchRep41.mscr" ver.2008.1.11 → # MortScript.exeのあるフォルダ内に"lib"フォルダを作り、 # その中に入れて下さい。 #・"qkc.exe" → "\Program Files" に入れて下さい。 #以上、保存ディレクトリが異なる場合は、適宜書き換えて下さい。 ##################################### #require MatchRep = SystemPath( "ScriptExe" ) \ "lib\MatchRep41.mscr" Qkc = "\Program Files\qkc.exe" scrName = "FindTextJ" #Operaのキャッシュフォルダを指定 Cache_dir = "\Application Data\Opera\cache4\*.*htm*" #検索文字列強調済htmlファイルの保存ディレクトリパス Found_dir = "\Application Data\Opera\Found" Found_file = Found_dir & "\oprfound.htm" Sjis_file = Found_dir & "\oprsjis.htm" #強調の仕方を設定 EmphO = "" EmphC = "" #テキスト入力ダイアログ(大文字小文字区別無し仕様) sStr = Input( "Find text:^NL^(Case Insensitive)" , scrName ) If( sStr eq "" ) Exit EndIf #保存ディレクトリがなければ作る If( DirExists( Found_dir ) = 0 ) MkDir( Found_dir ) EndIf ShowWaitCursor #キャッシュ内の全ての.*htm*ファイルの作成日時を比較して #最新のものを抽出 #300バイト以下のファイルは無視 cTime = 0 ForEach Cache in files ( Cache_dir ) If( FileCreateTime( Cache ) > cTime && FileSize( Cache ) > 300 ) cTime = FileCreateTime( Cache ) FilePath = Cache EndIf EndForEach #ヘッダ読み込み x = ToLower( ReadFile( FilePath )) If( Find( x, "" )) header = Part( x , "", 1 ) Else Message( "Can't read this file!^NL^Maybe not HTML file.", scrName ) Exit EndIf Copy( FilePath, Sjis_file, 1) #HTMLかXMLかを判定 html = Find( header , " If( html && xml ) If( html < xml ) lang = "html" Else lang = "xml" EndIf ElseIf( html = 0 && xml ) lang = "xml" ElseIf( html && xml = 0 ) lang = "html" Else Message( "Can't read this file!^NL^Maybe not HTML file.", scrName ) Exit EndIf #文字エンコード変換 #HTMLの場合 If( lang eq "html" ) bool = Find( header , "charset=utf-8""" ) Else bool = Find( header, "encoding=""utf-8""" ) EndIf If ( bool ) x = ReadFile( FilePath, 0, "utf8-prefix" ) WriteFile( Sjis_file, x, 0, "jis" ) Else RunWait( Qkc, "-s """ & Sjis_file & """" ) EndIf #出力ファイル初期化上書き WriteFile( Found_file, "", 0) #ヘッダとボディに分割 x = ReadFile( Sjis_file ) header = SubStr( x, 1, Find( ToLower( x ), "" ) + Length( "" ) - 1) aStr = SubStr( x, Find( ToLower( x ), "" ) + Length( "" )) #ボディをキーワードで仮検索 Idx = Find( ToLower( aStr ), ToLower( sStr )) #ひとつも見つからなければ終了 If( Idx = 0 ) Message( "Not found!", scrName ) Exit EndIf #ヘッダの文字エンコードタグをs_jisに変更 If( lang eq "html" ) If (Find( ToLower( header ), "charset=")) mr_Pat = "s/charset=euc-jp|charset=jis|charset=utf-8/charset=shift_jis/i" Else mr_Pat = "s!
!!i" EndIf Else mr_Pat = "s/encoding=""euc-jp""?>|encoding=""jis""?>|encoding=""utf-8""?>/encoding=""shift_jis""?>/i" EndIf CallScriptFunction( MatchRep, x, header, mr_Pat ) #ヘッダのみ出力 WriteFile( Found_file, x, 1) #本検索 While ( Idx ) Call( "FindOnce") EndWhile #出力ファイルに追記 WriteFile( Found_file, aStr, 1) HideWaitCursor #htmファイルに関連づけされているブラウザで開く Run( Found_file ) ################# #頭からひとつ目のマッチストリングを探すサブルーチン Sub FindOnce #マッチストリングの前の文字列 preStr = SubStr( aStr, 1, Idx - 1) #マッチストリング自体 mStr = SubStr( aStr, Idx, Length( sStr )) #マッチストリングの後の文字列 postStr = SubStr( aStr, Idx + Length( sStr )) #htmlタグの中の文字列かどうか #前回Callされたとき、検索文字列がタグの内側だった場合 If( tag ) #preStrの中の、"<"より後に">"があったら、タグの外側 If( ReverseFind( preStr, "<") < ReverseFind( preStr, ">")) tag = 0 EndIf #前回Callされたとき、検索文字列がタグの外側だった場合 Else #preStrの中の、">"より後に"<"があったら、タグの内側 If( ReverseFind( preStr, "<") > ReverseFind( preStr, ">") ) tag = 1 EndIf EndIf #もし検索文字列がタグの内側で見つかったなら、何もしないでそのまま追記出力 If( tag ) WriteFile( Found_file, preStr & mStr, 1) #そうでなければ、マッチストリングを強調して追記出力 Else WriteFile( Found_file, preStr & EmphO & mStr & EmphC, 1) EndIf #残りの文字列を再度頭から検索 aStr = postStr Idx = Find( ToLower( aStr ), ToLower( sStr )) EndSub