Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" standalone="yes" encoding="UTF-8" ?>
- <package>
- <job id="genVwCache">
- <?job error="True" debug="True" ?>
- <!--
- /**********************************************************/
- /* genVwCache.wsf : ver.0.26 2017/11/10 */
- /**********************************************************/
- // このスクリプトは、JaneStyle用で、画像リンクからイメージキャッシュファイルを作成するものです
- // JaneStyleで取得できない https:// の画像を取得するために作成しました
- // なお全てのhttpsが取得できるわけではないようです
- // WinHttpではTLS1.0まで、またサイトによっては、サーバー処理ミスへの対処要(備考欄参照)
- //
- // ※★ トラブルを避けるため、JaneStyleで取得出来なかったhttpsの場合のみに使用を限定することを推奨します
- // ※ 本スクリプトの動作確認は、WindowsXPで行っています(ver 0.25以降はWindows7SP1)
- // Windows2000では動作しませんが、287-291行を削除してcURLを有効にすれば動作するかもしれません
- //
- //==============================================================
- // ■ DOWNLOAD
- // a) pastbinのサイトでメニューから download を選択してダウンロードし、
- // ファイル名を genVwCache.wsf.txt から genVwCache.wsf に変更する
- // 又は
- // b) 下の RAW Paste Data 又はRAW(http://pastebin.com/raw.php?i=eN1tQZmc)から全てを
- // コピーペースト(ctrl+A,ctrl+C)でテキストエディタに貼り付け(ctrl+V)、
- // genVwCache.wsf という名前で文字コード UTF-8 で保存する
- // ※ IE で RAW を表示するには、セキュリティの設定で
- // 「拡張子ではなく内容によってファイルを開く」を無効にする必要がある
- // (レジストリHKROOTの拡張子にContent Type設定(text/plain)も必要だったかも)
- // ※ BOM は付けても付けなくてもよい(メモ帳では BOM が付加される)
- // a)又はb)で生成したファイルは下のコマンド登録で指定する場所に格納してください
- //
- // ■ JaneStyleへのコマンド登録
- // メニュー - ツール - 設定 - 機能 - コマンド で
- // コマンド名 : /画像取得(genVwCache)
- // ※ここは任意の名称で構いません(先頭に"/"を付けるとスレ欄右クリック時のみ)
- // コマンド内容 : wscript "$BASEPATHgenVwCache.wsf" /link:$LINK /url:$URL
- // を入力して、追加、OKする
- //
- // ★【注意】wscriptでは/iを付けると、環境によってはIEを起動できず動作しないことがあるので
- // その場合は/iを付けないか、又はcscriptを使ってください
- //
- // ※ なお、Jane直下フォルダでは無い場合はパスをフルパスで指定する
- // jane styleの下のscriptフォルダに入れた場合は、
- // wscript "$BASEPATHscript\genVwCache.wsf" /link:$LINK /url:$URL /i "/log:c:\genVwCacheLog.txt"
- // ※ ローカルPROXYを使う例
- // wscript "$BASEPATHgenVwCache.wsf" /link:$LINK /url:$URL /i /proxy:localhost:8080
- // ※ cscriptを使う例 (IEウィンドウを起動しないため起動・終了・表示が速い)
- // cscript //nologo "$BASEPATHgenVwCache.wsf" /link:$LINK /url:$URL /i:1000
- //
- // 起動オプション:(指定順番、大文字小文字の区別なし)
- // /link:$LINK 必須
- // /url:$URL 必須
- // "/log[:path]" トレースログを指定のファイルに追加書き込む
- // ファイルパス名省略時は %temp%\スクリプト名.log
- // /i[:999] wscript起動時には、IEウィンドウを起動して処理状況等の情報を表示する
- // cscript起動時には、コンソールに処理状況等の情報を表示する(IEウィンドウより高速)
- // 数値を指定した場合は、処理終了後 指定時間(ms)待ってIEウィンドウを閉じる
- // ただしエラー時には閉じない
- // また、http download中にIEウィンドウを閉じると処理を中断終了する
- // /proxy:server:port PROXYサーバー経由でアクセスする場合に指定する
- // /imgonly ImageViewURLReplace.datにマッチした場合及びimg拡張子を含む場合のみ取得する
- // /skip vchファイルにヘッダ以外のデータが存在した場合、vchファイルを上書きしない
- // /cfg[:path] カスタマイズ用定義ファイル(UTF-8)を指定する
- // なお/cfgを指定しなくても、スクリプトと同じフォルダに
- // "スクリプト名.cfg"ファイルがあると読み込むので注意
- // 内容は、JScriptの文法で記述する
- // スクリプト自体を書き換えなくとも、設定値や一部関数の差し替えが可能
- //
- // ■ 使い方:
- // 画像URLで右クリックし、コンテキストメニューの中の上記登録したコマンド名を選択する
- //
- // ■ 備考:
- // ●ImageViewURLReplace.dat の指定によるURL変換は出来ない場合がある
- // ・jscriptの正規表現の範囲を超えるパターンは認識できない(エラー発生時はその表現はスキップする)
- // ・第3,5引数で使用できる特殊変数は、$&,$1,$2,...に限定 / 第2引数はさらに$EXTRACT[1,...]が使える
- // ・変換エラー時はvchファイルが既に存在している場合にのみ処理を継続する
- // ・うまく変換できない場合は、vchファイル名が異なって生成されるため、JaneStyleからvchファイルが
- // 認識されない
- // ●ファイルの書き込みに失敗した場合は作成途中のファイルを残さないようにvchファイルは削除する
- // ●ImageView.iniで参照しているもの
- // [Cache]
- // UseViewCache=1
- // CachePath=
- // [HTTP]
- // TimeOut=30000
- // ConnectTimeout=10000
- // FileSizeMaximum=4096
- // ●NGFiles.txt のハッシュのマッチング処理を行っており、ブラクラ判定時には画像は格納しない
- // ●HTTPアクセスには以下の2つのCOMのどちらを使うかの選択ができる
- // 選択は、本スクリプトの「ユーザー設定エリア」の USING_WINHTTP_5_1 の値を書き替えることで可能
- // どちらもHTTPクライアントスタックWinHTTPに依存し、IEの設定やCache/Cookie/履歴を共有しない
- // (なお、WinHTTPの設定はレジストリやnetコマンド等で設定できるようです)
- // COMインターフェースでは細かな制御が出来ないため、Automatic Cookie Handlingは常に有効
- // (そのため、html内でCookieが別値で設定されていた場合、同じCookie名を2つ返すことになる)
- // 1) WinHttp.WinHttpRequest.5.1 (Win2000Pro SP3/WinXP SP1以降)
- // ・Refererヘッダの送信が可能
- // ・COMインターフェースだとイベント処理ができないようなので、受信前のチェックはできない
- // のでFileSizeMaximumの上限チェックは無効
- // ・リダイレクト回数はデフォルトの10回
- // ・Secure ProtocolはTLS 1.0のみに設定
- // 2) Msxml2.ServerXMLHTTP.6.0 (WinHttp.WinHttpRequest.5.0相当)
- // ・Refererの送信はできない
- // ・データの受信前に、データサイズの上限がチェックされる
- // ・リダイレクト回数は無限回
- // ・Secure ProtocolはSSL2.0/SSL3.0かも???
- // ●サーバーによっては処理をミスっており、何らかの対処をしないと正常データを取得できないことがある
- // http://www.sponichi.co.jp/entertainment/news/2017/09/08/jpeg/20170907s00041000378000p_view.jpg
- // "Accept-Encoding: gzip"を指定すると、無圧縮でデータを返してくるが
- // 指定しないと、逆に、gzip圧縮データを返す
- // https://tokyolily.jp/upload/save_image/11071927_5a018aa30f4c5.jpg
- // "Accept-Encoding: gzip"を指定すると、無圧縮でデータを返してくるが
- // 指定しないと、同じURLにリダイレクト(302)が返ってくるので延々とループし制限回数エラーとなる
- // どっちも、"Accept-Encoding"の値の判定が逆になっているものと思われる
- // 1) 外部プログラム:cURLを使う
- // 自動的にリクエストヘッダに"Accept-Encoding: deflate, gzip"を追加し、レスポンスヘッダに
- // "ContentEncoding: gzip"があると自動的にuncompressしてくれる
- // 2) gzip圧縮可の指定を行い、外部プログラム:gzip.exeを使う
- // カスタマイズ用定義ファイルに、
- // HTTP_HEADERS["Accept-Encoding"] = "gzip";
- // USING_GZIP = true;
- // のように指定する
- //
- // ■ 外部プログラム
- // ユーザー定義エリアの変数又はカスタマイズ用定義ファイルで各々設定する
- // PATH指定はフルパスで指定する、環境変数も使える、またフォルダの区切りは'\\'か'/'で記述する
- // ● cURL.exe - HTTP通信ソフト
- // 入手先: https://curl.haxx.se/
- // Win32 - GenericにあるSSL, SSH対応版
- // https://bintray.com/artifact/download/vszakats/generic/curl-7.56.1-win32-mingw.7z
- // 格納先: 本スクリプトと同じフォルダ、又は CURL_PATH にフルパスで指定する
- // 設定: USING_CURL = true; で有効
- // 説明: 上記WSHのCOMの仕様が古くSSLの取得ができないものに対応するためのものである
- // リダイレクション回数制限は10回に設定、WinHTTPのCOMのような使用するにあたっての制限は無い
- // なお、%temp%フォルダに作業用ファイルを2~3個作成する(デフォルトでは終了時に削除される)
- // また、/iオプションを付ける場合は、cscriptの方がプログレス表示されるので安心感がある
- // ● gzip.exe - GZIP圧縮解凍ソフト
- // 入手先: http://www.gzip.org/
- // Gzip for Windows Binaries
- // http://gnuwin32.sourceforge.net/downlinks/gzip-bin-zip.php
- // 格納先: 本スクリプトと同じフォルダ、又は GZIP_PATH にフルパスで指定する
- // 設定: USING_GZIP = true; で有効
- // 説明: 受信データのcontent-typeに、(x-)gzip,(x-)tar-gzを含まない場合でデータがgzip圧縮されたまま
- // だったらdecompressする(%temp%フォルダに作業用ファイルを作成し不要となった時点で削除する)
- // こういう事態はほとんど無いが、サイト側の設定ミスや中継サーバー設定等で起こりえる
- // ● 7za.exe - GZIP圧縮解凍ソフト
- // 入手先: http://7-zip.org/
- // Download 7-Zip for Windows 7-Zip Extra: standalone console version
- // http://7-zip.org/a/7z1604-extra.7z
- // 格納先: 本スクリプトと同じフォルダ、又は GZIP_PATH にフルパスで指定する
- // 設定: USING_7Z = true; で有効 (USING_GZIPと両方有効にするとGZIPの方を優先する)
- // 説明: gzip,exeと同じなのでどっちか片方のみでよい
- //==============================================================
- -->
- <script language="VBScript">
- <![CDATA[
- Function b2h(b,t,n)
- Dim d,i,s
- s = ""
- If t+n <= LenB(b) Then
- For i=1 To n
- d = Ucase(Hex(AscB(MidB(b,t+i,1))))
- s = s & Right( "0" & d, 2 )
- Next
- End If
- b2h = s
- End Function
- ]]>
- </script>
- <script language="JScript">
- <![CDATA[
- //----------------------------------
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var shell = new ActiveXObject("WScript.Shell");
- var sha = new ActiveXObject("Shell.Application");
- var strm = new ActiveXObject("ADODB.Stream");
- var JANE2CH = "Jane2ch";
- var JANE2CH_EXE = JANE2CH + ".exe";
- var JANE2CH_INI = JANE2CH + ".ini";
- var MY_NAME = WScript.ScriptName.split(/\.(?=[^.]+$)/)[0];
- var SCRIPT_PATH = fso.GetParentFolderName( WScript.ScriptFullName ).replace(/[^\\\/]$/,"$&\\");
- var JANE_PATH = findExeDir(SCRIPT_PATH,JANE2CH_EXE) || shell.CurrentDirectory.replace(/[^\\\/]$/,"$&\\");
- var TRACE_LOG = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+".log";
- var CSCRIPT = /cscript\.exe$/i.test(WScript.FullName);
- //-------- ユーザー設定エリア : begin --------------
- // HTTP通信に使うCOM objectを指定する
- var USING_WINHTTP_5_1 = true; //=true:WinHttp.WinHttpRequest.5.1 =false:Msxml2.ServerXMLHTTP.6.0
- //HTTP通信の設定
- var HTTP_ENCODE_URI = true; // urlで使用不可文字をパーセントエンコードする
- var HTTP_CONVERT_AMP = true; // url中に "&" が存在するときは"&"に変換する
- // 送信ヘッダを指定する
- // ただし同じヘッダは複数指定できない
- // なお、HTTP_HEADERS2は内部で使用する(Referer、Cookieの2つは指定してもこれで変更されることがある)
- var HTTP_HEADERS = {
- "User-Agent" : "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2450.0 Safari/537.36"
- // ,"Accept-Encoding" : "gzip"
- };
- var HTTP_HEADERS2 = {}; // script
- var HTTP_HEADERS3 = {}; // readHTTP
- var HTTP_REDIRECTION_COUNT = 3;
- var HTTP_PROGRESS = true; // iオプション時の受信経過表示の有無(cURLの場合はこの設定は無効)
- // cURL (HTTP通信) の設定(別途通信アプリ cURL が必要)
- // CURL_PATH中のフォルダの区切り及び終端は、"\\" 又は "/" で記述する 環境変数も指定できる
- var USING_CURL = false;
- var CURL_EXE = "cURL.exe";
- var CURL_PATH = SCRIPT_PATH;
- var CURL_DATA = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+"_DATA.tmp";
- var CURL_HEADER = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+"_HEADER.tmp";
- var CURL_OUTPUT = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+"_MSG.tmp";
- var CURL_ARGS = '-fkL# --compressed --max-redirs 10';
- var CURL_DELTMP = true; //終了時に用済みの作業用ファイルを削除する
- // https受信データがgzip圧縮されてた場合、decompressする
- var USING_GZIP = false;
- var USING_7Z = false;
- var GZIP_EXE = "gzip.exe";
- var GZIP_ARGS = "-df";
- var GZIP_EXE_7Z = "7za.exe";
- var GZIP_ARGS_7Z = "x -aoa";
- var GZIP_PATH = SCRIPT_PATH;
- var GZIP_DATA = CURL_DATA;
- //ImageViewURLReplace.datの編集ボタンをクリックした時に起動されるエディタを指定する
- // パスの中のフォルダの区切りは、"\\" 又は "/" で記述する 環境変数も指定できる
- // PARMSはエディタに渡す引数を指定する "$F"はファイルパスに、"$N"は行番号に置換される
- var TEXT_EDITOR = "notepad.exe";
- var TEXT_EDITOR_PARMS = '"$F",$N';
- //カスタマイズ用定義ファイル指定(この指定より引数/cfg:での指定の方が優先される)
- var CFG_FILE = SCRIPT_PATH + MY_NAME + ".cfg";
- // /resの場合にNGxx.txtファイルによるあぼーん処理の無効化
- var NO_ABONE = false;
- //ImageViewURLReplace.datの最終防衛ラインの位置検出用
- var RE_SAFETY_GUARD_MSG = /^\/\/\** +最終防衛ライン /;
- var HTTPS_SAFETY_GUARD_OFF = true;
- //Perl/Ruby Scriptを使用する
- var USING_PERL = false;
- var USING_RUBY = false;
- //ラップ関数
- var Wrap = {
- initialize: NOP
- ,finalize: NOP
- ,main: main
- ,makeURLs: makeURLs
- ,parseParms: parseParms
- ,genVwCache: genVwCache
- ,putVchFile: putVchFile
- ,putImgFile: putImgFile
- ,deleteVchFile: deleteVchFile
- ,dispOldVchFile: dispOldVchFile
- ,setVch: setVch
- ,urlReplace: urlReplace
- ,invokeEditor: invokeEditor
- ,out2: _out2
- ,newfile: newfile_name // newfile_time, newfile_name
- ,genRetryNewName: genRetryNewName
- ,readHTTP: readHTTP
- ,gzipDecompress: gzipDecompress
- ,gzipChk: gzipChk
- ,match: JS_match // JS_match, PS_match, RS_match
- ,test: JS_test // JS_test, PS_test, RS_test
- ,replace: JS_replace // JS_replace, PS_replace, RS_replace
- };
- //ImageViewURLReplace.dat検索の文言
- var MSG_SEARCH_IMAGE_DAT1 = "ImageViewURLReplace.dat $1検索開始";
- var MSG_SEARCH_IMAGE_DAT1_B = '<input type=button id="btn$1" value="編集" onClick="clicked(\'btn$1\');"> ';
- var MSG_SEARCH_IMAGE_DAT2 = "ImageViewURLReplace.dat 検索終了\n";
- // outimgオプションで出力するファイル名のダメ文字変換用文字セット
- var TBL_CONV_CHARS = {'\\':'¥','/':'/',':':':','*':'*','?':'?','"':'”','<':'<','>':'>','|':'|','.':'_'};
- var TBL_CONV_RE = /[\\/:*?"<>|.]/g;
- //-------- ユーザー設定エリア : end --------------
- if (USING_WINHTTP_5_1) {
- var http = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
- } else {
- var http = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
- }
- //=============================================================
- function findExeDir(p,x) {
- for(p+"dummy"; (p=p.replace(/[^\\\/]*[\\\/]?$/, "")) && !fso.FileExists(p+x); );
- return p;
- }
- function JS_test(s, ptn, flg) { return (new RegExp(ptn,flg)).test(s); }
- function JS_match(s, ptn, flg) { return s.match(new RegExp(ptn,flg)); }
- function JS_replace(s, ptn, flg, txt) { return s.replace(new RegExp(ptn,flg),txt); }
- function PS_test(s, ptn, flg) { return perl.co.test(s,ptn,flg) ? true : false; }
- function PS_match(s, ptn, flg) { var r=perl.co.match(s,ptn,flg); return r ? r.split("\n") : null; }
- function PS_replace(s, ptn, flg, txt) { return perl.co.replace(s,ptn,flg,txt); }
- function RS_test(s, ptn, flg) { return ruby.co.test(s,ptn,flg); }
- function RS_match(s, ptn, flg) { var r=ruby.co.match(s,ptn,flg); return r ? r.split("\n") : null; }
- function RS_replace(s, ptn, flg, txt) { return ruby.co.replace(s,ptn,flg,txt); }
- function PERL() {
- this.sc = new ActiveXObject("ScriptControl");
- this.sc.Language = "PerlScript";
- var code = [
- '#use 5.020;'
- , 'use strict;'
- , 'use warnings;'
- , 'use UTF8;'
- , 'use Encode qw/encode decode/;'
- , 'binmode STDIN, ":encoding(CP932)";'
- , 'binmode STDOUT, ":encoding(CP932)";'
- , 'binmode STDERR, ":encoding(CP932)";'
- , 'sub test {'
- , 'my ($s,$p,$o) = @_;'
- , '$s = decode("CP932", $s);'
- , '$p = decode("CP932", $p);'
- , 'eval "return \\$s =~ /\\$p/$o ? 1 : q!!;";'
- , '}'
- , 'sub replace {'
- , 'my ($s,$p,$o,$t) = @_;'
- , '$s = decode("CP932", $s);'
- , '$p = decode("CP932", $p);'
- , '$t = decode("CP932", $t);'
- , 'eval "\\$s =~ s/\\$p/$t/$o;";'
- , '$s = encode("CP932", $s);'
- , 'return $s;'
- , '}'
- , 'sub match {'
- , 'my ($s,$p,$o) = @_;'
- , '$s = decode("CP932", $s);'
- , '$p = decode("CP932", $p);'
- , 'my @a;'
- , 'if ($o =~ /g/) {'
- , ' eval "while (\\$s =~ /(\\$p)/$o) {push(\\@a,\\$1);}";'
- , '} else {'
- , ' eval "\\@a = \\$s =~ /(\\$p)/$o;";'
- , '}'
- , 'return encode("CP932",join("\n",@a));'
- , '}'
- ,].join("\n");
- this.sc.AddCode(code);
- this.co = this.sc.CodeObject;
- }
- function RUBY() {
- this.sc = new ActiveXObject("ScriptControl");
- this.sc.Language = "RubyScript.1";
- var code = [
- 'RE_OPT = { "i"=>Regexp::IGNORECASE, "m"=>Regexp::MULTILINE, "x"=>Regexp::EXTENDED }'
- , 'def test(s,p,f)'
- , ' Regexp.new(p,setFlg(f)) === s'
- , 'end'
- , 'def replace(s,p,f,t)'
- , ' if /g/ === f'
- , ' s.gsub(Regexp.new(p,setFlg(f)),t)'
- , ' else'
- , ' s.sub(Regexp.new(p,setFlg(f)),t)'
- , ' end'
- , 'end'
- , 'def match(s,p,f)'
- , ' if /g/ === f'
- // , ' s.scan(Regexp.new("("+p+")",setFlg(f))).map{|x| x[0]}.join("\n")'
- , ' a=[]; s.scan(Regexp.new(p,setFlg(f))) {|x| a.push($&)}; a.join("\n")'
- , ' else'
- , ' s.match(Regexp.new(p,setFlg(f))).to_a.join("\n")'
- , ' end'
- , 'end'
- , 'def setFlg(f)'
- , ' o = 0; f.scan(/[imx]/) {|x| o|=RE_OPT[x]}; return o'
- , 'end'
- ,].join("\n");
- this.sc.AddCode(code);
- this.co = this.sc.CodeObject;
- }
- function NOP() {};
- function NOPPASS(p) {return p;}
- function o(s) {WScript.Echo(s);}
- function q() {WScript.Quit();}
- function out(s,t,c) { trace(s,2); out2(s,t,c); }
- function out2(s,t,c) { Wrap.out2(s,t,c); }
- function _out2(s,t,c) {
- var ss=s.replace(/\n/g,"<br>");
- if(t) ss = ['<', t, (c)?' class="'+c+'"':'', '>', ss, '</', t, '>'].join("");
- if(ie) ie.out(ss);
- }
- function _out2_console(s,t,c) { try{WScript.StdOut.Write(s);}catch(e){}; }
- function outln(s,t,c) { trace(s,2); outln2(s,t,c); }
- function outln2(s,t,c) { out2(s+"\n",t,c); }
- function expand(s,p) { return s.replace(/\$(\d|&)/g, function($0, $1) {return (""+p[$1=='&'?0:$1]);}); }
- function expand2(s,p) { return s.replace(/\$EXTRACT(\d?)/g, function($0, $1) {return (""+p[$1||1]);}); }
- //=============================================================
- function string2bytes(string) {
- var bytes = null;
- var encode = new ActiveXObject("System.Text.UTF8Encoding");
- bytes = encode.GetBytes_4(string);
- encode = null;
- return bytes;
- }
- function bytes2string(bytes) {
- var string = null;
- var encode = new ActiveXObject("System.Text.UTF8Encoding");
- string = encode.GetString(bytes);
- encode = null;
- return string;
- }
- function file2bytes(fileName) {
- var bytes = null;
- strm.Type = 1;
- strm.Open();
- strm.LoadFromFile(fileName);
- bytes = strm.Read();
- strm.Close();
- return bytes;
- }
- function bytes2hex(bytes) {
- var hex = null;
- var doc = new ActiveXObject("Msxml2.DOMDocument");
- var element = doc.createElement("hex");
- element.dataType = "bin.hex";
- element.nodeTypedValue = bytes;
- hex = element.text;
- element = null;
- doc = null;
- return hex;
- }
- function hex2bytes(hex) {
- var bytes = null;
- var doc = new ActiveXObject("Msxml2.DOMDocument");
- var element = doc.createElement("hex");
- element.dataType = "bin.hex";
- element.text = hex;
- bytes = element.nodeTypedValue;
- element = null;
- doc = null;
- return bytes;
- }
- function md5(bytes) {
- var md5 = new ActiveXObject("System.Security.Cryptography.MD5CryptoServiceProvider");
- //var sha1 = new ActiveXObject("System.Security.Cryptography.SHA1CryptoServiceProvider");
- md5.ComputeHash_2(bytes);
- var hash = md5.Hash;
- md5.Clear();
- md5=null;
- return bytes2hex(hash);
- }
- var HASH_CHR = "0123456789ABCDEFGHIJKLMNOPQRSTUV".split("");
- function encode(hash) {
- var i,newhash = "", m=[];
- for(m[16]=i=0;i<16; i++) { m[i]=parseInt(hash.substr(i+i,2),16); }
- for(var i=0,j=0; i<26; i++,j+=5) {
- newhash += HASH_CHR[m[j>>>3]+(m[(j>>>3)+1]<<8)>>>j%8 & 0x1f];
- }
- return newhash;
- }
- function loadTextFile(f, n, p, c) {
- var s,emsg="";
- strm.Type = 2;
- try { strm.Charset = c ? c : 'shift_jis'; } catch(e) { throw new Error("loadTextFile: "+e.message+" - "+f+" charset="+c); }
- strm.Open();
- try {
- strm.loadFromFile(f);
- strm.Position = p ? p : 0;
- s = strm.ReadText((n) ? n : -1);
- } catch(e) { emsg=e.message; } finally { strm.Close(); }
- if(emsg) throw new Error("loadTextFile: "+emsg+" - "+f);
- return s;
- }
- function loadBinaryFile(f, n, p) {
- var s, emsg="";
- strm.Type = 1;
- strm.Open();
- try {
- strm.loadFromFile(f);
- strm.Position = p ? p : 0;
- s = (n) ? strm.Read(n) : strm.Read();
- } catch(e) { emsg = e.message; } finally { strm.Close(); }
- if(emsg) throw new Error("loadBinaryFile: "+emsg+" - "+f);
- return s;
- }
- function saveBinaryFile(f,b,a,p) {
- var emsg="";
- strm.Type = 1;
- strm.Open();
- if (a) { try {strm.loadFromFile(f); strm.Position = strm.Size;} catch(e){} }
- else if (p) { strm.Position = p; }
- try {
- strm.Write(b);
- strm.SaveToFile(f, 2);
- } catch(e) { emsg=e.message; } finally { strm.Close(); }
- if(emsg) throw new Error("saveBinaryFile: "+emsg+" - "+f);
- }
- function saveTextFile(f,s,cs,a) {
- var emsg="";
- strm.Type = 2;
- strm.Charset = cs ? cs : 'shift_jis';
- strm.Open();
- if(a) { try {strm.loadFromFile(f); strm.Position = strm.Size;} catch(e){} }
- try {
- strm.WriteText(s);
- strm.SaveToFile(f, 2);
- } catch(e) { emsg=e.message; } finally { strm.Close(); }
- if(emsg) throw new Error("saveTextFile: "+emsg+" - "+f);
- }
- function readHTTP(u, withText, redir_cnt) {
- var s, t="", r="", type="", size, i, emsg, url;
- var maxSize = parseInt(ini.FileSizeMaximum||"0", 10) * 1024;
- var http_redirection_count = redir_cnt || HTTP_REDIRECTION_COUNT;
- http.setTimeouts( 5*1000 /*resolve*/, ini.ConnectTimeout /*connect*/, 5*1000 /*send*/, ini.TimeOut /*receive*/);
- //SetProxy HTTPREQUEST_PROXYSETTING_PROXY=2
- if(args.proxy) http.setProxy(2, args.proxy, "");
- if(!USING_WINHTTP_5_1) {
- http.onreadystatechange
- = function() {
- switch(http.readyState) {
- case 1 : /*LOADING*/ break;
- case 2 : /*LOADED*/
- try{size=parseInt(http.getResponseHeader("Content-Length"),10);} catch(e) {}
- try{type=http.getResponseHeader("Content-Type").replace(/^([^ ;]+).*$/,"$1");}catch(e) {}
- if(maxSize>0 && size>maxSize) { http.abort(); emsg="image size over : "+addNumComma(size); return; }
- if(HTTP_PROGRESS) {
- out(type + " " + addNumComma(size) + " bytes");
- out2(" : "); out2("receive start .","strong");
- } else {
- trace(type + " " + addNumComma(size) + " bytes", 2);
- }
- break;
- case 3 : /*INTERACTIVE*/ break
- case 4 : /*COMPLETED*/ if(HTTP_PROGRESS) { outln2(" done.","strong"); break; }
- }
- };
- } else {
- // 信頼されていない認証局(CA)/CN不一致/期限切れのSSLエラーを無視
- // SslErrorIgnoreFlags |= Unknown certification authority (CA) or untrusted root (0x0100)
- // |= Wrong usage (0x0200) 誤使用
- // |= Invalid common name (CN) (0x1000)
- // |= Invalid date or certificate expired (0x2000)
- http.Option(4) |= (0x0100 /* | 0x0200 */ | 0x1000 | 0x2000);
- //SecureProtocols |= SSL2.0 (0x08)
- // |= SSL3.0 (0x20)
- // |= TLS 1.0 (0x80)
- http.Option(9) = 0x80;
- }
- //URLフラグメントが付いている場合削除, &を&に変換
- url = u.replace(/#.*$/,"");
- if(HTTP_CONVERT_AMP) url = url.replace(/&/g,"&");
- if(HTTP_ENCODE_URI && /[^\-_.!~*'a-zA-Z0-9;/?:@&=+$,%\[\]()#]|%(?![0-9A-F]{2})/.test(url)) {url=encodeURI(url);}
- http.open("GET", url, true);
- for(i in HTTP_HEADERS) { http.setRequestHeader(i, HTTP_HEADERS[i]); }
- for(i in HTTP_HEADERS2) { http.setRequestHeader(i, HTTP_HEADERS2[i]); }
- for(i in HTTP_HEADERS3) { http.setRequestHeader(i, HTTP_HEADERS3[i]); }
- delete HTTP_HEADERS3.Referer;
- http.send();
- if(USING_WINHTTP_5_1) {
- if(HTTP_PROGRESS) { out2("receive start .","strong"); }
- while(!http.waitForResponse(1)) {
- if(event_IE_Quit) { http.abort(); throw new Error("stopped from IE_Quit event"); }
- waitEvent(0);
- if(HTTP_PROGRESS) { out2(" .","strong"); }
- }
- try{size=parseInt(http.getResponseHeader("Content-Length"),10);} catch(e) {}
- try{type=http.getResponseHeader("Content-Type").replace(/^([^ ;]+).*$/,"$1");}catch(e) {}
- if(HTTP_PROGRESS) {
- out2(" done.","strong");
- outln(type + " " + addNumComma(size) + " bytes","span","padding20");outln2("");
- } else {
- trace(type + " " + addNumComma(size) + " bytes", 2);
- }
- } else {
- while(http.readyState<4) {
- if(emsg) throw new Error(emsg);
- if(http.readyState==3 && HTTP_PROGRESS) { out2(" .","strong"); }
- if(event_IE_Quit) { http.abort(); throw new Error("stopped from IE_Quit event"); }
- waitEvent(0);
- http.waitForResponse(1);
- }
- }
- r = http.status;
- if (http_redirection_count>0 && (r==301||r==302||r==303||r==307||r==308)) {
- r = http.getResponseHeader("Location");
- if(r) {
- http.abort();
- HTTP_HEADERS3.Referer = url;
- return readHTTP(r, true, http_redirection_count--);
- }
- }
- if (http.status != 200) throw new Error("rcv status="+http.status+" "+http.statusText);
- r = http.getAllResponseHeaders();
- s = http.responseBody;
- if(USING_GZIP||USING_7Z) s = Wrap.gzipDecompress(null, s, r);
- if(withText) {
- if(/text/.test(type)) {
- try {t = http.responseText;} catch(e) {}
- if (!/charset=/img.test(r)) {
- if(http.responseBody !== void 0) {
- var cs = (t.match(/<meta[^>]*charset=([^>;"'\s]+)/i)||[])[1] || '_autodetect';
- strm.Type = 1;
- strm.Open();
- strm.Write(s);
- strm.Position = 0;
- strm.Type = 2;
- strm.Charset = cs;
- t = strm.ReadText(-1);
- strm.Close();
- }
- }
- }
- s = [s,r,t,http.status,url];
- } else {
- s = [s,r,"",http.status,url];
- }
- http.abort();
- return s;
- }
- function CURL() {
- var maxSize = parseInt(ini.FileSizeMaximum||"0", 10) * 1024;
- var P_File = '-o "'+CURL_DATA+'" -D "'+CURL_HEADER+'"';
- var P_Output = (CSCRIPT) ? "" : '--stderr "' + CURL_OUTPUT + '"';
- var P_ConnTimeout = "--connect-timeout " + ini.ConnectTimeout/1000;
- var P_Timeout = "--max-time " + ini.TimeOut/1000;
- var P_MaxSize = (maxSize>0) ? "--max-filesize " + maxSize : "";
- var P_Proxy = (args.proxy) ? "--proxy " + args.proxy : "";
- this.readHTTP = function(u, withText, redir_cnt) {
- var s="", t="", r="", type="", i, emsg, url;
- var oExec,rc;
- var P_Headers = "";
- for(i in HTTP_HEADERS) {P_Headers += ' -H "'+i+(HTTP_HEADERS[i] ?": "+HTTP_HEADERS[i] :";")+'"';}
- for(i in HTTP_HEADERS2) {P_Headers += ' -H "'+i+(HTTP_HEADERS2[i]?": "+HTTP_HEADERS2[i]:";")+'"';}
- //URLフラグメントが付いている場合削除, &を&に変換
- url = u.replace(/#.*$/,"");
- if(HTTP_CONVERT_AMP) url = url.replace(/&/g,"&");
- if(HTTP_ENCODE_URI && /[^\-_.!~*'a-zA-Z0-9;/?:@&=+$,%\[\]()#]|%(?![0-9A-F]{2})/.test(url)) {url=encodeURI(url);}
- var P_Args = [ CURL_ARGS
- ,P_File,P_Output,P_ConnTimeout,P_Timeout,P_MaxSize,P_Proxy
- ,P_Headers
- ,url
- ].join(" ");
- if(CSCRIPT) {
- oExec = shell.exec('"'+CURL_PATH+CURL_EXE+'" '+P_Args);
- t="";
- while(oExec.Status==0) {
- t += s = oExec.StdErr.Read(80);
- WScript.StdOut.Write(s);
- }
- WScript.StdOut.Write(s=oExec.StdErr.ReadAll());
- t+= s;
- rc = oExec.ExitCode;
- } else {
- rc = shell.Run('"'+CURL_PATH+CURL_EXE+'" '+P_Args, 0, true);
- t = loadTextFile(CURL_OUTPUT);
- }
- if(rc) {
- t = t.match(/^(curl:.*)/mg) ? RegExp.$1 : "curl unknown error";
- throw new Error(t);
- }
- r = loadTextFile(CURL_HEADER);
- if(USING_GZIP||USING_7Z) Wrap.gzipDecompress(CURL_DATA, null, r);
- s = loadBinaryFile(CURL_DATA);
- t = "";
- if(r.match(/^Content-Type: *(.*)/img)) type=RegExp.$1;
- if(withText) {
- if(/text/.test(type)) {
- var cs = (type.match(/charset= *([-_a-zA-Z0-9]+)/)||[])[1];
- try{t=loadTextFile(CURL_DATA, null, null, cs||'_autodetect');} catch(e) {err.out(e.message);}
- if(!cs) {
- cs = (t.match(/<meta[^>]*charset=([^>;"'\s]+)/i)||[])[1] || '_autodetect';
- strm.Type = 1;
- strm.Open();
- strm.Write(s);
- strm.Position = 0;
- strm.Type = 2;
- strm.Charset = cs;
- t = strm.ReadText(-1);
- strm.Close();
- }
- }
- s = [s,r,t,200,url];
- } else {
- s = [s,r,"",200,url];
- }
- return s;
- };
- }
- function gzipDecompress(file, bin, header) {
- var rc, id, src, curDir, s;
- id = bin;
- if(file) { id = loadBinaryFile(file, 4); }
- if (b2h(id,0,2)=="1F8B" && Wrap.gzipChk(header)) {
- src = file || GZIP_DATA;
- if(!file) { saveBinaryFile(src+".gz", bin); }
- else {
- if(fso.FileExists(src+".gz")) try{ fso.DeleteFile(src+".gz"); } catch(e){};
- fso.GetFile(file).Name = fso.GetFile(file).Name + ".gz";
- }
- curDir = shell.CurrentDirectory;
- shell.CurrentDirectory = fso.GetParentFolderName(src+".gz");
- rc = shell.Run('"'+GZIP_PATH+GZIP_EXE+'" '+GZIP_ARGS+' "'+src+".gz"+'"', 0, true);
- shell.CurrentDirectory = curDir;
- if(!rc) {
- if(!file) {
- try{ bin = loadBinaryFile(src); }catch(e){}
- try{ fso.DeleteFile(src); } catch(e) {}
- }
- if(fso.FileExists(src+".gz")) try{ fso.DeleteFile(src+".gz"); } catch(e){}
- }
- }
- return bin;
- }
- function gzipChk(header) {
- var type=(header.match(/^Content-Type:.*/mg)||[]).join("");
- return /gzip|tar-gz/.test(type) ? false : true;
- }
- //-----------------------------------------------------------------
- function urlReplace(url,detail,noHTTP) {
- var lines, line, i, re, s="", rc=0, url2, url3, r, r2, rcv;
- lines = ImageViewURLReplaceDat.list;
- url2 = url;
- for(i=0; i<lines.length; i++) {
- if(!lines[i]) continue;
- try {
- r = Wrap.match(url,lines[i][0],"i");
- } catch(e) {
- if(detail & 0x08) outln2("ImageViewURLReplace.dat:"+(i+1)+":"+lines[i][0]+" -- この正規表現は認識できません");
- r = null;
- }
- if(r) break;
- }
- if(r) {
- line = lines[i];
- button.pos[button.n] = i+1;
- if(detail & 0x08) outln2([' --- found it! ---\nline=', i+1, " : ", line[0], "\n ---"].join(""));
- url = url2 = line[1];
- if(line[2]) {
- try { url3 = expand(line[2],r); } catch(e) {}
- }
- if(!noHTTP && /\$COOKIE|\$EXTRACT/.test(line[3])) {
- var s = (line[3].match(/=(.+?)(?=\$COOKIE|#|$)/)||[])[1];
- if(s) {
- try{ s = expand(s,r); }catch(e){}
- HTTP_HEADERS2.Referer = s;
- }
- try {
- if(detail & 0x08) outln("[arg3 URL = "+url3+"]");
- rcv = Wrap.readHTTP(url3, true);
- if(detail & 0x08) outln("[text length = "+rcv[2].length+" 文字]");
- } catch(e) {
- if(detail & 0x08) outln("replace URL read error: "+e.message);
- rcv=[null,e.message,e.message,e.message];
- }
- if(s) delete HTTP_HEADERS2.Referer;
- }
- if(/\$COOKIE/.test(line[3]) && rcv) {
- var s=rcv[1].match(/^Set-Cookie: *(.*)\r?\n/img);
- if(s) for(var i=0; i<s.length; i++) { Cookies.parse(s[i],0,url3); }
- s=rcv[2].match(/<meta http-equiv=(["'])Set-Cookie\1.*?>(?=[\s\S]*(?:<\/head|<body))/ig);
- if(s) for(var i=0; i<s.length; i++) { Cookies.parse(s[i],1,url3); }
- }
- if(/\$EXTRACT/.test(line[3])) {
- rc=2;
- url2 = (url3 !== void 0) ? url3 : line[2];
- if(line[4]) {
- try { r2 = Wrap.match(rcv[2],expand(line[4], r),"i"); } catch(e) {r2=null;}
- if(!r2) { url = url2; rc=-2; }
- else { url = expand2(expand(url,r), r2); }
- }
- } else { // 引数4が存在しないか$EXTRACTが指定されていない($COOKIEのみ)場合
- rc=1;
- try { url = url2 = expand(url, r); } catch(e) { rc = -1; }
- }
- }
- //rc=(0:未検出 1:変換 -1:ERR 2:EXTRACT変換 -2:ERR) url=HTTPアクセス用 url2=ハッシュ用 url3=リファラ
- if(url3) url3 = url3.replace(/#.*$/,"");
- return [rc,url,url2,url3];
- }
- function addNumComma(s) {
- try{ return s.toString(10).split('').reverse().join('').replace(/(\d{3})(?=\d)/g,'$1,').split('').reverse().join(''); }
- catch(e) { return s; }
- }
- function getEnv(s) { var wse = shell.Environment("Process"); return wse(s); }
- function replaceEnv(s) { return s.replace(/\%([^%]+)\%/ig, function(p0,p1) {return getEnv(p1);}); }
- function formatDate(d,n) {
- return [d.getFullYear()
- , "/" , ("0"+(d.getMonth()+1)).slice(-2)
- , "/" , ("0"+d.getDate()).slice(-2)
- , "(" , "日月火水木金土".substr(d.getDay(),1)
- , ") " , ("0"+d.getHours()).slice(-2)
- , ":" , ("0"+d.getMinutes()).slice(-2)
- , ":" , ("0"+d.getSeconds()).slice(-2)
- , "." , ("00"+parseInt(d.getMilliseconds(),10)+" ").slice(-4,n-4)
- ].join("");
- }
- function formatNum(d,n) { return (" "+d).slice(-n); }
- function Trace(log) {
- var logfile = log ? replaceEnv(log) : TRACE_LOG;
- var flag = true;
- var first = true;
- var t = [];
- return function(s,n) {
- if(flag) try{
- if(!n) n=0;
- var f = fso.OpenTextFile(logfile,8,true,0);
- if(first) {first=false; f.WriteLine("");}
- var tt=new Date();
- if(!s) { t[n] = new Date();}
- else { f.WriteLine(formatDate(tt,3)+"\t"+((n in t)?formatNum(tt-t[n],7)+"ms":" ")+"\t"+s); }
- f.Close();
- } catch(e) {flag=false; if(f) f.Close();}
- }
- }
- var HTML_CONTENTS = [
- '<html><head><title>', WScript.ScriptName, '</title>'
- ,'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
- ,'<meta http-equiv="Content-Style-Type" content="text/css">'
- ,'<style type="text/css">'
- ,'<!--'
- ,'body{background-color:#ebebeb; color:black;'
- ,'font-family:"MS Pゴシック","MS ゴシック";}'
- ,'div{margin:0px 0px 10px 0px;}'
- ,'strong{color:yellow;background-color:blue;font-size:120%;}'
- ,'strong.2{color:blue;background-color:#ebebeb;}'
- ,'strong.3{color:blue;background-color:yellow;font-size:100%;}'
- ,'.col2{margin-left:40px;} .padding20{padding-left:20px;}'
- ,'--></style></head>'
- ,'<script type="text/javascript">this.evt=[];function setEvent(s) {this.evt.push(s);};'
- ,'function clicked(s) {setEvent(s);}</script>'
- ,'<body><div id="msg1"></div></body></html>'
- ].join("");
- function IE() {
- this.existsIE = false;
- var ie = WScript.CreateObject("InternetExplorer.Application","Event_IE_");
- var doc,msg1;
- ie.Width =800;
- ie.Height =600;
- ie.AddressBar = false;
- ie.MenuBar = false;
- ie.ToolBar = false;
- ie.Resizable = true;
- ie.Visible = false;
- ie.Navigate2("about:blank", 2);
- while(ie.Busy || ie.readyState != 4) WScript.Sleep(100);
- doc=ie.Document;
- doc.write(HTML_CONTENTS);
- ie.Visible = true;
- msg1 = doc.getElementById('msg1');
- this.existsIE = true;
- this.out = function(s) { msg1.innerHTML += s.replace(/&/g,"&"); }
- this.quit = function() { ie.Quit(); while(ie.Busy) WScript.Sleep(50); this.existsIE=false; }
- this.getElement = function(s) { return doc.getElementById(s); }
- this.evt = doc.parentWindow.evt;
- this.getEvent = function() {
- try{ return (this.evt.length) ? this.evt.shift() : null; }catch(e){};
- return null;
- }
- this.setElementByIdDisabled = function(s,t) { this.getElement(s).disabled = t; }
- };
- function Event_IE_OnQuit() { ie.existsIE = false; event_IE_Quit = true; ie=null;}
- function isExistsIE() { return ie ? ie.existsIE : false; }
- function waitEvent(t) {
- var rc = 0, ev, n;
- if(!isExistsIE) return -1;
- for( ;t>=0 && !rc; t-=100) {
- try{
- ev=ie.getEvent();
- if(ev) {
- n=(ev.match(/(\d+)$/)||[])[1];
- switch(ev.replace(/\d+$/,"")) {
- case "btn": Wrap.invokeEditor(n); break;
- default: break;
- }
- }
- } catch(e) { rc = -1; }
- if(t>0) WScript.Sleep(100);
- }
- return 0;
- }
- function invokeEditor(n) {
- var parms,fname="ImageViewURLReplace.dat";
- n = button.pos[n] + "";
- parms = TEXT_EDITOR_PARMS.replace(/\$F/g, JANE_PATH+fname).replace(/\$N/g, n);
- sha.ShellExecute(replaceEnv(TEXT_EDITOR), parms);
- }
- function path(p) {
- var d = p.match(/[^\\]+\\/g), e = "";
- for (var i = 0; d[i]; i++) fso.FolderExists(e += d[i]) || fso.CreateFolder(e);
- return p;
- }
- //-----------------------------------------------------------------
- var button = new function() {
- this.n = 0;
- this.pos = [];
- }
- var err = new function ERR() {
- this.isError = false;
- this.out = function(s) { this.isError=true; s="ERROR : "+s; outln(s); throw new Error(s); }
- this.popup = function(s) { this.isError=true; s="ERROR : "+s; shell.Popup(s); throw new Error(s); }
- }
- var ini = new function ImageViewIni() {
- var ini = "";
- var re = "^\\[$1\\]\\r\\n(?:.*\\r\\n)*?(?:$2=(.*)|\\[.*\\])\\r\\n";
- var search = function(f,s,p) { return f.match(new RegExp(expand(s,p),"im"))||[]; }
- var expand = function(s,p) { return s.replace(/\$(\d)/g, function(m, n) { return (""+p[n]).replace(/\./g,"\\."); }); }
- try { ini = loadTextFile("ImageView.ini"); } catch(e) {}
- this.UseViewCache = search(ini, re, [,"Cache","UseViewCache"])[1];
- if(this.UseViewCache=="1")
- this.VwCacheDir = search(ini, re, [,"Cache","CachePath"])[1] || "VwCache";
- this.FileSizeMaximum = search(ini, re, [,"HTTP","FileSizeMaximum"])[1];
- this.TimeOut = search(ini, re, [,"HTTP","TimeOut"])[1];
- this.ConnectTimeout = search(ini, re, [,"HTTP","ConnectTimeout"])[1];
- try { ini = loadTextFile(JANE2CH_INI); } catch(e) {}
- this.Exclude1FromNGProcessing = search(ini, re, [,"VIEW","Exclude1FromNGProcessing"])[1];
- ini = null;
- }
- var ImageViewURLReplaceDat = new function(){
- var i;
- this.list = "";
- this.safety_line_pos = Infinity;
- try { this.list = loadTextFile("ImageViewURLReplace.dat"); } catch(e) {}
- this.list = this.list.replace(/\r/g,"").split("\n");
- this.list.splice(this.list.length-1,1);
- for(i=0;i<this.list.length;i++) {
- if(RE_SAFETY_GUARD_MSG.test(this.list[i])) this.safety_line_pos = i;
- this.list[i] = this.list[i].replace(/^(?:\/\/|;|').*$/,"");
- if(this.list[i]) this.list[i]=this.list[i].split("\t");
- }
- };
- var SearchNGFile = (function() {
- var list="",hashlist={},i,hash;
- try { list = loadTextFile("NGFiles.txt"); } catch(e) {}
- list = list.split("\n");
- for(i=0;i<list.length;i++) {
- if(list[i].indexOf("=")==26) hashlist[list[i].substring(0,26)] = list[i];
- }
- list=null;
- return function(key) { return hashlist[key]; }
- })();
- function imageHashFile(d){
- var i,list="",hashlist={},hash,fname,dir=d;
- fname = dir+MY_NAME+".txt";
- try{ list=loadTextFile(fname); } catch(e){}
- list = list.replace(/^(?:\/\/|;|').*(?=\r?\n)/mg,"").split(/\r?\n/);
- list.splice(list.length-1,1);
- for(i=0;i<list.length;i++) {
- if(list[i]) {
- list[i]=list[i].split("\t");
- if(list[i][0]) hashlist[list[i][0]] = (list[i][1])?list[i][1]:"dummy";
- }
- }
- return {
- search : function(s) { return hashlist[s]; }
- ,append : function(s,f) {
- hashlist[s]=s;
- try{ saveTextFile(fname,s+"\t"+f+"\r\n",null,true); } catch(e){}
- }
- ,"delete" : function(s) { delete hashlist[s]; }
- ,rebuild : function() {
- var img, s="",f;
- var folder=fso.GetFolder(dir);
- hashlist = {};
- var em = new Enumerator( folder.Files );
- for( em.moveFirst(); !em.atEnd(); em.moveNext() ) {
- f = em.item().Name;
- if(/\.txt$/.test(f)) continue;
- try { img=loadBinaryFile(dir+f); } catch(e) { img=null; }
- if(img!=null) {
- hash=encode(md5(img));
- hashlist[hash] = em.item().Name;
- outln2(hash+" : "+hashlist[hash]);
- }
- }
- for(i in hashlist) s += i+"\t"+hashlist[i]+"\r\n";
- outln2("");
- try{ saveTextFile(fname, s); outln(fname+"ファイルを作成しました");}
- catch(e){ outln(fname+"が作成できませんでした");}
- }
- }
- };
- function NGExClass(s) {
- this._SectionName = s; //管理用
- this.AboneType = 0;
- this.Name = "";
- this.NameBody = "";
- this.Mail = "";
- this.MailBody = "";
- this.ID = "";
- this.IDBody = "";
- this.Msg = "";
- this.MsgBody = "";
- this.Be = "";
- this.BeBody = "";
- this.TargetURL = "";
- this.TargetURLBody = "";
- }
- function escapeMetaChar(s) {return s.replace(/([\/\[\]\(\)\{\}\.\+\*\?\^\$\|\\])/g,"\\$1");}
- function Abone(f) {
- var i,ret,n,s="";
- this.abn = [];
- this.NGs = [];
- this.NGEx = [];
- var NGs_txt=[ "NGnames2.txt", "NGaddrs2.txt", "NGid2.txt", "NGwords2.txt", "NGBE2.txt" ];
- try{ s=bytes2hex(loadBinaryFile(f)); } catch(e){}
- if(s) for(i=0;i<s.length/2; i++) this.abn[i] = parseInt(s.substr(i+i,2),16);
- if(ini.Exclude1FromNGProcessing=="1") this.abn[0] = 0x0C;
- for(i=0; i<NGs_txt.length; i++) {
- s="";
- try{ s=loadTextFile(NGs_txt[i]); } catch(e){}
- this.NGs[i] = s.split(/\r?\n/);
- for(j=0;j<this.NGs[i].length;j++) {
- this.NGs[i][j] = this.NGs[i][j].split("\t");
- n = parseInt(this.NGs[i][j][6],10);
- this.NGs[i][j][6] = isFinite(n) ? n : 0;
- }
- }
- this.isAbn = function(n) {return (this.abn[n] & 0x03) ? true : false;};
- this.isNoNG = function(n) {return (this.abn[n] & 0x0C) ? true : false;};
- this.isNGNames = function(s) {return isNGs(this,s,0,true);};
- this.isNGAddrs = function(s) {return isNGs(this,s,1,true);};
- this.isNGID = function(s) {return isNGs(this,s,2,false);};
- this.isNGWords = function(s) {return isNGs(this,s,3,true);};
- this.isNGBE = function(s) {
- ret=-1;
- for(i=0;i<this.NGs[4].length;i++) {
- if(s==this.NGs[4][i][0]) { ret=this.NGs[4][i][6]; break; }
- }
- return ret;
- };
- this.isNGEx = function(s, url, title) {
- var i,j,r;
- this.NGEx = makeNGExList();
- s = s.split("<>");
- r = -1;
- for(i=0;i<this.NGEx.length;i++) {
- for(j in this.NGEx[i]) {
- if(!this.NGEx[i][j]) continue;
- switch(j) {
- case "Name": r = NGEx_sub(s[0], this.NGEx[i], j, true); break;
- case "Mail": r = NGEx_sub(s[1], this.NGEx[i], j, true); break;
- case "ID": r = NGEx_sub(s[2], this.NGEx[i], j, false); break;
- case "Msg": r = NGEx_sub(s[3], this.NGEx[i], j, true); break;
- case "Be": r = NGEx_sub((s[2].match(/ BE:(\d+)/)||[])[1], this.NGEx[i], j, true); break;
- case "TergetURL":
- r = NGEx_sub(url, this.NGEx[i], j, false);
- if(!r) r = NGEx_sub(title, this.NGEx[i], j, false);
- break;
- default: r = true; break;
- }
- if(!r) break; //どれかがfalseだったら次の条件を判定せずに次の定義に移動する
- }
- if(r) {
- r = parseInt(this.NGEx[i].AboneType,10);
- if(!isFinite(r)) r = 0;
- break; //全部trueだったらこの定義のand条件をすべて満たしたので抜ける
- } else {
- r = -1;
- }
- }
- return r;
- };
- function isNGs(own,s,n,case_insensitive) {
- ret = -1;
- for(i=0;i<own.NGs[n].length;i++) {
- if(!own.NGs[n][i][0]) continue;
- if(case_insensitive) ret = s.toUpperCase().indexOf(own.NGs[n][i][0].toUpperCase());
- else ret = s.indexOf(own.NGs[n][i][0]);
- if(ret>=0) break;
- }
- return (ret>=0) ? own.NGs[n][i][6] : -1;
- }
- function makeNGExList() {
- var i,j,r,s="",ngex,NGEx=[],REs={};
- for(i in new NGExClass()) { REs[i] = new RegExp('^'+i+'="?(.*?)"?$'); }
- try{ s=loadTextFile("NGEx.txt"); } catch(e){}
- s = s.split(/\r?\n/);
- for(i=0;i<s.length;i++) {
- if(r = s[i].match(/^\[(.+?)\]/)) {
- if(ngex) NGEx.push(ngex);
- ngex = new NGExClass(r[1]);
- }
- for(j in new NGExClass()) {
- r = (s[i].match(REs[j])||[])[1];
- if(r) {
- if(!ngex) ngex = new NGExClass(); //イレギュラー対策
- ngex[j] = r;
- }
- }
- }
- if(ngex) NGEx.push(ngex);
- return NGEx;
- }
- function NGEx_sub(s, ngex, itemName, case_insensitive) {
- var r,str;
- str = ngex[itemName+"Body"];
- if(!str) return false;
- try {
- switch(ngex[itemName]) {
- case "0": r = Wrap.test(s, escapeMetaChar(str), (case_insensitive)?"i":""); break;
- case "1": r = !Wrap.test(s, escapeMetaChar(str), (case_insensitive)?"i":""); break;
- case "2": r = Wrap.test(s, "^"+escapeMetaChar(str)+"$", (case_insensitive)?"i":""); break;
- case "3": r = !Wrap.test(s, "^"+escapeMetaChar(str)+"$", (case_insensitive)?"i":""); break;
- case "4": r = Wrap.test(s, str, (case_insensitive)?"i":""); break;
- case "5": r = !Wrap.test(s, str, (case_insensitive)?"i":""); break;
- default: r = false; break;
- }
- } catch(e) { r = false; }
- return r;
- }
- }
- function ReplaceStrTxt() {
- var i,list="";
- try{ list=loadTextFile("ReplaceStr.txt"); } catch(e){}
- list = list.replace(/^(?:\/\/|;|').*(?=\r?\n)/mg,"").split(/\r?\n/);
- for(i=0;i<list.length;i++) {
- if(list[i]) {
- list[i]= list[i].replace(/^<>/,"<rx>")
- .replace(/^((?!<)\S)/,"<ex>$1")
- .replace(/^(.+?\t.*?\t.*?\t)<>/,"$1<0>")
- .replace(/^(.+?\t.*?\t.*?\t)((?!<[012345]>)\S)/,"$1<0>$2");
- list[i]=list[i].split("\t");
- }
- }
- s="";for(i=0;i<list.length;i++) {if(list[i]) s+=list[i].join("\t");s+="\n";}
- this.execute = function(s,url,title) {
- var i,r,s2,re;
- for(i=0;i<list.length;i++) {
- if(!list[i][0] || list[i][2] && !/^(?:msg|all|$)/i.test(list[i][2])) continue;
- if(list[i][3]) {
- r = list[i][3].match(/<(\d)>(.*)$/);
- try {
- switch(r[1]) {
- case "0": if((url+"\n"+title).indexOf(r[2])<0) continue; break;
- case "1": if((url+"\n"+title).indexOf(r[2])>=0) continue; break;
- case "2": if(url!=r[2] && title!=r[2]) continue; break;
- case "3": if(url==r[2] || title==r[2]) continue; break;
- case "4": if(!Wrap.test(url,r[2],"i")&&!Wrap.test(title,r[2],"i")) continue; break;
- case "5": if(Wrap.test(url,r[2],"i")||Wrap.test(title,r[2],"i")) continue; break;
- }
- } catch(e) { continue; }
- }
- r = list[i][0].match(/^<(ex2|ex|rx2|rx)>(.+)$/i);
- try {
- switch((r||[])[1]) {
- case "ex" : s=Wrap.replace(s,escapeMetaChar(r[2]),"ig",list[i][1]); break;
- case "ex2" : s=Wrap.replace(s,escapeMetaChar(r[2]),"g",list[i][1]); break;
- case "rx" : s=Wrap.replace(s,r[2],"ig",list[i][1]); break;
- case "rx2" : s=Wrap.replace(s,r[2],"g",list[i][1]); break;
- }
- } catch(e){}
- }
- return s;
- };
- };
- function Cookie() {
- this.key;
- this.data;
- this.domain;
- this.path;
- this.secure;
- this.lifetime;
- this.inHtml;
- }
- Cookie.prototype.set = function(key, data, domain, path, secure, lifetime, inHtml) {
- this.key = key;
- this.data = data;
- this.domain = domain;
- this.path = path;
- this.secure = secure;
- this.lifetime = lifetime;
- this.inHtml = inHtml;
- }
- var cookies = [];
- var Cookies = (function() {
- var words = [ "(path)=", "(domain)=", "(secure)", "(httponly)", "(max-age)=", "(expires)="
- , "(version)=", "(comment)=", "(.+)=", "(.)" ];
- return {
- parse : function(s,inHtml,url) {
- var key=[], data=[], path="", domain="", secure=false, lifetime, httponly=false;
- var i,re,r,sArray,chunk;
- var r = this.parseURL(url);
- domain = r[0];
- path = r[1];
- sArray = s.replace(/^Set-Cookie: *(.*)\s*$/i,"$1").replace(/^<meta.*content=(["'])(.+)\1.*\s*$/i,"$2").split(/; */);
- while(sArray.length) {
- chunk = sArray.shift();
- for(i=0; i<words.length; i++) {
- re=new RegExp("^"+words[i]+"(.*)$", "i");
- r = chunk.match(re);
- if(!r) continue;
- switch(i) {
- case 0: path = r[2]; break
- case 1: domain = r[2]; break;
- case 2: secure = true; break;
- case 3: break; //httponlyはスキップ
- case 4: lifetime = Number(r[2]); break;
- case 5:
- if(!isFinite(lifetime)) {
- lifetime = r[2].replace(/-/g," ").replace(/(\d+ \w+ )(\d\d)(?=[^\d])/,"$120$2");
- }
- break;
- case 6: break; //versionはスキップ
- case 7: break; //commentはスキップ
- case 8: key.push(r[1]); data.push(r[2]); break;
- default: break;
- }
- break;
- }
- }
- if(lifetime!==void 0) {
- try{
- if(!isFinite(lifetime)) lifetime = new Date(lifetime)-0;
- else lifetime = (new Date()-0) + Number(lifetime) * 1000;
- } catch(e) {}
- }
- for(i=0; i<key.length; i++) {
- var cookie=new Cookie();
- cookie.set(key[i], data[i], domain, path, secure, lifetime, inHtml);
- if(secure && /^http:/.test(url)) continue;
- if(lifetime!==void 0 && new Date()>=lifetime) this.del(cookie);
- else if(USING_CURL||inHtml) this.put(cookie); //ヘッダの場合auto-cookie handlingで処理されるのでスキップ
- }
- }
- , put : function(cookie) {
- var r = this.search(cookie);
- if(r>=0) cookies[i] = cookie;
- else cookies.push(cookie);
- }
- , del : function(cookie) {
- var r = this.search(cookie);
- if(r>=0) {cookies.splice(r,1);}
- }
- , search : function(cookie) {
- var i,r=-1;
- for(i=0; i<cookies.length; i++) {
- if(cookies[i].key==cookie.key && cookies[i].domain==cookie.domain && cookies[i].path==cookie.path)
- {r=i; break;}
- }
- return r;
- }
- , parseURL : function(url) {
- var i, r, domain, path;
- r = url.replace(/^https?:\/\//,"").split("/");
- domain = r.shift();
- if(r[r.length-1]!="") r.pop();
- for(i=0;i<r.length;i++) {
- if(r[i]==".") { r.splice(i,1); }
- if(r[i]=="..") { (i>0) ? r.splice(i-1,2) : r.splice(i,1); }
- }
- path = "/"+r.join("/");
- return [domain, path];
- }
- , setHttpHeaders : function(HeaderList, url) {
- var r, domain, path;
- r = this.parseURL(url);
- domain = r[0];
- path = r[1];
- for(var i=0; i<cookies.length; i++) {
- if(cookies[i].lifetime!==void 0 && new Date()>=cookies[i].lifetime) cookies.splice(i,1);
- }
- for(var i=0; i<cookies.length; i++) {
- if(cookies[i].domain == domain
- && (!cookies[i].secure || url.indexOf("https")<0)
- && path.indexOf(cookies[i].path)>=0) {
- if("Cookie" in HeaderList) HeaderList["Cookie"] += "; "+cookies[i].key+"="+cookies[i].data;
- else HeaderList["Cookie"] = cookies[i].key+"="+cookies[i].data;
- }
- }
- }
- , getAll : function() {
- var i,j,r=[],s;
- for (i=0;i<cookies.length;i++) {s="";for(j in cookies[i]) if(j!="set") s+=j+"="+cookies[i][j]+"; "; r.push(s);}
- return r.join("\n");
- }
- }
- })();
- //-----------------------------------------------------------------
- function getVchFileName(url,detail) {
- var rc, url_new, vwCacheDir, vchFile, hash;
- rc = Wrap.urlReplace(url, detail, true);
- if(detail & 0x01) {
- outln2("結果: \t"+rc[0]+"\t(0:未検出 1:変換 -1:ERR 2:EXTRACT変換 -2:ERR)");
- outln2("new : \t"+rc[2]);
- }
- url_new = rc[2];
- vwCacheDir = ini.VwCacheDir.replace(/[^\\\/]$/,"$&\\");
- hash = encode(md5(string2bytes(url_new)));
- vwCacheDir = ini.VwCacheDir.replace(/[^\\\/]$/,"$&\\");
- vchFile = hash.substr(0,22) + ".vch";
- if(detail & 0x02) outln2("【ファイル名】"+vchFile,"strong","2");
- return vwCacheDir + vchFile;
- }
- function genVwCache(url,detail) {
- var rc, url_new, url_access, url_referer, vwCacheDir, vchFile, hash, n;
- var isErr = false;
- cookies = [];
- delete HTTP_HEADERS2.Cookie;
- delete HTTP_HEADERS2.Referer;
- url_new = url;
- url_access = url;
- ++button.n;
- if(detail & 0x08) {
- var btnmsg = (CSCRIPT) ? "" : expand(MSG_SEARCH_IMAGE_DAT1_B, [,button.n]);
- outln2(expand(MSG_SEARCH_IMAGE_DAT1,[,btnmsg]));
- }
- rc = Wrap.urlReplace(url, detail);
- switch(rc[0]) {
- case 0: //no match
- if(args.imgonly && !/\.(?:jpe?g|png|gif|bmp)(?=$|&)/i.test(url)) {
- outln("URL="+url);
- outln("Skip: imgのURLではありません","strong","3");
- return;
- }
- outln2("未検出");
- break;
- case -1: //replaced //このケースは発生しない
- case -2: //$EXTRACT変換
- try{ err.out("URL変換失敗"+((rc[0]==-2)?"(第5引数)":"(第1引数)")); } catch(e) {};
- isErr = true;
- break;
- }
- if(HTTPS_SAFETY_GUARD_OFF
- && url.substr(0,5) == "https"
- && rc[1].substr(0,5) == "http:"
- && button.pos[button.n] > ImageViewURLReplaceDat.safety_line_pos) {
- rc[1]=rc[1].replace(/^http:/,"https:");
- if(rc[3]) rc[3]=rc[3].replace(/^http:/,"https:");
- if(detail & 0x08) outln2("*** 最終防衛ラインによる置換をhttpsに戻しました");
- }
- url_access = rc[1];
- url_new = rc[2];
- url_referer = rc[3];
- if(detail & 0x08) outln2(MSG_SEARCH_IMAGE_DAT2);
- if(detail & 0x01) {
- outln("Org URL: "+url);
- outln("New URL: "+url_new);
- outln("Access : "+url_access);
- } else {
- trace("Org URL: "+url, 2);
- trace("New URL: "+url_new, 2);
- trace("Access : "+url_access, 2);
- }
- vwCacheDir = ini.VwCacheDir.replace(/[^\\\/]$/,"$&\\");
- hash = encode(md5(string2bytes(url_new)));
- vchFile = hash.substr(0,22) + ".vch";
- if(url_referer) HTTP_HEADERS2.Referer = url_referer;
- Cookies.setHttpHeaders(HTTP_HEADERS2, url_access);
- if(args.outimg) {
- if(fso.FileExists(vwCacheDir+vchFile)) Wrap.putImgFile(vwCacheDir+vchFile, null);
- else Wrap.putImgFile(null, url_access);
- } else if(args.deleteVch) {
- Wrap.deleteVchFile(vwCacheDir, vchFile);
- } else {
- Wrap.putVchFile(url_new, url_access, vwCacheDir, vchFile, isErr, detail);
- }
- }
- function putVchFile(url_new, url_access, vwCacheDir, vchFile, isErr, detail) {
- var img, Vch, n;
- if(detail & 0x02) outln("【ファイル名】"+vchFile,"strong","2");
- else trace("【ファイル名】"+vchFile, 2);
- isErr = Wrap.dispOldVchFile(vwCacheDir, vchFile, isErr, detail);
- if(isErr) return;
- try { img=Wrap.readHTTP(url_access); }
- catch(e) { img=e.message; try{err.out("http: "+e.message);}catch(e){} }
- outln2("");
- if(event_IE_Quit) return;
- Vch = new VCH();
- img = Wrap.setVch(img, url_new, Vch, detail);
- n = ("0000000"+Vch.getAll().length.toString(16)).slice(-8);
- vchFile = path(vwCacheDir+vchFile);
- try {
- saveBinaryFile(vchFile, hex2bytes(hexReverseByteOrder(n)));
- saveTextFile(vchFile, Vch.getAll(), "", true);
- if(img!=null) saveBinaryFile(vchFile, img, true);
- } catch(e) {
- try{ fso.DeleteFile(vchFile); } catch(e2) {}
- try{ err.out("save: "+e.message); } catch(e) {if(!ie) throw new Error(e.message); }
- return;
- }
- Vch = null;
- }
- function putImgFile(vchfile, url_access) {
- var s, img, n, fname, fext="", fsize, top2, hash, f;
- if(vchfile) {
- n = chkOldVchExists(vchfile);
- if(n) {
- try{ img = loadBinaryFile(vchfile, fsize-4-n, 4+n); }
- catch(e){ outln("Skip: ファイル読込みエラー"+e.message,"Strong","3"); return; }
- } else { outln("Skip: vchファイルにimgデータ無し","strong","3"); return; }
- } else {
- try { img=Wrap.readHTTP(url_access); }
- catch(e) { try{err.out("http: "+e.message);}catch(e){return;} }
- if(event_IE_Quit) return;
- img = img[0];
- }
- switch( b2h(img,0,2) ) {
- case "FFD8" : fext = ".jpg"; break;
- case "8950" : fext = ".png"; break;
- case "4749" : fext = ".gif"; break;
- case "424D" : fext = ".bmp"; break;
- default : fext = ".dat";
- }
- //if(args.imgonly && fext==".dat") {outln("Skip: imgではありません","strong","3"); return;}
- hash = encode(md5(img));
- if(f=ImageHashFile.search(hash)) {outln("Skip: 同hash値のファイル("+f+")があります","strong","3");}
- else if (SearchNGFile(hash)) {outln("Skip: NGFiles.txtで検閲されました","strong","3");}
- else {
- fname=Wrap.newfile(args.outimg, vchfile, url_access, fext);
- try{
- saveBinaryFile(args.outimg+fname,img);
- outln(fname,"strong","3");
- } catch(e){ outln(fname+" --- 失敗"+e.message,"strong","3"); }
- ImageHashFile.append(hash,fname);
- }
- return;
- }
- function deleteVchFile(vwCacheDir, vchFile) {
- if(fso.FileExists(vwCacheDir+vchFile)) {
- try{
- fso.DeleteFile(vwCacheDir+vchFile);
- outln(vchFile+" --- 削除","strong","3");
- } catch(e) { outln(vchFile+" --- 削除できません","strong","3"); }
- } else {
- outln2("既存ファイルなし");
- }
- return;
- }
- function getVchInfo(f) {
- var s="", n, m;
- n = bytes2hex(loadBinaryFile(f, 4));
- m = parseInt(hexReverseByteOrder(n),16);
- if(!isNaN(m)) s = loadTextFile(f, m, 4);
- return s;
- }
- function VCH() {
- var data = [];
- this.putItem = function(s,d) { if(d) data.push(s+"="+d); }
- this.getAll = function() { var r=data.join("\r\n"); return r ? r+"\r\n" : ""; }
- }
- function hexReverseByteOrder(s) {
- var i,ss="";
- for(i=0; i<s.length; i+=2) { ss += s.substr(s.length-i-2,2); }
- return ss;
- }
- function dispOldVchFile(vwCacheDir, vchFile, isErr, detail) {
- if(fso.FileExists(vwCacheDir+vchFile)) {
- if(args.skip && chkOldVchExists(vwCacheDir+vchFile)) {
- outln("Skip: vchファイルが存在しています","strong","3");
- isErr=true;
- } else {
- if(detail & 0x20) {
- outln2("【既存ファイルの内容】");
- outln2(getVchInfo(vwCacheDir+vchFile),"div","col2");
- }
- }
- } else {
- if(isErr) outln("ファイルがありません");
- else if(detail & 0x20) outln2("既存ファイルなし");
- }
- return isErr;
- }
- function chkOldVchExists(vchfile) {
- var s, n=0;
- if(fso.FileExists(vchfile)) {
- try { s = loadBinaryFile(vchfile, 4) } catch(e) {}
- if(s !== void 0) {
- n = parseInt(hexReverseByteOrder(bytes2hex(s)),16);
- if(isNaN(n) || fso.GetFile(vchfile).Size<=4+n) { n = 0; }
- }
- }
- return n;
- }
- function setVch(img, url_new, Vch, detail) {
- var header, ngFile, hash;
- if(typeof img=='string') { //http error code set
- Vch.putItem("URL", url_new);
- Vch.putItem("Referer", args.link);
- Vch.putItem("STATUS", img);
- img = null;
- } else {
- header = img[1];
- try { hash=encode(md5(img[0])); } catch(e) { hash="作成できません"; }
- if(detail & 0x04) outln("【NGFile用ハッシュ】 "+hash,"strong","2");
- else trace("【NGFile用ハッシュ】 "+hash, 2);
- ngFile = SearchNGFile(hash);
- if(ngFile) outln("《ブラクラ危険》:"+ngFile+"\n","strong","3");
- if(!ngFile) {
- img = img[0];
- Vch.putItem("ContentType", (header.match(/^Content-Type:\s*([^\r]+)/im)||[])[1]);
- Vch.putItem("LastModified", (header.match(/^Last-Modified:\s*([^\r]+)/im)||[])[1]);
- Vch.putItem("URL", url_new);
- Vch.putItem("Referer", args.link);
- } else {
- img = null;
- Vch.putItem("URL", url_new);
- Vch.putItem("STATUS", "BROCRA");
- }
- }
- if(detail & 0x10) {
- outln2("【作成したヘッダ内容】");
- outln2(Vch.getAll(),"div","col2");
- }
- return img;
- }
- function newfile_time(d, vchfile, url, fext) { return (new Date()-0) + fext; }
- function newfile_name(d, vchfile, url, fext) {
- var s, fname, count = 0, a = [];
- s = vchfile ? ((getVchInfo(vchfile).match(/^URL=(.+?)\s*$/m)||[])[1]||"") : url;
- s = decodeURIComponent(s);
- s = s.replace(/\?.*$/,"");
- s = s.replace(/\/$/,"");
- s = s.replace(/\/#/,"#");
- s = s.replace(/^.+\//,"");
- s = s.replace(/\.(?:jpe?g|gif(?:v)?|png|bmp|html?|php|aspx?|cgi)$/i,"");
- s = s.replace(/^[ .]+/,"");
- s = s.replace(TBL_CONV_RE, function(w){return TBL_CONV_CHARS[w];});
- s = s.replace(/^(con|aux|nul|prn|com\d|lpt\d)(?:\.|$)/i, "$1$");
- s = (s || "(unknown)");
- a = ["", s, ""];
- while(fso.FileExists(d+a.join("")+fext)) {
- a = Wrap.genRetryNewName(a,++count);
- }
- return a.join("") + fext;
- }
- function genRetryNewName(a,c) {
- // a[0]:prefix, a[1]:filename, a[2]:postfix c:count
- a[2] = "_" + ((c<1000) ? ("00"+c).slice(-3) : c);
- return a;
- return
- }
- //-------------------
- function parseParms() {
- var i;
- args.ie = args0.Exists("i");
- if(!args0.Item("link") && !args0.Item("range") && !args0.Item("res") && !args0.Exists("rebuild"))
- { throw new Error("引数 /link /range /res /rebuild のいずれかを指定してください"); }
- args.url = args0.Item("link");
- args.link = args0.Item("url");
- args.range = args0.Item("range") && decodeURIComponent(args0.Item("range"));
- args.res = args0.Item("res");
- if(args.res) {
- args.res = args.res.split(",");
- for(i=1;i<args.res.length;i++) { args.res[i]=parseInt(args.res[i],10); }
- if(isNaN(args.res[2])) args.res[2] = 1;
- if(isNaN(args.res[1])) { args.res[1] = 1; args.res[2] = 0; }
- }
- args.proxy = args0.Item("proxy");
- args.httpsonly = args0.Exists("httpsonly");
- args.skip = args0.Exists("skip");
- args.imgonly = args0.Exists("imgonly");
- args.outimg = (args0.Item("outimg") && replaceEnv(args0.Item("outimg")).replace(/[^\\\/]$/,"$&\\"));
- args.deleteVch = args0.Exists("delete");
- args.rebuild = args0.Exists("rebuild");
- args.abn = (args0.Item("abn") != "no");
- if(args.rebuild && !args.outimg) throw new Error("/rebuildを実行するには/outimgを指定してください");
- }
- function makeURLs() {
- var urls,i,r,s,delNo,ln,title,abone,offset,replaceStrTxt;
- var isNGs = { isNGNames : /^(.*?)<>/, isNGAddrs : /^.*?<>(.*?)<>/
- , isNGID : /^.*?<>.*?<>(.*?)<>/, isNGWords : /^.*?<>.*?<>.*?<>(.+?)<>/
- , isNGBE : /^.*?<>.*?<>.*? BE:(\d+).*?<>/ };
- if(args.res) {
- try { urls = loadTextFile(args.res[0]) }
- catch(e) { throw new Error("datファイルが読み込めません: "+e.message); }
- // datにtitleが埋め込まれてない場合もある
- title = (urls.match(/^.*?<>.*?<>.*?<>.*?<>(.*)\r?$/m)||[])[1];
- offset=0;
- urls = urls.split(/\r?\n/);
- if(args.res[1]) {
- offset = args.res[1]-1;
- ln = 0;
- delNo = offset;
- if(args.res[2]) {
- delNo += args.res[2];
- ln = urls.length-delNo;
- }
- if(ln>0) urls.splice(delNo, ln);
- if(args.res[1]>1) urls.splice(0,args.res[1]-1);
- }
- if(!NO_ABONE) abone = new Abone(args.res[0].replace(/\.dat$/,".abn"));
- for(i=0;i<urls.length;i++) {
- if(!NO_ABONE) {
- if(abone.isAbn(i+offset)) {urls[i]=""; continue; } //あぼーん・透明あぼーん
- if(abone.isNoNG(i+offset)) continue; //自分・重要レス
- for(j in isNGs) {
- r = abone[j]( (urls[i].match(isNGs[j])||[])[1] );
- if(r>=0) {
- if(r<4) urls[i] = "";
- break;
- }
- }
- if(r<0) { //NGxxにマッチしなかった場合のみNGExを判定する
- r = abone.isNGEx(urls[i], args.link, title);
- if(r>=0 && r<4) urls[i] = "";
- }
- }
- replaceStrTxt = new ReplaceStrTxt();
- if(urls[i]) { //ReplaceStr.Txtによるテキスト変換
- urls[i] = urls[i].replace(/^.*?<>.*?<>.*?<>(.*?)<>.*$/,"$1");
- if(urls[i]) urls[i] = replaceStrTxt.execute(urls[i],args.link,title);
- }
- }
- urls = urls.join("\n").replace(/&/g,"&");
- abone = replaceStrTxt = null;
- } else {
- urls = args.range;
- }
- urls = urls.replace(/h?(ttps?:\/\/)/g,"h$1");
- var re = (args.httpsonly)
- ? /https:\/\/[-.a-zA-Z0-9]+(?::\d+)?\/[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#\[\]]+/g
- : /https?:\/\/[-.a-zA-Z0-9]+(?::\d+)?\/[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#\[\]]+/g;
- return urls.match(re);
- }
- function main() {
- var i, url;
- if(!args.abn) NO_ABONE = true;
- trace = args0.Exists("log") ? new Trace(args0.Item("log")) : function(){};
- if(args0.Exists("i")) { if(CSCRIPT) Wrap.out2 = _out2_console; else ie = new IE(); }
- if (USING_CURL) {
- CURL_PATH = replaceEnv(CURL_PATH).replace(/[^\\\/]$/,"$&\\");
- if(!fso.FileExists(CURL_PATH+CURL_EXE)) err.popup("File Not Found - "+CURL_PATH+CURL_EXE);
- cURL = new CURL();
- Wrap.readHTTP = cURL.readHTTP;
- }
- if(USING_GZIP||USING_7Z) {
- if(!USING_GZIP) {
- GZIP_EXE = GZIP_EXE_7Z;
- GZIP_ARGS = GZIP_ARGS_7Z;
- }
- GZIP_PATH = replaceEnv(GZIP_PATH).replace(/[^\\\/]$/,"$&\\");
- if(!fso.FileExists(GZIP_PATH+GZIP_EXE)) err.popup("File Not Found - "+GZIP_PATH+GZIP_EXE);
- }
- Wrap.initialize();
- trace("--- start ---",1);trace("",1);
- if(args.outimg) {
- path(args.outimg);
- ImageHashFile = new imageHashFile(args.outimg);
- }
- if(args.rebuild) {
- ImageHashFile.rebuild();
- } else {
- if(ini.UseViewCache=="1") {
- if(!args.range && !args.res) { Wrap.genVwCache(args.url, 0x3f); }
- else {
- url = Wrap.makeURLs();
- if(url) {
- for(i=0; i<url.length; i++) {
- Wrap.genVwCache(url[i], 0x07);
- outln2("");
- if(event_IE_Quit) break;
- }
- } else outln2("URL抽出 0件");
- }
- } else {
- outln("ビューア設定で「キャッシュを使用する」がチェックされていません");
- }
- }
- Wrap.finalize();
- outln2("--- finished. ---");
- trace("--- end ---",1);
- if(USING_CURL && CURL_DELTMP) {
- try{ fso.DeleteFile(CURL_DATA); } catch(e) {}
- try{ fso.DeleteFile(CURL_HEADER); } catch(e) {}
- try{ fso.DeleteFile(CURL_OUTPUT); } catch(e) {}
- }
- }
- //=================================================================
- var args0 = WScript.Arguments.Named, args = {};
- var trace, ie, ImageHashFile, cfg, cURL, event_IE_Quit = false;
- var ruby, perl;
- //----- オプションファイルの組み込み (genVwCache.cfg) -----
- cfg = args0.Item("cfg") || CFG_FILE;
- if(fso.FileExists(replaceEnv(cfg))) {
- // "_autodetect"が効かないorz
- var code = loadTextFile(cfg, null, null, "utf-8");
- try{ eval(code);} catch(e) { shell.Popup("文法エラー又は文字コードがUTF-8で無い: "+e.message); q(); }
- }
- //---------------------------------------------------------
- if (USING_PERL) { perl = new PERL(); }
- if (USING_RUBY) { ruby = new RUBY(); }
- try { Wrap.parseParms(); } catch(e) { err.popup(e.message); q(); }
- try { Wrap.main(); } catch(e){}
- if(!CSCRIPT) {
- while(isExistsIE()) {
- if(!err.isError && args0.Item("i")) {
- if(!waitEvent(parseInt(args0.Item("i"),10))) try{ie.quit();}catch(e){};
- } else { waitEvent(1000); }
- }
- }
- var isError = err.isError;
- cURL = trace = ie = ini = fso = shell = strm = http = cookies = Cookies = err = button = ImageHashFile = SearchNGFile = ImageViewURLReplaceDat = perl = ruby = null;
- if(CSCRIPT && args0.Exists("i")) {
- if(!isError && args0.Item("i")) WScript.Sleep(parseInt(args0.Item("i"),10));
- else while(true){ WScript.Sleep(50); };
- }
- ]]>
- </script>
- <!--
- //=========================================================
- //修正履歴:
- //2015.11.27: 新規作成
- //2015.12.05: ver 0.2
- // 抽出からのリンククリックでスレURLが無い場合でも取得作成可能とした
- // ImageViewURLReplace.datの第4,5引数有($EXTRACT)の変換を可能にした
- // /i:時、ImageViewURLReplace.datの検索結果を表示するようにした
- // http読み込み中にIEウィンドウを閉じると処理を中断するようにした
- //2015.12.10: ver 0.3
- // ImageViewURLReplace.datの変換処理を修正
- // ( url.replace(第1引数,第2引数)で処理していたところを、
- // url.$&(=第1引数にマッチした全体のこと).replace(第1引数,第2引数)に変更した)
- //2016.01.08: ver 0.4
- // HTTPアクセスでアドレス末尾のURLフラグメント(#以降)を削除するようにした
- // ImageViewURLReplace.datの変換処理を修正
- // (第5引数の$nの部分を順次置換していくようにした、
- // またこのとき第3引数をURLとしてアクセスする、第3引数の特殊変数$&,$1,…を置換する)
- // 第2引数の$n,$EXTRACT[n]も同様に変更)
- //2016.01.09: ver 0.5
- // ImageViewURLReplace.datの変換処理を修正
- // (第1,5引数のマッチングで大文字小文字の区別をしないようにした)
- //2016.01.11: ver 0.6
- // ImageViewURLReplace.datの変換処理を修正
- // ($EXTRACTの場合、vchファイル名を第3引数から作成するようにした)
- // HTTPアクセスでアドレスに & が含まれている場合、& に変換する(独自仕様)
- // HTTPアクセスでUser-Agent指定を変更
- // (ver 0.4-0.5のUAだとo.8ch.netのブラックリストに載ってるようで弾かれる
- // なお、UA指定をコメントアウトした場合のUAは、
- // "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)" )
- //2016.01.16: ver 0.7
- // ImageViewURLReplace.datが存在してない場合、エラーになってたのを修正
- // ビューア設定で「キャッシュを使用する」未チェックの場合、エラーになってたのを修正
- // /i時、表示を少し修飾及びテキストエディタ起動ボタンを追加
- // (先頭にあるユーザー設定エリアにテキストエディタの設定をしてください)
- //2016.02.06: ver 0.8
- // PROXY経由でのアクセスを可能とした(引数に /PROXY:server:port 指定を追加)
- // ImageViewURLReplace.datの変換処理で、cookie処理及びreferer処理を追加
- // (なお、Jane StyleのCookie Handlingは受信したSet-Cookie値をそのまま
- // まるごと返すという荒っぽいものであることが判明した
- // また、Set-Cookie2とCookie2のハンドリングはIEやChromeもしてないようなので無視する)
- // HTTPアクセスにデフォルトで WinHttp.WinHttpRequest.5.1 を使うように変更
- // WinHttpの2つのCOMの違いは上記備考参照
- //2016.02.07: ver 0.9
- // HTTP受信時、レスポンスヘッダにContent-Lengthが無い場合エラーになってたのを修正
- //2016.02.08: ver 0.10
- // ImageViewURLReplace.datの変換処理を修正
- // (第4引数で、$EXTRACT={url}/$COOKIE={url}指定時、urlの$&,$n置換処理が抜けていた)
- //2016.05.04: ver 0.11
- // URIエンコードされたリンクで、正常に取得できないのを修正
- // (ver 0.6でのエンバグで、無条件にURIエンコードするため%がさらにエンコードされる)
- // 追加オプション /imgonly,/skip
- // 以下のオプションも追加 (使い方のわかる人だけ自己責任で使ってください)
- // (http://jane2ch.net/test/read.cgi/community/1432050479/938-939)
- // /delete, /outimg:"DirPath", /rebuild (/outimg必須 genVwCache.txt再作成のみ)
- // /range:$TEXTU, /res:"$LOCALDAT"[,ResNo.[,nums]], /httpsonly
- // (nums: =0:ResNo and later,default 1, /httpsonly: extract URLs with "https://")
- // 例: +cmd=wscript~ /res:"$LOCALDAT",$NUMBER /url:$URL /httpsonly /imgonly /skip /i
- //2016.05.05: ver 0.12
- // /imgonlyに大文字の拡張子(".JPG"など)も含まれるようにした
- // /res時"&"を"&"に変換する これ以外の文字参照が使われている場合は正常なURLにはならない
- //2016.05.07: ver 0.13
- // /outimgでNGFilesチェックが抜けてたのを修正
- //2016.06.27: ver 0.14
- // ImageViewURLReplace.datの最終防衛ラインでhttpsがhttpに置換されたものをhttpsに戻すようにした
- // /range、/resでの複数URL処理中でIEウィンドウを閉じると以降の処理を中止する
- // /resにAbone処理(.abn, NGxx.txt)とReplaceStr.txt処理を追加
- // (各種設定ファイルを基に処理しているのでJane起動中に設定したファイルに未反映のもの
- // は処理されない)
- // 追加オプション /abn:no (/res指定時にAbone処理を無効化する)
- // /outimgで出力imgファイル名を時刻からURLを基にした名前に変更した
- // cfgファイルの組み込みを追加
- // (バージョンアップの度に本スクリプトを書き換えなくても、一部の変数の値や関数の
- // 差し替えなど外部ファイルでカスタマイズできるようにした)
- // 【例】genVwCache.cfg
- // // これはgenVwCache.wsfの外部定義ファイルです
- //
- // TEXT_EDITOR = "%SystemDrive%/bin/editor/newqx/newqx.exe";
- //
- // // out,outln: ログ出力及びIE表示 out2,outln2: IE表示のみ o:Echo表示 q:終了
- // Wrap.initialize = function() {
- // outln2("*** CFGファイルが組み込まれました ***\n");
- // }
- //
- // //【WSHにPerlやRubyが組み込めるということでやってみた】
- // // (使うなら<script>タグで記述を分けた方が$WScript->Echoとかも使えてベター)
- // // Perlを使ってNGxx.txt,ReplaceStr.txt,ImageViewURLReplace.datの正規表現を処理する
- // // PerlはActivePerl 5.20.3.2003で確認(5.22.1は動かなかった)
- // // RubyはActiveScriptRuby1.8.3が必要
- // // (Ruby2.3.1等にはActiveScriptRubyが含まれているがこちらでは動かなかった
- // // 試したい人は、Language="RubyScript.2.3"又は"RubyScript"に変更)
- // // 両方をインストールする場合は、ActiveScriptRuby1.8.3(ActiveRuby.msi)を先に、
- // // Ruby2.3.1(Ruby-2.3.msi)を後にした方がトラブらないだろう
- // USING_PERL = true;
- // //USING_RUBY = true;
- // // JS_xxx: JScript, PS_xxx: PerlScript, RS_xxx: RubyScript
- // Wrap.match = PS_match;
- // Wrap.test = PS_test;
- // Wrap.replace = PS_replace;
- //
- // // range,res時もIE詳細情報表示を行う
- // //detail 01:url 02:vchfilename 04:nghash 08:urlreplace 10:new header 20:old header
- // Wrap.genVwCache = function(url,detail) { genVwCache(url,0x3f); }
- //
- // //----END-----
- //2016.09.02: ver 0.15
- // HTTP通信でstatus=30x(redirection)が返ってきた時は、レスポンスヘッダのLocationのURLで
- // 再度取得するようにした(amazon対応 但し、画像認証には非対応)
- //2016.09.15: ver 0.16
- // ReplaceStr.txtが無いときエラーになっていたのを修正(ver.0.14での変数の初期化設定抜け)
- // 30xリダイレクトでのWinhttpRequest5.1無限ループ回避処理を追加
- // HTTP_REDIRECTION_COUNT = 3(初期値) ※合計 (WinHTTP内部でのリダイレクト回数=10)×HTTP_REDIRECTION_COUNT
- // (残案件 相対アドレスのURL、metaタグでのリダイレクトへの対応)
- //2016.10.19: ver 0.17
- // /range,/res時、/iをつけていないと最初のURL1つしか処理されないのを修正
- //2016.12.08: ver 0.18
- // wscriptの代わりにcscriptで起動した場合には、/iオプションの情報表示をコンソールに出力するようにした
- // HTTPアクセス用に外部プログラム:cURLを選択できるようにした
- // (WSHのWinHttpのCOMではSSLの仕様が古くて取得できないものに対応するため)
- // (http://jane2ch.net/test/read.cgi/community/1475970286/188,283
- // https://img.barks.jp/image/review/1000078188/004.jpg
- // https://nijiero-ch.com/wp-content/uploads/2016/09/nijich14748505504341260.jpg)
- //2016.12.09: ver 0.19
- // cscriptで起動した場合、/range,/res時、最初のURL1つしか処理されないのを修正
- //2016.12.26: ver 0.20
- // 受信データが "content-type: application/gzip(x-gzip)" 以外でgzip圧縮されたままの場合、
- // 外部プログラム(7-Zip Extra: コマンドラインバージョン: 7za.exe)を使ってdecompressできるようにした
- // (おそらくはサイト設定ミスぐらいしか無いとは思うがchromeでは正常に表示するんで一応組み込んでみた)
- // ユーザ設定変数 USING_GZIPを true にすることで有効となる
- // 本スクリプトのフォルダ以外に7za.exeを格納する場合は、ユーザ設定変数 GZIP_PATH に設定すること
- // (7-Zip Extra: コマンドラインバージョンは、7z1604-extra.7z にて動作確認した)
- // (http://jane2ch.net/test/read.cgi/community/1462621843/720)
- //2016.12.27: ver 0.21
- // gzip decompressに外部プログラム: 7za.exeの代わりにgzip.exeも使えるようにした
- // (それにつれてver.0,20の定義変数を変更 USING_GZIP -> USING_7Z )
- // 説明を本スクリプトヘッダの外部プログラムの項目に記述した
- // 外部プログラム存在チェックを追加、gzip解凍に"application/x-tar-gz"も除外した
- //2017.01.05: ver 0.22
- // 外部定義ファイルでUSING_7Z=trueにした場合エラーになってたのを修正
- // 既存のvchファイルがヌルの場合ダンマリとなってたのを修正
- // /skipの条件を、vchファイルにヘッダ以外のデータがある場合に変更
- // /outimgの内部処理(ファイル名リネーム)を変更
- //2017.04.15: ver 0.23
- // 引数エラー時、メッセージが出ないで終了していたのを修正
- // CURL使用時、リクエストヘッダにReferer,Cookieが設定されないのを修正
- // /outimgの内部処理(ファイル名リネーム)のファイル名ダメ文字変換処理(異常系)を追加
- //
- // 例のgzip圧縮されたデータが返ってくるのは、リクエストヘッダに、Accept-Encoding: gzip を追加すると
- // ちゃんとデコードされてくれるんですが、今度は今まで正常だった所までもがgzip圧縮データを返してきて
- // それが何故かデコードされてないんで結局ダメ
- // この辺は不思議なんだが、自分に知識が無いせいで迷宮入りです
- //2017.04.15: ver 0.24
- // 最終防衛ラインによるhttpsをhttpに変換したものを、さらにhttpsに戻す場合
- // refererを削除していたのを、こっちも削除しないでhttpに変換するようにした
- //2017.10.20: ver 0.25
- // cURL使用時、htmlの読み込みデータがなしになって正規表現変換できない場合があった
- // (レスポンスヘッダの"Content-Type:"の抜き出しで大文字小文字の区別をしないようにした)
- //2017.11.10: ver 0.26
- // cfgファイルの文字コードを変更(SJIS→UTF-8)したので、全角を使ってる場合は修正して下さい
- // cURL使用時は、データ圧縮可(gzip,deflate)でアクセスするようにした
- // なお、WinHttpでは、自動的にgzip uncompressする機能が無いらしい
- // (ver 0.23ではデコードされると言ったが、圧縮されてないだけだった)
- // 以下のサイトはサーバー側の処理ミスだと思われる(備考欄に詳細を記載)
- // http://www.sponichi.co.jp/entertainment/news/2017/09/08/jpeg/20170907s00041000378000p_view.jpg
- // https://tokyolily.jp/upload/save_image/11071927_5a018aa30f4c5.jpg
- // 一連(http://egg.5ch.net/test/read.cgi/software/1506934532/668-694)のやりとりを見て、
- // キャッシュファイル名取得関数を追加(getVchFileName)
- // この関数はImageViewURLReplace.datで$EXTRACT指定の場合でもHTTPアクセスはしない
- // cfgファイル記述例
- // Wrap.genVwCache = function(url,detail) {
- // var vchFile = getVchFileName(url,detail);
- // if(!fso.FileExists(vchFile)) genVwCache(url,detail);
- // var exe = replaceEnv("%SystemDrive%/MassiGra/MassiGra.exe");
- // shell.Run('"'+exe+'" "'+vchFile+'"');
- // }
- /**********************************************************/
- -->
- </job>
- </package>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement