Advertisement
nanashi_kana

genVwCache.wsf

Nov 27th, 2015 (edited)
36,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.17 KB | None | 0 0
  1. <?xml version="1.0" standalone="yes" encoding="UTF-8" ?>
  2. <package>
  3. <job id="genVwCache">
  4. <?job error="True" debug="True" ?>
  5. <!--
  6. /**********************************************************/
  7. /* genVwCache.wsf : ver.0.26 2017/11/10 */
  8. /**********************************************************/
  9. // このスクリプトは、JaneStyle用で、画像リンクからイメージキャッシュファイルを作成するものです
  10. // JaneStyleで取得できない https:// の画像を取得するために作成しました
  11. // なお全てのhttpsが取得できるわけではないようです
  12. // WinHttpではTLS1.0まで、またサイトによっては、サーバー処理ミスへの対処要(備考欄参照)
  13. //
  14. // ※★ トラブルを避けるため、JaneStyleで取得出来なかったhttpsの場合のみに使用を限定することを推奨します
  15. // ※ 本スクリプトの動作確認は、WindowsXPで行っています(ver 0.25以降はWindows7SP1)
  16. // Windows2000では動作しませんが、287-291行を削除してcURLを有効にすれば動作するかもしれません
  17. //
  18. //==============================================================
  19. // ■ DOWNLOAD
  20. // a) pastbinのサイトでメニューから download を選択してダウンロードし、
  21. // ファイル名を genVwCache.wsf.txt から genVwCache.wsf に変更する
  22. // 又は
  23. // b) 下の RAW Paste Data 又はRAW(http://pastebin.com/raw.php?i=eN1tQZmc)から全てを
  24. // コピーペースト(ctrl+A,ctrl+C)でテキストエディタに貼り付け(ctrl+V)、
  25. // genVwCache.wsf という名前で文字コード UTF-8 で保存する
  26. // ※ IE で RAW を表示するには、セキュリティの設定で
  27. // 「拡張子ではなく内容によってファイルを開く」を無効にする必要がある
  28. // (レジストリHKROOTの拡張子にContent Type設定(text/plain)も必要だったかも)
  29. // ※ BOM は付けても付けなくてもよい(メモ帳では BOM が付加される)
  30. // a)又はb)で生成したファイルは下のコマンド登録で指定する場所に格納してください
  31. //
  32. // ■ JaneStyleへのコマンド登録
  33. // メニュー - ツール - 設定 - 機能 - コマンド で
  34. // コマンド名 : /画像取得(genVwCache)
  35. // ※ここは任意の名称で構いません(先頭に"/"を付けるとスレ欄右クリック時のみ)
  36. // コマンド内容 : wscript "$BASEPATHgenVwCache.wsf" /link:$LINK /url:$URL
  37. // を入力して、追加、OKする
  38. //
  39. // ★【注意】wscriptでは/iを付けると、環境によってはIEを起動できず動作しないことがあるので
  40. // その場合は/iを付けないか、又はcscriptを使ってください
  41. //
  42. // ※ なお、Jane直下フォルダでは無い場合はパスをフルパスで指定する
  43. // jane styleの下のscriptフォルダに入れた場合は、
  44. // wscript "$BASEPATHscript\genVwCache.wsf" /link:$LINK /url:$URL /i "/log:c:\genVwCacheLog.txt"
  45. // ※ ローカルPROXYを使う例
  46. // wscript "$BASEPATHgenVwCache.wsf" /link:$LINK /url:$URL /i /proxy:localhost:8080
  47. // ※ cscriptを使う例 (IEウィンドウを起動しないため起動・終了・表示が速い)
  48. // cscript //nologo "$BASEPATHgenVwCache.wsf" /link:$LINK /url:$URL /i:1000
  49. //
  50. // 起動オプション:(指定順番、大文字小文字の区別なし)
  51. // /link:$LINK 必須
  52. // /url:$URL 必須
  53. // "/log[:path]" トレースログを指定のファイルに追加書き込む
  54. // ファイルパス名省略時は %temp%\スクリプト名.log
  55. // /i[:999] wscript起動時には、IEウィンドウを起動して処理状況等の情報を表示する
  56. // cscript起動時には、コンソールに処理状況等の情報を表示する(IEウィンドウより高速)
  57. // 数値を指定した場合は、処理終了後 指定時間(ms)待ってIEウィンドウを閉じる
  58. // ただしエラー時には閉じない
  59. // また、http download中にIEウィンドウを閉じると処理を中断終了する
  60. // /proxy:server:port PROXYサーバー経由でアクセスする場合に指定する
  61. // /imgonly ImageViewURLReplace.datにマッチした場合及びimg拡張子を含む場合のみ取得する
  62. // /skip vchファイルにヘッダ以外のデータが存在した場合、vchファイルを上書きしない
  63. // /cfg[:path] カスタマイズ用定義ファイル(UTF-8)を指定する
  64. // なお/cfgを指定しなくても、スクリプトと同じフォルダに
  65. // "スクリプト名.cfg"ファイルがあると読み込むので注意
  66. // 内容は、JScriptの文法で記述する
  67. // スクリプト自体を書き換えなくとも、設定値や一部関数の差し替えが可能
  68. //
  69. // ■ 使い方:
  70. // 画像URLで右クリックし、コンテキストメニューの中の上記登録したコマンド名を選択する
  71. //
  72. // ■ 備考:
  73. // ●ImageViewURLReplace.dat の指定によるURL変換は出来ない場合がある
  74. // ・jscriptの正規表現の範囲を超えるパターンは認識できない(エラー発生時はその表現はスキップする)
  75. // ・第3,5引数で使用できる特殊変数は、$&,$1,$2,...に限定 / 第2引数はさらに$EXTRACT[1,...]が使える
  76. // ・変換エラー時はvchファイルが既に存在している場合にのみ処理を継続する
  77. // ・うまく変換できない場合は、vchファイル名が異なって生成されるため、JaneStyleからvchファイルが
  78. // 認識されない
  79. // ●ファイルの書き込みに失敗した場合は作成途中のファイルを残さないようにvchファイルは削除する
  80. // ●ImageView.iniで参照しているもの
  81. // [Cache]
  82. // UseViewCache=1
  83. // CachePath=
  84. // [HTTP]
  85. // TimeOut=30000
  86. // ConnectTimeout=10000
  87. // FileSizeMaximum=4096
  88. // ●NGFiles.txt のハッシュのマッチング処理を行っており、ブラクラ判定時には画像は格納しない
  89. // ●HTTPアクセスには以下の2つのCOMのどちらを使うかの選択ができる
  90. // 選択は、本スクリプトの「ユーザー設定エリア」の USING_WINHTTP_5_1 の値を書き替えることで可能
  91. // どちらもHTTPクライアントスタックWinHTTPに依存し、IEの設定やCache/Cookie/履歴を共有しない
  92. // (なお、WinHTTPの設定はレジストリやnetコマンド等で設定できるようです)
  93. // COMインターフェースでは細かな制御が出来ないため、Automatic Cookie Handlingは常に有効
  94. // (そのため、html内でCookieが別値で設定されていた場合、同じCookie名を2つ返すことになる)
  95. // 1) WinHttp.WinHttpRequest.5.1 (Win2000Pro SP3/WinXP SP1以降)
  96. // ・Refererヘッダの送信が可能
  97. // ・COMインターフェースだとイベント処理ができないようなので、受信前のチェックはできない
  98. // のでFileSizeMaximumの上限チェックは無効
  99. // ・リダイレクト回数はデフォルトの10回
  100. // ・Secure ProtocolはTLS 1.0のみに設定
  101. // 2) Msxml2.ServerXMLHTTP.6.0 (WinHttp.WinHttpRequest.5.0相当)
  102. // ・Refererの送信はできない
  103. // ・データの受信前に、データサイズの上限がチェックされる
  104. // ・リダイレクト回数は無限回
  105. // ・Secure ProtocolはSSL2.0/SSL3.0かも???
  106. // ●サーバーによっては処理をミスっており、何らかの対処をしないと正常データを取得できないことがある
  107. // http://www.sponichi.co.jp/entertainment/news/2017/09/08/jpeg/20170907s00041000378000p_view.jpg
  108. // "Accept-Encoding: gzip"を指定すると、無圧縮でデータを返してくるが
  109. // 指定しないと、逆に、gzip圧縮データを返す
  110. // https://tokyolily.jp/upload/save_image/11071927_5a018aa30f4c5.jpg
  111. // "Accept-Encoding: gzip"を指定すると、無圧縮でデータを返してくるが
  112. // 指定しないと、同じURLにリダイレクト(302)が返ってくるので延々とループし制限回数エラーとなる
  113. // どっちも、"Accept-Encoding"の値の判定が逆になっているものと思われる
  114. // 1) 外部プログラム:cURLを使う
  115. // 自動的にリクエストヘッダに"Accept-Encoding: deflate, gzip"を追加し、レスポンスヘッダに
  116. // "ContentEncoding: gzip"があると自動的にuncompressしてくれる
  117. // 2) gzip圧縮可の指定を行い、外部プログラム:gzip.exeを使う
  118. // カスタマイズ用定義ファイルに、
  119. // HTTP_HEADERS["Accept-Encoding"] = "gzip";
  120. // USING_GZIP = true;
  121. // のように指定する
  122. //
  123. // ■ 外部プログラム
  124. // ユーザー定義エリアの変数又はカスタマイズ用定義ファイルで各々設定する
  125. // PATH指定はフルパスで指定する、環境変数も使える、またフォルダの区切りは'\\'か'/'で記述する
  126. // ● cURL.exe - HTTP通信ソフト
  127. // 入手先: https://curl.haxx.se/
  128. // Win32 - GenericにあるSSL, SSH対応版
  129. // https://bintray.com/artifact/download/vszakats/generic/curl-7.56.1-win32-mingw.7z
  130. // 格納先: 本スクリプトと同じフォルダ、又は CURL_PATH にフルパスで指定する
  131. // 設定: USING_CURL = true; で有効
  132. // 説明: 上記WSHのCOMの仕様が古くSSLの取得ができないものに対応するためのものである
  133. // リダイレクション回数制限は10回に設定、WinHTTPのCOMのような使用するにあたっての制限は無い
  134. // なお、%temp%フォルダに作業用ファイルを2~3個作成する(デフォルトでは終了時に削除される)
  135. // また、/iオプションを付ける場合は、cscriptの方がプログレス表示されるので安心感がある
  136. // ● gzip.exe - GZIP圧縮解凍ソフト
  137. // 入手先: http://www.gzip.org/
  138. // Gzip for Windows Binaries
  139. // http://gnuwin32.sourceforge.net/downlinks/gzip-bin-zip.php
  140. // 格納先: 本スクリプトと同じフォルダ、又は GZIP_PATH にフルパスで指定する
  141. // 設定: USING_GZIP = true; で有効
  142. // 説明: 受信データのcontent-typeに、(x-)gzip,(x-)tar-gzを含まない場合でデータがgzip圧縮されたまま
  143. // だったらdecompressする(%temp%フォルダに作業用ファイルを作成し不要となった時点で削除する)
  144. // こういう事態はほとんど無いが、サイト側の設定ミスや中継サーバー設定等で起こりえる
  145. // ● 7za.exe - GZIP圧縮解凍ソフト
  146. // 入手先: http://7-zip.org/
  147. // Download 7-Zip for Windows 7-Zip Extra: standalone console version
  148. // http://7-zip.org/a/7z1604-extra.7z
  149. // 格納先: 本スクリプトと同じフォルダ、又は GZIP_PATH にフルパスで指定する
  150. // 設定: USING_7Z = true; で有効 (USING_GZIPと両方有効にするとGZIPの方を優先する)
  151. // 説明: gzip,exeと同じなのでどっちか片方のみでよい
  152. //==============================================================
  153. -->
  154. <script language="VBScript">
  155. <![CDATA[
  156. Function b2h(b,t,n)
  157. Dim d,i,s
  158. s = ""
  159. If t+n <= LenB(b) Then
  160. For i=1 To n
  161. d = Ucase(Hex(AscB(MidB(b,t+i,1))))
  162. s = s & Right( "0" & d, 2 )
  163. Next
  164. End If
  165. b2h = s
  166. End Function
  167. ]]>
  168. </script>
  169.  
  170. <script language="JScript">
  171. <![CDATA[
  172. //----------------------------------
  173. var fso = new ActiveXObject("Scripting.FileSystemObject");
  174. var shell = new ActiveXObject("WScript.Shell");
  175. var sha = new ActiveXObject("Shell.Application");
  176. var strm = new ActiveXObject("ADODB.Stream");
  177.  
  178. var JANE2CH = "Jane2ch";
  179. var JANE2CH_EXE = JANE2CH + ".exe";
  180. var JANE2CH_INI = JANE2CH + ".ini";
  181. var MY_NAME = WScript.ScriptName.split(/\.(?=[^.]+$)/)[0];
  182. var SCRIPT_PATH = fso.GetParentFolderName( WScript.ScriptFullName ).replace(/[^\\\/]$/,"$&\\");
  183. var JANE_PATH = findExeDir(SCRIPT_PATH,JANE2CH_EXE) || shell.CurrentDirectory.replace(/[^\\\/]$/,"$&\\");
  184. var TRACE_LOG = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+".log";
  185. var CSCRIPT = /cscript\.exe$/i.test(WScript.FullName);
  186.  
  187. //-------- ユーザー設定エリア : begin --------------
  188.  
  189. // HTTP通信に使うCOM objectを指定する
  190. var USING_WINHTTP_5_1 = true; //=true:WinHttp.WinHttpRequest.5.1 =false:Msxml2.ServerXMLHTTP.6.0
  191.  
  192. //HTTP通信の設定
  193. var HTTP_ENCODE_URI = true; // urlで使用不可文字をパーセントエンコードする
  194. var HTTP_CONVERT_AMP = true; // url中に "&amp;" が存在するときは"&"に変換する
  195.  
  196. // 送信ヘッダを指定する
  197. // ただし同じヘッダは複数指定できない
  198. // なお、HTTP_HEADERS2は内部で使用する(Referer、Cookieの2つは指定してもこれで変更されることがある)
  199. var HTTP_HEADERS = {
  200. "User-Agent" : "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2450.0 Safari/537.36"
  201. // ,"Accept-Encoding" : "gzip"
  202. };
  203. var HTTP_HEADERS2 = {}; // script
  204. var HTTP_HEADERS3 = {}; // readHTTP
  205.  
  206. var HTTP_REDIRECTION_COUNT = 3;
  207. var HTTP_PROGRESS = true; // iオプション時の受信経過表示の有無(cURLの場合はこの設定は無効)
  208.  
  209. // cURL (HTTP通信) の設定(別途通信アプリ cURL が必要)
  210. // CURL_PATH中のフォルダの区切り及び終端は、"\\" 又は "/" で記述する 環境変数も指定できる
  211. var USING_CURL = false;
  212. var CURL_EXE = "cURL.exe";
  213. var CURL_PATH = SCRIPT_PATH;
  214. var CURL_DATA = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+"_DATA.tmp";
  215. var CURL_HEADER = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+"_HEADER.tmp";
  216. var CURL_OUTPUT = replaceEnv("%temp%").replace(/[^\\\/]$/,"$&\\")+MY_NAME+"_MSG.tmp";
  217. var CURL_ARGS = '-fkL# --compressed --max-redirs 10';
  218. var CURL_DELTMP = true; //終了時に用済みの作業用ファイルを削除する
  219.  
  220. // https受信データがgzip圧縮されてた場合、decompressする
  221. var USING_GZIP = false;
  222. var USING_7Z = false;
  223. var GZIP_EXE = "gzip.exe";
  224. var GZIP_ARGS = "-df";
  225. var GZIP_EXE_7Z = "7za.exe";
  226. var GZIP_ARGS_7Z = "x -aoa";
  227. var GZIP_PATH = SCRIPT_PATH;
  228. var GZIP_DATA = CURL_DATA;
  229.  
  230. //ImageViewURLReplace.datの編集ボタンをクリックした時に起動されるエディタを指定する
  231. // パスの中のフォルダの区切りは、"\\" 又は "/" で記述する 環境変数も指定できる
  232. // PARMSはエディタに渡す引数を指定する "$F"はファイルパスに、"$N"は行番号に置換される
  233. var TEXT_EDITOR = "notepad.exe";
  234. var TEXT_EDITOR_PARMS = '"$F",$N';
  235.  
  236. //カスタマイズ用定義ファイル指定(この指定より引数/cfg:での指定の方が優先される)
  237. var CFG_FILE = SCRIPT_PATH + MY_NAME + ".cfg";
  238.  
  239. // /resの場合にNGxx.txtファイルによるあぼーん処理の無効化
  240. var NO_ABONE = false;
  241.  
  242. //ImageViewURLReplace.datの最終防衛ラインの位置検出用
  243. var RE_SAFETY_GUARD_MSG = /^\/\/\** +最終防衛ライン /;
  244. var HTTPS_SAFETY_GUARD_OFF = true;
  245.  
  246. //Perl/Ruby Scriptを使用する
  247. var USING_PERL = false;
  248. var USING_RUBY = false;
  249.  
  250. //ラップ関数
  251. var Wrap = {
  252. initialize: NOP
  253. ,finalize: NOP
  254. ,main: main
  255. ,makeURLs: makeURLs
  256. ,parseParms: parseParms
  257. ,genVwCache: genVwCache
  258. ,putVchFile: putVchFile
  259. ,putImgFile: putImgFile
  260. ,deleteVchFile: deleteVchFile
  261. ,dispOldVchFile: dispOldVchFile
  262. ,setVch: setVch
  263. ,urlReplace: urlReplace
  264. ,invokeEditor: invokeEditor
  265. ,out2: _out2
  266. ,newfile: newfile_name // newfile_time, newfile_name
  267. ,genRetryNewName: genRetryNewName
  268. ,readHTTP: readHTTP
  269. ,gzipDecompress: gzipDecompress
  270. ,gzipChk: gzipChk
  271. ,match: JS_match // JS_match, PS_match, RS_match
  272. ,test: JS_test // JS_test, PS_test, RS_test
  273. ,replace: JS_replace // JS_replace, PS_replace, RS_replace
  274. };
  275.  
  276. //ImageViewURLReplace.dat検索の文言
  277. var MSG_SEARCH_IMAGE_DAT1 = "ImageViewURLReplace.dat $1検索開始";
  278. var MSG_SEARCH_IMAGE_DAT1_B = '<input type=button id="btn$1" value="編集" onClick="clicked(\'btn$1\');"> ';
  279. var MSG_SEARCH_IMAGE_DAT2 = "ImageViewURLReplace.dat 検索終了\n";
  280.  
  281. // outimgオプションで出力するファイル名のダメ文字変換用文字セット
  282. var TBL_CONV_CHARS = {'\\':'¥','/':'/',':':':','*':'*','?':'?','"':'”','<':'<','>':'>','|':'|','.':'_'};
  283. var TBL_CONV_RE = /[\\/:*?"<>|.]/g;
  284.  
  285. //-------- ユーザー設定エリア : end --------------
  286.  
  287. if (USING_WINHTTP_5_1) {
  288. var http = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
  289. } else {
  290. var http = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
  291. }
  292.  
  293. //=============================================================
  294.  
  295. function findExeDir(p,x) {
  296. for(p+"dummy"; (p=p.replace(/[^\\\/]*[\\\/]?$/, "")) && !fso.FileExists(p+x); );
  297. return p;
  298. }
  299.  
  300. function JS_test(s, ptn, flg) { return (new RegExp(ptn,flg)).test(s); }
  301. function JS_match(s, ptn, flg) { return s.match(new RegExp(ptn,flg)); }
  302. function JS_replace(s, ptn, flg, txt) { return s.replace(new RegExp(ptn,flg),txt); }
  303. function PS_test(s, ptn, flg) { return perl.co.test(s,ptn,flg) ? true : false; }
  304. function PS_match(s, ptn, flg) { var r=perl.co.match(s,ptn,flg); return r ? r.split("\n") : null; }
  305. function PS_replace(s, ptn, flg, txt) { return perl.co.replace(s,ptn,flg,txt); }
  306. function RS_test(s, ptn, flg) { return ruby.co.test(s,ptn,flg); }
  307. function RS_match(s, ptn, flg) { var r=ruby.co.match(s,ptn,flg); return r ? r.split("\n") : null; }
  308. function RS_replace(s, ptn, flg, txt) { return ruby.co.replace(s,ptn,flg,txt); }
  309.  
  310. function PERL() {
  311. this.sc = new ActiveXObject("ScriptControl");
  312. this.sc.Language = "PerlScript";
  313. var code = [
  314. '#use 5.020;'
  315. , 'use strict;'
  316. , 'use warnings;'
  317. , 'use UTF8;'
  318. , 'use Encode qw/encode decode/;'
  319. , 'binmode STDIN, ":encoding(CP932)";'
  320. , 'binmode STDOUT, ":encoding(CP932)";'
  321. , 'binmode STDERR, ":encoding(CP932)";'
  322. , 'sub test {'
  323. , 'my ($s,$p,$o) = @_;'
  324. , '$s = decode("CP932", $s);'
  325. , '$p = decode("CP932", $p);'
  326. , 'eval "return \\$s =~ /\\$p/$o ? 1 : q!!;";'
  327. , '}'
  328. , 'sub replace {'
  329. , 'my ($s,$p,$o,$t) = @_;'
  330. , '$s = decode("CP932", $s);'
  331. , '$p = decode("CP932", $p);'
  332. , '$t = decode("CP932", $t);'
  333. , 'eval "\\$s =~ s/\\$p/$t/$o;";'
  334. , '$s = encode("CP932", $s);'
  335. , 'return $s;'
  336. , '}'
  337. , 'sub match {'
  338. , 'my ($s,$p,$o) = @_;'
  339. , '$s = decode("CP932", $s);'
  340. , '$p = decode("CP932", $p);'
  341. , 'my @a;'
  342. , 'if ($o =~ /g/) {'
  343. , ' eval "while (\\$s =~ /(\\$p)/$o) {push(\\@a,\\$1);}";'
  344. , '} else {'
  345. , ' eval "\\@a = \\$s =~ /(\\$p)/$o;";'
  346. , '}'
  347. , 'return encode("CP932",join("\n",@a));'
  348. , '}'
  349. ,].join("\n");
  350. this.sc.AddCode(code);
  351. this.co = this.sc.CodeObject;
  352. }
  353.  
  354. function RUBY() {
  355. this.sc = new ActiveXObject("ScriptControl");
  356. this.sc.Language = "RubyScript.1";
  357. var code = [
  358. 'RE_OPT = { "i"=>Regexp::IGNORECASE, "m"=>Regexp::MULTILINE, "x"=>Regexp::EXTENDED }'
  359. , 'def test(s,p,f)'
  360. , ' Regexp.new(p,setFlg(f)) === s'
  361. , 'end'
  362. , 'def replace(s,p,f,t)'
  363. , ' if /g/ === f'
  364. , ' s.gsub(Regexp.new(p,setFlg(f)),t)'
  365. , ' else'
  366. , ' s.sub(Regexp.new(p,setFlg(f)),t)'
  367. , ' end'
  368. , 'end'
  369. , 'def match(s,p,f)'
  370. , ' if /g/ === f'
  371. // , ' s.scan(Regexp.new("("+p+")",setFlg(f))).map{|x| x[0]}.join("\n")'
  372. , ' a=[]; s.scan(Regexp.new(p,setFlg(f))) {|x| a.push($&)}; a.join("\n")'
  373. , ' else'
  374. , ' s.match(Regexp.new(p,setFlg(f))).to_a.join("\n")'
  375. , ' end'
  376. , 'end'
  377. , 'def setFlg(f)'
  378. , ' o = 0; f.scan(/[imx]/) {|x| o|=RE_OPT[x]}; return o'
  379. , 'end'
  380. ,].join("\n");
  381. this.sc.AddCode(code);
  382. this.co = this.sc.CodeObject;
  383. }
  384.  
  385. function NOP() {};
  386. function NOPPASS(p) {return p;}
  387. function o(s) {WScript.Echo(s);}
  388. function q() {WScript.Quit();}
  389. function out(s,t,c) { trace(s,2); out2(s,t,c); }
  390. function out2(s,t,c) { Wrap.out2(s,t,c); }
  391. function _out2(s,t,c) {
  392. var ss=s.replace(/\n/g,"<br>");
  393. if(t) ss = ['<', t, (c)?' class="'+c+'"':'', '>', ss, '</', t, '>'].join("");
  394. if(ie) ie.out(ss);
  395. }
  396. function _out2_console(s,t,c) { try{WScript.StdOut.Write(s);}catch(e){}; }
  397. function outln(s,t,c) { trace(s,2); outln2(s,t,c); }
  398. function outln2(s,t,c) { out2(s+"\n",t,c); }
  399. function expand(s,p) { return s.replace(/\$(\d|&)/g, function($0, $1) {return (""+p[$1=='&'?0:$1]);}); }
  400. function expand2(s,p) { return s.replace(/\$EXTRACT(\d?)/g, function($0, $1) {return (""+p[$1||1]);}); }
  401.  
  402. //=============================================================
  403.  
  404. function string2bytes(string) {
  405. var bytes = null;
  406. var encode = new ActiveXObject("System.Text.UTF8Encoding");
  407. bytes = encode.GetBytes_4(string);
  408. encode = null;
  409. return bytes;
  410. }
  411.  
  412. function bytes2string(bytes) {
  413. var string = null;
  414. var encode = new ActiveXObject("System.Text.UTF8Encoding");
  415. string = encode.GetString(bytes);
  416. encode = null;
  417. return string;
  418. }
  419. function file2bytes(fileName) {
  420. var bytes = null;
  421. strm.Type = 1;
  422. strm.Open();
  423. strm.LoadFromFile(fileName);
  424. bytes = strm.Read();
  425. strm.Close();
  426. return bytes;
  427. }
  428. function bytes2hex(bytes) {
  429. var hex = null;
  430. var doc = new ActiveXObject("Msxml2.DOMDocument");
  431. var element = doc.createElement("hex");
  432. element.dataType = "bin.hex";
  433. element.nodeTypedValue = bytes;
  434. hex = element.text;
  435. element = null;
  436. doc = null;
  437. return hex;
  438. }
  439.  
  440. function hex2bytes(hex) {
  441. var bytes = null;
  442. var doc = new ActiveXObject("Msxml2.DOMDocument");
  443. var element = doc.createElement("hex");
  444. element.dataType = "bin.hex";
  445. element.text = hex;
  446. bytes = element.nodeTypedValue;
  447. element = null;
  448. doc = null;
  449. return bytes;
  450. }
  451.  
  452. function md5(bytes) {
  453. var md5 = new ActiveXObject("System.Security.Cryptography.MD5CryptoServiceProvider");
  454. //var sha1 = new ActiveXObject("System.Security.Cryptography.SHA1CryptoServiceProvider");
  455. md5.ComputeHash_2(bytes);
  456. var hash = md5.Hash;
  457. md5.Clear();
  458. md5=null;
  459. return bytes2hex(hash);
  460. }
  461.  
  462. var HASH_CHR = "0123456789ABCDEFGHIJKLMNOPQRSTUV".split("");
  463. function encode(hash) {
  464. var i,newhash = "", m=[];
  465. for(m[16]=i=0;i<16; i++) { m[i]=parseInt(hash.substr(i+i,2),16); }
  466.  
  467. for(var i=0,j=0; i<26; i++,j+=5) {
  468. newhash += HASH_CHR[m[j>>>3]+(m[(j>>>3)+1]<<8)>>>j%8 & 0x1f];
  469. }
  470. return newhash;
  471. }
  472.  
  473. function loadTextFile(f, n, p, c) {
  474. var s,emsg="";
  475. strm.Type = 2;
  476. try { strm.Charset = c ? c : 'shift_jis'; } catch(e) { throw new Error("loadTextFile: "+e.message+" - "+f+" charset="+c); }
  477. strm.Open();
  478. try {
  479. strm.loadFromFile(f);
  480. strm.Position = p ? p : 0;
  481. s = strm.ReadText((n) ? n : -1);
  482. } catch(e) { emsg=e.message; } finally { strm.Close(); }
  483. if(emsg) throw new Error("loadTextFile: "+emsg+" - "+f);
  484. return s;
  485. }
  486.  
  487. function loadBinaryFile(f, n, p) {
  488. var s, emsg="";
  489. strm.Type = 1;
  490. strm.Open();
  491. try {
  492. strm.loadFromFile(f);
  493. strm.Position = p ? p : 0;
  494. s = (n) ? strm.Read(n) : strm.Read();
  495. } catch(e) { emsg = e.message; } finally { strm.Close(); }
  496. if(emsg) throw new Error("loadBinaryFile: "+emsg+" - "+f);
  497. return s;
  498. }
  499.  
  500. function saveBinaryFile(f,b,a,p) {
  501. var emsg="";
  502. strm.Type = 1;
  503. strm.Open();
  504. if (a) { try {strm.loadFromFile(f); strm.Position = strm.Size;} catch(e){} }
  505. else if (p) { strm.Position = p; }
  506. try {
  507. strm.Write(b);
  508. strm.SaveToFile(f, 2);
  509. } catch(e) { emsg=e.message; } finally { strm.Close(); }
  510. if(emsg) throw new Error("saveBinaryFile: "+emsg+" - "+f);
  511. }
  512.  
  513. function saveTextFile(f,s,cs,a) {
  514. var emsg="";
  515. strm.Type = 2;
  516. strm.Charset = cs ? cs : 'shift_jis';
  517. strm.Open();
  518. if(a) { try {strm.loadFromFile(f); strm.Position = strm.Size;} catch(e){} }
  519. try {
  520. strm.WriteText(s);
  521. strm.SaveToFile(f, 2);
  522. } catch(e) { emsg=e.message; } finally { strm.Close(); }
  523. if(emsg) throw new Error("saveTextFile: "+emsg+" - "+f);
  524. }
  525.  
  526. function readHTTP(u, withText, redir_cnt) {
  527. var s, t="", r="", type="", size, i, emsg, url;
  528. var maxSize = parseInt(ini.FileSizeMaximum||"0", 10) * 1024;
  529. var http_redirection_count = redir_cnt || HTTP_REDIRECTION_COUNT;
  530.  
  531. http.setTimeouts( 5*1000 /*resolve*/, ini.ConnectTimeout /*connect*/, 5*1000 /*send*/, ini.TimeOut /*receive*/);
  532.  
  533. //SetProxy HTTPREQUEST_PROXYSETTING_PROXY=2
  534. if(args.proxy) http.setProxy(2, args.proxy, "");
  535.  
  536. if(!USING_WINHTTP_5_1) {
  537. http.onreadystatechange
  538. = function() {
  539. switch(http.readyState) {
  540. case 1 : /*LOADING*/ break;
  541. case 2 : /*LOADED*/
  542. try{size=parseInt(http.getResponseHeader("Content-Length"),10);} catch(e) {}
  543. try{type=http.getResponseHeader("Content-Type").replace(/^([^ ;]+).*$/,"$1");}catch(e) {}
  544. if(maxSize>0 && size>maxSize) { http.abort(); emsg="image size over : "+addNumComma(size); return; }
  545. if(HTTP_PROGRESS) {
  546. out(type + " " + addNumComma(size) + " bytes");
  547. out2(" : "); out2("receive start .","strong");
  548. } else {
  549. trace(type + " " + addNumComma(size) + " bytes", 2);
  550. }
  551. break;
  552. case 3 : /*INTERACTIVE*/ break
  553. case 4 : /*COMPLETED*/ if(HTTP_PROGRESS) { outln2(" done.","strong"); break; }
  554. }
  555. };
  556. } else {
  557. // 信頼されていない認証局(CA)/CN不一致/期限切れのSSLエラーを無視
  558. // SslErrorIgnoreFlags |= Unknown certification authority (CA) or untrusted root (0x0100)
  559. // |= Wrong usage (0x0200) 誤使用
  560. // |= Invalid common name (CN) (0x1000)
  561. // |= Invalid date or certificate expired (0x2000)
  562. http.Option(4) |= (0x0100 /* | 0x0200 */ | 0x1000 | 0x2000);
  563. //SecureProtocols |= SSL2.0 (0x08)
  564. // |= SSL3.0 (0x20)
  565. // |= TLS 1.0 (0x80)
  566. http.Option(9) = 0x80;
  567. }
  568. //URLフラグメントが付いている場合削除, &amp;を&に変換
  569. url = u.replace(/#.*$/,"");
  570. if(HTTP_CONVERT_AMP) url = url.replace(/&amp;/g,"&");
  571. if(HTTP_ENCODE_URI && /[^\-_.!~*'a-zA-Z0-9;/?:@&=+$,%\[\]()#]|%(?![0-9A-F]{2})/.test(url)) {url=encodeURI(url);}
  572.  
  573. http.open("GET", url, true);
  574. for(i in HTTP_HEADERS) { http.setRequestHeader(i, HTTP_HEADERS[i]); }
  575. for(i in HTTP_HEADERS2) { http.setRequestHeader(i, HTTP_HEADERS2[i]); }
  576. for(i in HTTP_HEADERS3) { http.setRequestHeader(i, HTTP_HEADERS3[i]); }
  577. delete HTTP_HEADERS3.Referer;
  578. http.send();
  579. if(USING_WINHTTP_5_1) {
  580. if(HTTP_PROGRESS) { out2("receive start .","strong"); }
  581. while(!http.waitForResponse(1)) {
  582. if(event_IE_Quit) { http.abort(); throw new Error("stopped from IE_Quit event"); }
  583. waitEvent(0);
  584. if(HTTP_PROGRESS) { out2(" .","strong"); }
  585. }
  586. try{size=parseInt(http.getResponseHeader("Content-Length"),10);} catch(e) {}
  587. try{type=http.getResponseHeader("Content-Type").replace(/^([^ ;]+).*$/,"$1");}catch(e) {}
  588. if(HTTP_PROGRESS) {
  589. out2(" done.","strong");
  590. outln(type + " " + addNumComma(size) + " bytes","span","padding20");outln2("");
  591. } else {
  592. trace(type + " " + addNumComma(size) + " bytes", 2);
  593. }
  594. } else {
  595. while(http.readyState<4) {
  596. if(emsg) throw new Error(emsg);
  597. if(http.readyState==3 && HTTP_PROGRESS) { out2(" .","strong"); }
  598. if(event_IE_Quit) { http.abort(); throw new Error("stopped from IE_Quit event"); }
  599. waitEvent(0);
  600. http.waitForResponse(1);
  601. }
  602. }
  603. r = http.status;
  604. if (http_redirection_count>0 && (r==301||r==302||r==303||r==307||r==308)) {
  605. r = http.getResponseHeader("Location");
  606. if(r) {
  607. http.abort();
  608. HTTP_HEADERS3.Referer = url;
  609. return readHTTP(r, true, http_redirection_count--);
  610. }
  611. }
  612. if (http.status != 200) throw new Error("rcv status="+http.status+" "+http.statusText);
  613. r = http.getAllResponseHeaders();
  614. s = http.responseBody;
  615.  
  616. if(USING_GZIP||USING_7Z) s = Wrap.gzipDecompress(null, s, r);
  617.  
  618. if(withText) {
  619. if(/text/.test(type)) {
  620. try {t = http.responseText;} catch(e) {}
  621. if (!/charset=/img.test(r)) {
  622. if(http.responseBody !== void 0) {
  623. var cs = (t.match(/<meta[^>]*charset=([^>;"'\s]+)/i)||[])[1] || '_autodetect';
  624. strm.Type = 1;
  625. strm.Open();
  626. strm.Write(s);
  627. strm.Position = 0;
  628. strm.Type = 2;
  629. strm.Charset = cs;
  630. t = strm.ReadText(-1);
  631. strm.Close();
  632. }
  633. }
  634. }
  635. s = [s,r,t,http.status,url];
  636. } else {
  637. s = [s,r,"",http.status,url];
  638. }
  639. http.abort();
  640. return s;
  641. }
  642.  
  643. function CURL() {
  644. var maxSize = parseInt(ini.FileSizeMaximum||"0", 10) * 1024;
  645. var P_File = '-o "'+CURL_DATA+'" -D "'+CURL_HEADER+'"';
  646. var P_Output = (CSCRIPT) ? "" : '--stderr "' + CURL_OUTPUT + '"';
  647. var P_ConnTimeout = "--connect-timeout " + ini.ConnectTimeout/1000;
  648. var P_Timeout = "--max-time " + ini.TimeOut/1000;
  649. var P_MaxSize = (maxSize>0) ? "--max-filesize " + maxSize : "";
  650. var P_Proxy = (args.proxy) ? "--proxy " + args.proxy : "";
  651.  
  652. this.readHTTP = function(u, withText, redir_cnt) {
  653. var s="", t="", r="", type="", i, emsg, url;
  654. var oExec,rc;
  655.  
  656. var P_Headers = "";
  657. for(i in HTTP_HEADERS) {P_Headers += ' -H "'+i+(HTTP_HEADERS[i] ?": "+HTTP_HEADERS[i] :";")+'"';}
  658. for(i in HTTP_HEADERS2) {P_Headers += ' -H "'+i+(HTTP_HEADERS2[i]?": "+HTTP_HEADERS2[i]:";")+'"';}
  659.  
  660. //URLフラグメントが付いている場合削除, &amp;を&に変換
  661. url = u.replace(/#.*$/,"");
  662. if(HTTP_CONVERT_AMP) url = url.replace(/&amp;/g,"&");
  663. if(HTTP_ENCODE_URI && /[^\-_.!~*'a-zA-Z0-9;/?:@&=+$,%\[\]()#]|%(?![0-9A-F]{2})/.test(url)) {url=encodeURI(url);}
  664.  
  665. var P_Args = [ CURL_ARGS
  666. ,P_File,P_Output,P_ConnTimeout,P_Timeout,P_MaxSize,P_Proxy
  667. ,P_Headers
  668. ,url
  669. ].join(" ");
  670. if(CSCRIPT) {
  671. oExec = shell.exec('"'+CURL_PATH+CURL_EXE+'" '+P_Args);
  672. t="";
  673. while(oExec.Status==0) {
  674. t += s = oExec.StdErr.Read(80);
  675. WScript.StdOut.Write(s);
  676. }
  677. WScript.StdOut.Write(s=oExec.StdErr.ReadAll());
  678. t+= s;
  679. rc = oExec.ExitCode;
  680. } else {
  681. rc = shell.Run('"'+CURL_PATH+CURL_EXE+'" '+P_Args, 0, true);
  682. t = loadTextFile(CURL_OUTPUT);
  683. }
  684. if(rc) {
  685. t = t.match(/^(curl:.*)/mg) ? RegExp.$1 : "curl unknown error";
  686. throw new Error(t);
  687. }
  688. r = loadTextFile(CURL_HEADER);
  689.  
  690. if(USING_GZIP||USING_7Z) Wrap.gzipDecompress(CURL_DATA, null, r);
  691.  
  692. s = loadBinaryFile(CURL_DATA);
  693.  
  694. t = "";
  695. if(r.match(/^Content-Type: *(.*)/img)) type=RegExp.$1;
  696. if(withText) {
  697. if(/text/.test(type)) {
  698. var cs = (type.match(/charset= *([-_a-zA-Z0-9]+)/)||[])[1];
  699. try{t=loadTextFile(CURL_DATA, null, null, cs||'_autodetect');} catch(e) {err.out(e.message);}
  700. if(!cs) {
  701. cs = (t.match(/<meta[^>]*charset=([^>;"'\s]+)/i)||[])[1] || '_autodetect';
  702. strm.Type = 1;
  703. strm.Open();
  704. strm.Write(s);
  705. strm.Position = 0;
  706. strm.Type = 2;
  707. strm.Charset = cs;
  708. t = strm.ReadText(-1);
  709. strm.Close();
  710. }
  711. }
  712. s = [s,r,t,200,url];
  713. } else {
  714. s = [s,r,"",200,url];
  715. }
  716. return s;
  717. };
  718. }
  719.  
  720. function gzipDecompress(file, bin, header) {
  721. var rc, id, src, curDir, s;
  722.  
  723. id = bin;
  724. if(file) { id = loadBinaryFile(file, 4); }
  725. if (b2h(id,0,2)=="1F8B" && Wrap.gzipChk(header)) {
  726. src = file || GZIP_DATA;
  727. if(!file) { saveBinaryFile(src+".gz", bin); }
  728. else {
  729. if(fso.FileExists(src+".gz")) try{ fso.DeleteFile(src+".gz"); } catch(e){};
  730. fso.GetFile(file).Name = fso.GetFile(file).Name + ".gz";
  731. }
  732. curDir = shell.CurrentDirectory;
  733. shell.CurrentDirectory = fso.GetParentFolderName(src+".gz");
  734. rc = shell.Run('"'+GZIP_PATH+GZIP_EXE+'" '+GZIP_ARGS+' "'+src+".gz"+'"', 0, true);
  735. shell.CurrentDirectory = curDir;
  736. if(!rc) {
  737. if(!file) {
  738. try{ bin = loadBinaryFile(src); }catch(e){}
  739. try{ fso.DeleteFile(src); } catch(e) {}
  740. }
  741. if(fso.FileExists(src+".gz")) try{ fso.DeleteFile(src+".gz"); } catch(e){}
  742. }
  743. }
  744. return bin;
  745. }
  746. function gzipChk(header) {
  747. var type=(header.match(/^Content-Type:.*/mg)||[]).join("");
  748. return /gzip|tar-gz/.test(type) ? false : true;
  749. }
  750.  
  751. //-----------------------------------------------------------------
  752.  
  753. function urlReplace(url,detail,noHTTP) {
  754. var lines, line, i, re, s="", rc=0, url2, url3, r, r2, rcv;
  755. lines = ImageViewURLReplaceDat.list;
  756. url2 = url;
  757. for(i=0; i<lines.length; i++) {
  758. if(!lines[i]) continue;
  759. try {
  760. r = Wrap.match(url,lines[i][0],"i");
  761. } catch(e) {
  762. if(detail & 0x08) outln2("ImageViewURLReplace.dat:"+(i+1)+":"+lines[i][0]+" -- この正規表現は認識できません");
  763. r = null;
  764. }
  765. if(r) break;
  766. }
  767. if(r) {
  768. line = lines[i];
  769. button.pos[button.n] = i+1;
  770. if(detail & 0x08) outln2([' --- found it! ---\nline=', i+1, " : ", line[0], "\n ---"].join(""));
  771. url = url2 = line[1];
  772. if(line[2]) {
  773. try { url3 = expand(line[2],r); } catch(e) {}
  774. }
  775. if(!noHTTP && /\$COOKIE|\$EXTRACT/.test(line[3])) {
  776. var s = (line[3].match(/=(.+?)(?=\$COOKIE|#|$)/)||[])[1];
  777. if(s) {
  778. try{ s = expand(s,r); }catch(e){}
  779. HTTP_HEADERS2.Referer = s;
  780. }
  781. try {
  782. if(detail & 0x08) outln("[arg3 URL = "+url3+"]");
  783. rcv = Wrap.readHTTP(url3, true);
  784. if(detail & 0x08) outln("[text length = "+rcv[2].length+" 文字]");
  785. } catch(e) {
  786. if(detail & 0x08) outln("replace URL read error: "+e.message);
  787. rcv=[null,e.message,e.message,e.message];
  788. }
  789. if(s) delete HTTP_HEADERS2.Referer;
  790. }
  791. if(/\$COOKIE/.test(line[3]) && rcv) {
  792. var s=rcv[1].match(/^Set-Cookie: *(.*)\r?\n/img);
  793. if(s) for(var i=0; i<s.length; i++) { Cookies.parse(s[i],0,url3); }
  794. s=rcv[2].match(/<meta http-equiv=(["'])Set-Cookie\1.*?>(?=[\s\S]*(?:<\/head|<body))/ig);
  795. if(s) for(var i=0; i<s.length; i++) { Cookies.parse(s[i],1,url3); }
  796. }
  797. if(/\$EXTRACT/.test(line[3])) {
  798. rc=2;
  799. url2 = (url3 !== void 0) ? url3 : line[2];
  800. if(line[4]) {
  801. try { r2 = Wrap.match(rcv[2],expand(line[4], r),"i"); } catch(e) {r2=null;}
  802. if(!r2) { url = url2; rc=-2; }
  803. else { url = expand2(expand(url,r), r2); }
  804. }
  805. } else { // 引数4が存在しないか$EXTRACTが指定されていない($COOKIEのみ)場合
  806. rc=1;
  807. try { url = url2 = expand(url, r); } catch(e) { rc = -1; }
  808. }
  809. }
  810. //rc=(0:未検出 1:変換 -1:ERR 2:EXTRACT変換 -2:ERR) url=HTTPアクセス用 url2=ハッシュ用 url3=リファラ
  811. if(url3) url3 = url3.replace(/#.*$/,"");
  812. return [rc,url,url2,url3];
  813. }
  814.  
  815. function addNumComma(s) {
  816. try{ return s.toString(10).split('').reverse().join('').replace(/(\d{3})(?=\d)/g,'$1,').split('').reverse().join(''); }
  817. catch(e) { return s; }
  818. }
  819.  
  820. function getEnv(s) { var wse = shell.Environment("Process"); return wse(s); }
  821. function replaceEnv(s) { return s.replace(/\%([^%]+)\%/ig, function(p0,p1) {return getEnv(p1);}); }
  822. function formatDate(d,n) {
  823. return [d.getFullYear()
  824. , "/" , ("0"+(d.getMonth()+1)).slice(-2)
  825. , "/" , ("0"+d.getDate()).slice(-2)
  826. , "(" , "日月火水木金土".substr(d.getDay(),1)
  827. , ") " , ("0"+d.getHours()).slice(-2)
  828. , ":" , ("0"+d.getMinutes()).slice(-2)
  829. , ":" , ("0"+d.getSeconds()).slice(-2)
  830. , "." , ("00"+parseInt(d.getMilliseconds(),10)+" ").slice(-4,n-4)
  831. ].join("");
  832. }
  833. function formatNum(d,n) { return (" "+d).slice(-n); }
  834. function Trace(log) {
  835. var logfile = log ? replaceEnv(log) : TRACE_LOG;
  836. var flag = true;
  837. var first = true;
  838. var t = [];
  839. return function(s,n) {
  840. if(flag) try{
  841. if(!n) n=0;
  842. var f = fso.OpenTextFile(logfile,8,true,0);
  843. if(first) {first=false; f.WriteLine("");}
  844. var tt=new Date();
  845. if(!s) { t[n] = new Date();}
  846. else { f.WriteLine(formatDate(tt,3)+"\t"+((n in t)?formatNum(tt-t[n],7)+"ms":" ")+"\t"+s); }
  847. f.Close();
  848. } catch(e) {flag=false; if(f) f.Close();}
  849. }
  850. }
  851.  
  852. var HTML_CONTENTS = [
  853. '<html><head><title>', WScript.ScriptName, '</title>'
  854. ,'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
  855. ,'<meta http-equiv="Content-Style-Type" content="text/css">'
  856. ,'<style type="text/css">'
  857. ,'<!--'
  858. ,'body{background-color:#ebebeb; color:black;'
  859. ,'font-family:"MS Pゴシック","MS ゴシック";}'
  860. ,'div{margin:0px 0px 10px 0px;}'
  861. ,'strong{color:yellow;background-color:blue;font-size:120%;}'
  862. ,'strong.2{color:blue;background-color:#ebebeb;}'
  863. ,'strong.3{color:blue;background-color:yellow;font-size:100%;}'
  864. ,'.col2{margin-left:40px;} .padding20{padding-left:20px;}'
  865. ,'--></style></head>'
  866. ,'<script type="text/javascript">this.evt=[];function setEvent(s) {this.evt.push(s);};'
  867. ,'function clicked(s) {setEvent(s);}</script>'
  868. ,'<body><div id="msg1"></div></body></html>'
  869. ].join("");
  870.  
  871. function IE() {
  872. this.existsIE = false;
  873. var ie = WScript.CreateObject("InternetExplorer.Application","Event_IE_");
  874. var doc,msg1;
  875. ie.Width =800;
  876. ie.Height =600;
  877. ie.AddressBar = false;
  878. ie.MenuBar = false;
  879. ie.ToolBar = false;
  880. ie.Resizable = true;
  881. ie.Visible = false;
  882. ie.Navigate2("about:blank", 2);
  883. while(ie.Busy || ie.readyState != 4) WScript.Sleep(100);
  884. doc=ie.Document;
  885. doc.write(HTML_CONTENTS);
  886. ie.Visible = true;
  887. msg1 = doc.getElementById('msg1');
  888. this.existsIE = true;
  889. this.out = function(s) { msg1.innerHTML += s.replace(/&/g,"&amp;"); }
  890. this.quit = function() { ie.Quit(); while(ie.Busy) WScript.Sleep(50); this.existsIE=false; }
  891. this.getElement = function(s) { return doc.getElementById(s); }
  892. this.evt = doc.parentWindow.evt;
  893. this.getEvent = function() {
  894. try{ return (this.evt.length) ? this.evt.shift() : null; }catch(e){};
  895. return null;
  896. }
  897. this.setElementByIdDisabled = function(s,t) { this.getElement(s).disabled = t; }
  898. };
  899. function Event_IE_OnQuit() { ie.existsIE = false; event_IE_Quit = true; ie=null;}
  900. function isExistsIE() { return ie ? ie.existsIE : false; }
  901.  
  902. function waitEvent(t) {
  903. var rc = 0, ev, n;
  904. if(!isExistsIE) return -1;
  905. for( ;t>=0 && !rc; t-=100) {
  906. try{
  907. ev=ie.getEvent();
  908. if(ev) {
  909. n=(ev.match(/(\d+)$/)||[])[1];
  910. switch(ev.replace(/\d+$/,"")) {
  911. case "btn": Wrap.invokeEditor(n); break;
  912. default: break;
  913. }
  914. }
  915. } catch(e) { rc = -1; }
  916. if(t>0) WScript.Sleep(100);
  917. }
  918. return 0;
  919. }
  920.  
  921. function invokeEditor(n) {
  922. var parms,fname="ImageViewURLReplace.dat";
  923. n = button.pos[n] + "";
  924. parms = TEXT_EDITOR_PARMS.replace(/\$F/g, JANE_PATH+fname).replace(/\$N/g, n);
  925. sha.ShellExecute(replaceEnv(TEXT_EDITOR), parms);
  926. }
  927.  
  928. function path(p) {
  929. var d = p.match(/[^\\]+\\/g), e = "";
  930. for (var i = 0; d[i]; i++) fso.FolderExists(e += d[i]) || fso.CreateFolder(e);
  931. return p;
  932. }
  933.  
  934. //-----------------------------------------------------------------
  935.  
  936. var button = new function() {
  937. this.n = 0;
  938. this.pos = [];
  939. }
  940.  
  941. var err = new function ERR() {
  942. this.isError = false;
  943. this.out = function(s) { this.isError=true; s="ERROR : "+s; outln(s); throw new Error(s); }
  944. this.popup = function(s) { this.isError=true; s="ERROR : "+s; shell.Popup(s); throw new Error(s); }
  945. }
  946.  
  947. var ini = new function ImageViewIni() {
  948. var ini = "";
  949. var re = "^\\[$1\\]\\r\\n(?:.*\\r\\n)*?(?:$2=(.*)|\\[.*\\])\\r\\n";
  950. var search = function(f,s,p) { return f.match(new RegExp(expand(s,p),"im"))||[]; }
  951. var expand = function(s,p) { return s.replace(/\$(\d)/g, function(m, n) { return (""+p[n]).replace(/\./g,"\\."); }); }
  952.  
  953. try { ini = loadTextFile("ImageView.ini"); } catch(e) {}
  954. this.UseViewCache = search(ini, re, [,"Cache","UseViewCache"])[1];
  955. if(this.UseViewCache=="1")
  956. this.VwCacheDir = search(ini, re, [,"Cache","CachePath"])[1] || "VwCache";
  957. this.FileSizeMaximum = search(ini, re, [,"HTTP","FileSizeMaximum"])[1];
  958. this.TimeOut = search(ini, re, [,"HTTP","TimeOut"])[1];
  959. this.ConnectTimeout = search(ini, re, [,"HTTP","ConnectTimeout"])[1];
  960. try { ini = loadTextFile(JANE2CH_INI); } catch(e) {}
  961. this.Exclude1FromNGProcessing = search(ini, re, [,"VIEW","Exclude1FromNGProcessing"])[1];
  962. ini = null;
  963. }
  964.  
  965. var ImageViewURLReplaceDat = new function(){
  966. var i;
  967. this.list = "";
  968. this.safety_line_pos = Infinity;
  969. try { this.list = loadTextFile("ImageViewURLReplace.dat"); } catch(e) {}
  970. this.list = this.list.replace(/\r/g,"").split("\n");
  971. this.list.splice(this.list.length-1,1);
  972. for(i=0;i<this.list.length;i++) {
  973. if(RE_SAFETY_GUARD_MSG.test(this.list[i])) this.safety_line_pos = i;
  974. this.list[i] = this.list[i].replace(/^(?:\/\/|;|').*$/,"");
  975. if(this.list[i]) this.list[i]=this.list[i].split("\t");
  976. }
  977. };
  978.  
  979. var SearchNGFile = (function() {
  980. var list="",hashlist={},i,hash;
  981. try { list = loadTextFile("NGFiles.txt"); } catch(e) {}
  982. list = list.split("\n");
  983. for(i=0;i<list.length;i++) {
  984. if(list[i].indexOf("=")==26) hashlist[list[i].substring(0,26)] = list[i];
  985. }
  986. list=null;
  987. return function(key) { return hashlist[key]; }
  988. })();
  989.  
  990. function imageHashFile(d){
  991. var i,list="",hashlist={},hash,fname,dir=d;
  992. fname = dir+MY_NAME+".txt";
  993. try{ list=loadTextFile(fname); } catch(e){}
  994. list = list.replace(/^(?:\/\/|;|').*(?=\r?\n)/mg,"").split(/\r?\n/);
  995. list.splice(list.length-1,1);
  996. for(i=0;i<list.length;i++) {
  997. if(list[i]) {
  998. list[i]=list[i].split("\t");
  999. if(list[i][0]) hashlist[list[i][0]] = (list[i][1])?list[i][1]:"dummy";
  1000. }
  1001. }
  1002. return {
  1003. search : function(s) { return hashlist[s]; }
  1004. ,append : function(s,f) {
  1005. hashlist[s]=s;
  1006. try{ saveTextFile(fname,s+"\t"+f+"\r\n",null,true); } catch(e){}
  1007. }
  1008. ,"delete" : function(s) { delete hashlist[s]; }
  1009. ,rebuild : function() {
  1010. var img, s="",f;
  1011. var folder=fso.GetFolder(dir);
  1012. hashlist = {};
  1013. var em = new Enumerator( folder.Files );
  1014. for( em.moveFirst(); !em.atEnd(); em.moveNext() ) {
  1015. f = em.item().Name;
  1016. if(/\.txt$/.test(f)) continue;
  1017. try { img=loadBinaryFile(dir+f); } catch(e) { img=null; }
  1018. if(img!=null) {
  1019. hash=encode(md5(img));
  1020. hashlist[hash] = em.item().Name;
  1021. outln2(hash+" : "+hashlist[hash]);
  1022. }
  1023. }
  1024. for(i in hashlist) s += i+"\t"+hashlist[i]+"\r\n";
  1025. outln2("");
  1026. try{ saveTextFile(fname, s); outln(fname+"ファイルを作成しました");}
  1027. catch(e){ outln(fname+"が作成できませんでした");}
  1028. }
  1029. }
  1030. };
  1031.  
  1032. function NGExClass(s) {
  1033. this._SectionName = s; //管理用
  1034. this.AboneType = 0;
  1035. this.Name = "";
  1036. this.NameBody = "";
  1037. this.Mail = "";
  1038. this.MailBody = "";
  1039. this.ID = "";
  1040. this.IDBody = "";
  1041. this.Msg = "";
  1042. this.MsgBody = "";
  1043. this.Be = "";
  1044. this.BeBody = "";
  1045. this.TargetURL = "";
  1046. this.TargetURLBody = "";
  1047. }
  1048. function escapeMetaChar(s) {return s.replace(/([\/\[\]\(\)\{\}\.\+\*\?\^\$\|\\])/g,"\\$1");}
  1049. function Abone(f) {
  1050. var i,ret,n,s="";
  1051. this.abn = [];
  1052. this.NGs = [];
  1053. this.NGEx = [];
  1054. var NGs_txt=[ "NGnames2.txt", "NGaddrs2.txt", "NGid2.txt", "NGwords2.txt", "NGBE2.txt" ];
  1055. try{ s=bytes2hex(loadBinaryFile(f)); } catch(e){}
  1056. if(s) for(i=0;i<s.length/2; i++) this.abn[i] = parseInt(s.substr(i+i,2),16);
  1057. if(ini.Exclude1FromNGProcessing=="1") this.abn[0] = 0x0C;
  1058. for(i=0; i<NGs_txt.length; i++) {
  1059. s="";
  1060. try{ s=loadTextFile(NGs_txt[i]); } catch(e){}
  1061. this.NGs[i] = s.split(/\r?\n/);
  1062. for(j=0;j<this.NGs[i].length;j++) {
  1063. this.NGs[i][j] = this.NGs[i][j].split("\t");
  1064. n = parseInt(this.NGs[i][j][6],10);
  1065. this.NGs[i][j][6] = isFinite(n) ? n : 0;
  1066. }
  1067. }
  1068. this.isAbn = function(n) {return (this.abn[n] & 0x03) ? true : false;};
  1069. this.isNoNG = function(n) {return (this.abn[n] & 0x0C) ? true : false;};
  1070. this.isNGNames = function(s) {return isNGs(this,s,0,true);};
  1071. this.isNGAddrs = function(s) {return isNGs(this,s,1,true);};
  1072. this.isNGID = function(s) {return isNGs(this,s,2,false);};
  1073. this.isNGWords = function(s) {return isNGs(this,s,3,true);};
  1074. this.isNGBE = function(s) {
  1075. ret=-1;
  1076. for(i=0;i<this.NGs[4].length;i++) {
  1077. if(s==this.NGs[4][i][0]) { ret=this.NGs[4][i][6]; break; }
  1078. }
  1079. return ret;
  1080. };
  1081. this.isNGEx = function(s, url, title) {
  1082. var i,j,r;
  1083. this.NGEx = makeNGExList();
  1084. s = s.split("<>");
  1085. r = -1;
  1086. for(i=0;i<this.NGEx.length;i++) {
  1087. for(j in this.NGEx[i]) {
  1088. if(!this.NGEx[i][j]) continue;
  1089. switch(j) {
  1090. case "Name": r = NGEx_sub(s[0], this.NGEx[i], j, true); break;
  1091. case "Mail": r = NGEx_sub(s[1], this.NGEx[i], j, true); break;
  1092. case "ID": r = NGEx_sub(s[2], this.NGEx[i], j, false); break;
  1093. case "Msg": r = NGEx_sub(s[3], this.NGEx[i], j, true); break;
  1094. case "Be": r = NGEx_sub((s[2].match(/ BE:(\d+)/)||[])[1], this.NGEx[i], j, true); break;
  1095. case "TergetURL":
  1096. r = NGEx_sub(url, this.NGEx[i], j, false);
  1097. if(!r) r = NGEx_sub(title, this.NGEx[i], j, false);
  1098. break;
  1099. default: r = true; break;
  1100. }
  1101. if(!r) break; //どれかがfalseだったら次の条件を判定せずに次の定義に移動する
  1102. }
  1103. if(r) {
  1104. r = parseInt(this.NGEx[i].AboneType,10);
  1105. if(!isFinite(r)) r = 0;
  1106. break; //全部trueだったらこの定義のand条件をすべて満たしたので抜ける
  1107. } else {
  1108. r = -1;
  1109. }
  1110. }
  1111. return r;
  1112. };
  1113. function isNGs(own,s,n,case_insensitive) {
  1114. ret = -1;
  1115. for(i=0;i<own.NGs[n].length;i++) {
  1116. if(!own.NGs[n][i][0]) continue;
  1117. if(case_insensitive) ret = s.toUpperCase().indexOf(own.NGs[n][i][0].toUpperCase());
  1118. else ret = s.indexOf(own.NGs[n][i][0]);
  1119. if(ret>=0) break;
  1120. }
  1121. return (ret>=0) ? own.NGs[n][i][6] : -1;
  1122. }
  1123. function makeNGExList() {
  1124. var i,j,r,s="",ngex,NGEx=[],REs={};
  1125. for(i in new NGExClass()) { REs[i] = new RegExp('^'+i+'="?(.*?)"?$'); }
  1126. try{ s=loadTextFile("NGEx.txt"); } catch(e){}
  1127. s = s.split(/\r?\n/);
  1128. for(i=0;i<s.length;i++) {
  1129. if(r = s[i].match(/^\[(.+?)\]/)) {
  1130. if(ngex) NGEx.push(ngex);
  1131. ngex = new NGExClass(r[1]);
  1132. }
  1133. for(j in new NGExClass()) {
  1134. r = (s[i].match(REs[j])||[])[1];
  1135. if(r) {
  1136. if(!ngex) ngex = new NGExClass(); //イレギュラー対策
  1137. ngex[j] = r;
  1138. }
  1139. }
  1140. }
  1141. if(ngex) NGEx.push(ngex);
  1142. return NGEx;
  1143. }
  1144. function NGEx_sub(s, ngex, itemName, case_insensitive) {
  1145. var r,str;
  1146. str = ngex[itemName+"Body"];
  1147. if(!str) return false;
  1148. try {
  1149. switch(ngex[itemName]) {
  1150. case "0": r = Wrap.test(s, escapeMetaChar(str), (case_insensitive)?"i":""); break;
  1151. case "1": r = !Wrap.test(s, escapeMetaChar(str), (case_insensitive)?"i":""); break;
  1152. case "2": r = Wrap.test(s, "^"+escapeMetaChar(str)+"$", (case_insensitive)?"i":""); break;
  1153. case "3": r = !Wrap.test(s, "^"+escapeMetaChar(str)+"$", (case_insensitive)?"i":""); break;
  1154. case "4": r = Wrap.test(s, str, (case_insensitive)?"i":""); break;
  1155. case "5": r = !Wrap.test(s, str, (case_insensitive)?"i":""); break;
  1156. default: r = false; break;
  1157. }
  1158. } catch(e) { r = false; }
  1159. return r;
  1160. }
  1161. }
  1162.  
  1163. function ReplaceStrTxt() {
  1164. var i,list="";
  1165. try{ list=loadTextFile("ReplaceStr.txt"); } catch(e){}
  1166. list = list.replace(/^(?:\/\/|;|').*(?=\r?\n)/mg,"").split(/\r?\n/);
  1167. for(i=0;i<list.length;i++) {
  1168. if(list[i]) {
  1169. list[i]= list[i].replace(/^<>/,"<rx>")
  1170. .replace(/^((?!<)\S)/,"<ex>$1")
  1171. .replace(/^(.+?\t.*?\t.*?\t)<>/,"$1<0>")
  1172. .replace(/^(.+?\t.*?\t.*?\t)((?!<[012345]>)\S)/,"$1<0>$2");
  1173. list[i]=list[i].split("\t");
  1174. }
  1175. }
  1176. s="";for(i=0;i<list.length;i++) {if(list[i]) s+=list[i].join("\t");s+="\n";}
  1177. this.execute = function(s,url,title) {
  1178. var i,r,s2,re;
  1179. for(i=0;i<list.length;i++) {
  1180. if(!list[i][0] || list[i][2] && !/^(?:msg|all|$)/i.test(list[i][2])) continue;
  1181. if(list[i][3]) {
  1182. r = list[i][3].match(/<(\d)>(.*)$/);
  1183. try {
  1184. switch(r[1]) {
  1185. case "0": if((url+"\n"+title).indexOf(r[2])<0) continue; break;
  1186. case "1": if((url+"\n"+title).indexOf(r[2])>=0) continue; break;
  1187. case "2": if(url!=r[2] && title!=r[2]) continue; break;
  1188. case "3": if(url==r[2] || title==r[2]) continue; break;
  1189. case "4": if(!Wrap.test(url,r[2],"i")&&!Wrap.test(title,r[2],"i")) continue; break;
  1190. case "5": if(Wrap.test(url,r[2],"i")||Wrap.test(title,r[2],"i")) continue; break;
  1191. }
  1192. } catch(e) { continue; }
  1193. }
  1194. r = list[i][0].match(/^<(ex2|ex|rx2|rx)>(.+)$/i);
  1195. try {
  1196. switch((r||[])[1]) {
  1197. case "ex" : s=Wrap.replace(s,escapeMetaChar(r[2]),"ig",list[i][1]); break;
  1198. case "ex2" : s=Wrap.replace(s,escapeMetaChar(r[2]),"g",list[i][1]); break;
  1199. case "rx" : s=Wrap.replace(s,r[2],"ig",list[i][1]); break;
  1200. case "rx2" : s=Wrap.replace(s,r[2],"g",list[i][1]); break;
  1201. }
  1202. } catch(e){}
  1203. }
  1204. return s;
  1205. };
  1206. };
  1207.  
  1208. function Cookie() {
  1209. this.key;
  1210. this.data;
  1211. this.domain;
  1212. this.path;
  1213. this.secure;
  1214. this.lifetime;
  1215. this.inHtml;
  1216. }
  1217. Cookie.prototype.set = function(key, data, domain, path, secure, lifetime, inHtml) {
  1218. this.key = key;
  1219. this.data = data;
  1220. this.domain = domain;
  1221. this.path = path;
  1222. this.secure = secure;
  1223. this.lifetime = lifetime;
  1224. this.inHtml = inHtml;
  1225. }
  1226. var cookies = [];
  1227. var Cookies = (function() {
  1228. var words = [ "(path)=", "(domain)=", "(secure)", "(httponly)", "(max-age)=", "(expires)="
  1229. , "(version)=", "(comment)=", "(.+)=", "(.)" ];
  1230. return {
  1231. parse : function(s,inHtml,url) {
  1232. var key=[], data=[], path="", domain="", secure=false, lifetime, httponly=false;
  1233. var i,re,r,sArray,chunk;
  1234. var r = this.parseURL(url);
  1235. domain = r[0];
  1236. path = r[1];
  1237. sArray = s.replace(/^Set-Cookie: *(.*)\s*$/i,"$1").replace(/^<meta.*content=(["'])(.+)\1.*\s*$/i,"$2").split(/; */);
  1238. while(sArray.length) {
  1239. chunk = sArray.shift();
  1240. for(i=0; i<words.length; i++) {
  1241. re=new RegExp("^"+words[i]+"(.*)$", "i");
  1242. r = chunk.match(re);
  1243. if(!r) continue;
  1244. switch(i) {
  1245. case 0: path = r[2]; break
  1246. case 1: domain = r[2]; break;
  1247. case 2: secure = true; break;
  1248. case 3: break; //httponlyはスキップ
  1249. case 4: lifetime = Number(r[2]); break;
  1250. case 5:
  1251. if(!isFinite(lifetime)) {
  1252. lifetime = r[2].replace(/-/g," ").replace(/(\d+ \w+ )(\d\d)(?=[^\d])/,"$120$2");
  1253. }
  1254. break;
  1255. case 6: break; //versionはスキップ
  1256. case 7: break; //commentはスキップ
  1257. case 8: key.push(r[1]); data.push(r[2]); break;
  1258. default: break;
  1259. }
  1260. break;
  1261. }
  1262. }
  1263. if(lifetime!==void 0) {
  1264. try{
  1265. if(!isFinite(lifetime)) lifetime = new Date(lifetime)-0;
  1266. else lifetime = (new Date()-0) + Number(lifetime) * 1000;
  1267. } catch(e) {}
  1268. }
  1269. for(i=0; i<key.length; i++) {
  1270. var cookie=new Cookie();
  1271. cookie.set(key[i], data[i], domain, path, secure, lifetime, inHtml);
  1272. if(secure && /^http:/.test(url)) continue;
  1273. if(lifetime!==void 0 && new Date()>=lifetime) this.del(cookie);
  1274. else if(USING_CURL||inHtml) this.put(cookie); //ヘッダの場合auto-cookie handlingで処理されるのでスキップ
  1275. }
  1276. }
  1277. , put : function(cookie) {
  1278. var r = this.search(cookie);
  1279. if(r>=0) cookies[i] = cookie;
  1280. else cookies.push(cookie);
  1281. }
  1282. , del : function(cookie) {
  1283. var r = this.search(cookie);
  1284. if(r>=0) {cookies.splice(r,1);}
  1285. }
  1286. , search : function(cookie) {
  1287. var i,r=-1;
  1288. for(i=0; i<cookies.length; i++) {
  1289. if(cookies[i].key==cookie.key && cookies[i].domain==cookie.domain && cookies[i].path==cookie.path)
  1290. {r=i; break;}
  1291. }
  1292. return r;
  1293. }
  1294. , parseURL : function(url) {
  1295. var i, r, domain, path;
  1296. r = url.replace(/^https?:\/\//,"").split("/");
  1297. domain = r.shift();
  1298. if(r[r.length-1]!="") r.pop();
  1299. for(i=0;i<r.length;i++) {
  1300. if(r[i]==".") { r.splice(i,1); }
  1301. if(r[i]=="..") { (i>0) ? r.splice(i-1,2) : r.splice(i,1); }
  1302. }
  1303. path = "/"+r.join("/");
  1304. return [domain, path];
  1305. }
  1306. , setHttpHeaders : function(HeaderList, url) {
  1307. var r, domain, path;
  1308. r = this.parseURL(url);
  1309. domain = r[0];
  1310. path = r[1];
  1311. for(var i=0; i<cookies.length; i++) {
  1312. if(cookies[i].lifetime!==void 0 && new Date()>=cookies[i].lifetime) cookies.splice(i,1);
  1313. }
  1314. for(var i=0; i<cookies.length; i++) {
  1315. if(cookies[i].domain == domain
  1316. && (!cookies[i].secure || url.indexOf("https")<0)
  1317. && path.indexOf(cookies[i].path)>=0) {
  1318. if("Cookie" in HeaderList) HeaderList["Cookie"] += "; "+cookies[i].key+"="+cookies[i].data;
  1319. else HeaderList["Cookie"] = cookies[i].key+"="+cookies[i].data;
  1320. }
  1321. }
  1322. }
  1323. , getAll : function() {
  1324. var i,j,r=[],s;
  1325. for (i=0;i<cookies.length;i++) {s="";for(j in cookies[i]) if(j!="set") s+=j+"="+cookies[i][j]+"; "; r.push(s);}
  1326. return r.join("\n");
  1327. }
  1328. }
  1329. })();
  1330.  
  1331. //-----------------------------------------------------------------
  1332.  
  1333. function getVchFileName(url,detail) {
  1334. var rc, url_new, vwCacheDir, vchFile, hash;
  1335.  
  1336. rc = Wrap.urlReplace(url, detail, true);
  1337. if(detail & 0x01) {
  1338. outln2("結果: \t"+rc[0]+"\t(0:未検出 1:変換 -1:ERR 2:EXTRACT変換 -2:ERR)");
  1339. outln2("new : \t"+rc[2]);
  1340. }
  1341. url_new = rc[2];
  1342. vwCacheDir = ini.VwCacheDir.replace(/[^\\\/]$/,"$&\\");
  1343. hash = encode(md5(string2bytes(url_new)));
  1344. vwCacheDir = ini.VwCacheDir.replace(/[^\\\/]$/,"$&\\");
  1345. vchFile = hash.substr(0,22) + ".vch";
  1346. if(detail & 0x02) outln2("【ファイル名】"+vchFile,"strong","2");
  1347. return vwCacheDir + vchFile;
  1348. }
  1349.  
  1350. function genVwCache(url,detail) {
  1351. var rc, url_new, url_access, url_referer, vwCacheDir, vchFile, hash, n;
  1352. var isErr = false;
  1353.  
  1354. cookies = [];
  1355. delete HTTP_HEADERS2.Cookie;
  1356. delete HTTP_HEADERS2.Referer;
  1357.  
  1358. url_new = url;
  1359. url_access = url;
  1360. ++button.n;
  1361. if(detail & 0x08) {
  1362. var btnmsg = (CSCRIPT) ? "" : expand(MSG_SEARCH_IMAGE_DAT1_B, [,button.n]);
  1363. outln2(expand(MSG_SEARCH_IMAGE_DAT1,[,btnmsg]));
  1364. }
  1365. rc = Wrap.urlReplace(url, detail);
  1366. switch(rc[0]) {
  1367. case 0: //no match
  1368. if(args.imgonly && !/\.(?:jpe?g|png|gif|bmp)(?=$|&)/i.test(url)) {
  1369. outln("URL="+url);
  1370. outln("Skip: imgのURLではありません","strong","3");
  1371. return;
  1372. }
  1373. outln2("未検出");
  1374. break;
  1375. case -1: //replaced //このケースは発生しない
  1376. case -2: //$EXTRACT変換
  1377. try{ err.out("URL変換失敗"+((rc[0]==-2)?"(第5引数)":"(第1引数)")); } catch(e) {};
  1378. isErr = true;
  1379. break;
  1380. }
  1381. if(HTTPS_SAFETY_GUARD_OFF
  1382. && url.substr(0,5) == "https"
  1383. && rc[1].substr(0,5) == "http:"
  1384. && button.pos[button.n] > ImageViewURLReplaceDat.safety_line_pos) {
  1385. rc[1]=rc[1].replace(/^http:/,"https:");
  1386. if(rc[3]) rc[3]=rc[3].replace(/^http:/,"https:");
  1387. if(detail & 0x08) outln2("*** 最終防衛ラインによる置換をhttpsに戻しました");
  1388. }
  1389.  
  1390. url_access = rc[1];
  1391. url_new = rc[2];
  1392. url_referer = rc[3];
  1393. if(detail & 0x08) outln2(MSG_SEARCH_IMAGE_DAT2);
  1394.  
  1395. if(detail & 0x01) {
  1396. outln("Org URL: "+url);
  1397. outln("New URL: "+url_new);
  1398. outln("Access : "+url_access);
  1399. } else {
  1400. trace("Org URL: "+url, 2);
  1401. trace("New URL: "+url_new, 2);
  1402. trace("Access : "+url_access, 2);
  1403. }
  1404.  
  1405. vwCacheDir = ini.VwCacheDir.replace(/[^\\\/]$/,"$&\\");
  1406. hash = encode(md5(string2bytes(url_new)));
  1407. vchFile = hash.substr(0,22) + ".vch";
  1408.  
  1409. if(url_referer) HTTP_HEADERS2.Referer = url_referer;
  1410. Cookies.setHttpHeaders(HTTP_HEADERS2, url_access);
  1411.  
  1412. if(args.outimg) {
  1413. if(fso.FileExists(vwCacheDir+vchFile)) Wrap.putImgFile(vwCacheDir+vchFile, null);
  1414. else Wrap.putImgFile(null, url_access);
  1415. } else if(args.deleteVch) {
  1416. Wrap.deleteVchFile(vwCacheDir, vchFile);
  1417. } else {
  1418. Wrap.putVchFile(url_new, url_access, vwCacheDir, vchFile, isErr, detail);
  1419. }
  1420. }
  1421.  
  1422. function putVchFile(url_new, url_access, vwCacheDir, vchFile, isErr, detail) {
  1423. var img, Vch, n;
  1424.  
  1425. if(detail & 0x02) outln("【ファイル名】"+vchFile,"strong","2");
  1426. else trace("【ファイル名】"+vchFile, 2);
  1427.  
  1428. isErr = Wrap.dispOldVchFile(vwCacheDir, vchFile, isErr, detail);
  1429. if(isErr) return;
  1430. try { img=Wrap.readHTTP(url_access); }
  1431. catch(e) { img=e.message; try{err.out("http: "+e.message);}catch(e){} }
  1432. outln2("");
  1433. if(event_IE_Quit) return;
  1434.  
  1435. Vch = new VCH();
  1436. img = Wrap.setVch(img, url_new, Vch, detail);
  1437. n = ("0000000"+Vch.getAll().length.toString(16)).slice(-8);
  1438. vchFile = path(vwCacheDir+vchFile);
  1439. try {
  1440. saveBinaryFile(vchFile, hex2bytes(hexReverseByteOrder(n)));
  1441. saveTextFile(vchFile, Vch.getAll(), "", true);
  1442. if(img!=null) saveBinaryFile(vchFile, img, true);
  1443. } catch(e) {
  1444. try{ fso.DeleteFile(vchFile); } catch(e2) {}
  1445. try{ err.out("save: "+e.message); } catch(e) {if(!ie) throw new Error(e.message); }
  1446. return;
  1447. }
  1448. Vch = null;
  1449. }
  1450.  
  1451. function putImgFile(vchfile, url_access) {
  1452. var s, img, n, fname, fext="", fsize, top2, hash, f;
  1453. if(vchfile) {
  1454. n = chkOldVchExists(vchfile);
  1455. if(n) {
  1456. try{ img = loadBinaryFile(vchfile, fsize-4-n, 4+n); }
  1457. catch(e){ outln("Skip: ファイル読込みエラー"+e.message,"Strong","3"); return; }
  1458. } else { outln("Skip: vchファイルにimgデータ無し","strong","3"); return; }
  1459. } else {
  1460. try { img=Wrap.readHTTP(url_access); }
  1461. catch(e) { try{err.out("http: "+e.message);}catch(e){return;} }
  1462. if(event_IE_Quit) return;
  1463. img = img[0];
  1464. }
  1465. switch( b2h(img,0,2) ) {
  1466. case "FFD8" : fext = ".jpg"; break;
  1467. case "8950" : fext = ".png"; break;
  1468. case "4749" : fext = ".gif"; break;
  1469. case "424D" : fext = ".bmp"; break;
  1470. default : fext = ".dat";
  1471. }
  1472. //if(args.imgonly && fext==".dat") {outln("Skip: imgではありません","strong","3"); return;}
  1473. hash = encode(md5(img));
  1474. if(f=ImageHashFile.search(hash)) {outln("Skip: 同hash値のファイル("+f+")があります","strong","3");}
  1475. else if (SearchNGFile(hash)) {outln("Skip: NGFiles.txtで検閲されました","strong","3");}
  1476. else {
  1477. fname=Wrap.newfile(args.outimg, vchfile, url_access, fext);
  1478. try{
  1479. saveBinaryFile(args.outimg+fname,img);
  1480. outln(fname,"strong","3");
  1481. } catch(e){ outln(fname+" --- 失敗"+e.message,"strong","3"); }
  1482. ImageHashFile.append(hash,fname);
  1483. }
  1484. return;
  1485. }
  1486.  
  1487. function deleteVchFile(vwCacheDir, vchFile) {
  1488. if(fso.FileExists(vwCacheDir+vchFile)) {
  1489. try{
  1490. fso.DeleteFile(vwCacheDir+vchFile);
  1491. outln(vchFile+" --- 削除","strong","3");
  1492. } catch(e) { outln(vchFile+" --- 削除できません","strong","3"); }
  1493. } else {
  1494. outln2("既存ファイルなし");
  1495. }
  1496. return;
  1497. }
  1498.  
  1499. function getVchInfo(f) {
  1500. var s="", n, m;
  1501. n = bytes2hex(loadBinaryFile(f, 4));
  1502. m = parseInt(hexReverseByteOrder(n),16);
  1503. if(!isNaN(m)) s = loadTextFile(f, m, 4);
  1504. return s;
  1505. }
  1506.  
  1507. function VCH() {
  1508. var data = [];
  1509. this.putItem = function(s,d) { if(d) data.push(s+"="+d); }
  1510. this.getAll = function() { var r=data.join("\r\n"); return r ? r+"\r\n" : ""; }
  1511. }
  1512.  
  1513. function hexReverseByteOrder(s) {
  1514. var i,ss="";
  1515. for(i=0; i<s.length; i+=2) { ss += s.substr(s.length-i-2,2); }
  1516. return ss;
  1517. }
  1518.  
  1519. function dispOldVchFile(vwCacheDir, vchFile, isErr, detail) {
  1520. if(fso.FileExists(vwCacheDir+vchFile)) {
  1521. if(args.skip && chkOldVchExists(vwCacheDir+vchFile)) {
  1522. outln("Skip: vchファイルが存在しています","strong","3");
  1523. isErr=true;
  1524. } else {
  1525. if(detail & 0x20) {
  1526. outln2("【既存ファイルの内容】");
  1527. outln2(getVchInfo(vwCacheDir+vchFile),"div","col2");
  1528. }
  1529. }
  1530. } else {
  1531. if(isErr) outln("ファイルがありません");
  1532. else if(detail & 0x20) outln2("既存ファイルなし");
  1533. }
  1534. return isErr;
  1535. }
  1536.  
  1537. function chkOldVchExists(vchfile) {
  1538. var s, n=0;
  1539.  
  1540. if(fso.FileExists(vchfile)) {
  1541. try { s = loadBinaryFile(vchfile, 4) } catch(e) {}
  1542. if(s !== void 0) {
  1543. n = parseInt(hexReverseByteOrder(bytes2hex(s)),16);
  1544. if(isNaN(n) || fso.GetFile(vchfile).Size<=4+n) { n = 0; }
  1545. }
  1546. }
  1547. return n;
  1548. }
  1549.  
  1550. function setVch(img, url_new, Vch, detail) {
  1551. var header, ngFile, hash;
  1552.  
  1553. if(typeof img=='string') { //http error code set
  1554. Vch.putItem("URL", url_new);
  1555. Vch.putItem("Referer", args.link);
  1556. Vch.putItem("STATUS", img);
  1557. img = null;
  1558. } else {
  1559. header = img[1];
  1560. try { hash=encode(md5(img[0])); } catch(e) { hash="作成できません"; }
  1561. if(detail & 0x04) outln("【NGFile用ハッシュ】 "+hash,"strong","2");
  1562. else trace("【NGFile用ハッシュ】 "+hash, 2);
  1563.  
  1564. ngFile = SearchNGFile(hash);
  1565. if(ngFile) outln("《ブラクラ危険》:"+ngFile+"\n","strong","3");
  1566. if(!ngFile) {
  1567. img = img[0];
  1568. Vch.putItem("ContentType", (header.match(/^Content-Type:\s*([^\r]+)/im)||[])[1]);
  1569. Vch.putItem("LastModified", (header.match(/^Last-Modified:\s*([^\r]+)/im)||[])[1]);
  1570. Vch.putItem("URL", url_new);
  1571. Vch.putItem("Referer", args.link);
  1572. } else {
  1573. img = null;
  1574. Vch.putItem("URL", url_new);
  1575. Vch.putItem("STATUS", "BROCRA");
  1576. }
  1577. }
  1578. if(detail & 0x10) {
  1579. outln2("【作成したヘッダ内容】");
  1580. outln2(Vch.getAll(),"div","col2");
  1581. }
  1582. return img;
  1583. }
  1584.  
  1585. function newfile_time(d, vchfile, url, fext) { return (new Date()-0) + fext; }
  1586. function newfile_name(d, vchfile, url, fext) {
  1587. var s, fname, count = 0, a = [];
  1588. s = vchfile ? ((getVchInfo(vchfile).match(/^URL=(.+?)\s*$/m)||[])[1]||"") : url;
  1589. s = decodeURIComponent(s);
  1590. s = s.replace(/\?.*$/,"");
  1591. s = s.replace(/\/$/,"");
  1592. s = s.replace(/\/#/,"#");
  1593. s = s.replace(/^.+\//,"");
  1594. s = s.replace(/\.(?:jpe?g|gif(?:v)?|png|bmp|html?|php|aspx?|cgi)$/i,"");
  1595. s = s.replace(/^[ .]+/,"");
  1596. s = s.replace(TBL_CONV_RE, function(w){return TBL_CONV_CHARS[w];});
  1597. s = s.replace(/^(con|aux|nul|prn|com\d|lpt\d)(?:\.|$)/i, "$1$");
  1598. s = (s || "(unknown)");
  1599. a = ["", s, ""];
  1600. while(fso.FileExists(d+a.join("")+fext)) {
  1601. a = Wrap.genRetryNewName(a,++count);
  1602. }
  1603. return a.join("") + fext;
  1604. }
  1605. function genRetryNewName(a,c) {
  1606. // a[0]:prefix, a[1]:filename, a[2]:postfix c:count
  1607. a[2] = "_" + ((c<1000) ? ("00"+c).slice(-3) : c);
  1608. return a;
  1609. return
  1610. }
  1611.  
  1612. //-------------------
  1613.  
  1614. function parseParms() {
  1615. var i;
  1616. args.ie = args0.Exists("i");
  1617. if(!args0.Item("link") && !args0.Item("range") && !args0.Item("res") && !args0.Exists("rebuild"))
  1618. { throw new Error("引数 /link /range /res /rebuild のいずれかを指定してください"); }
  1619. args.url = args0.Item("link");
  1620. args.link = args0.Item("url");
  1621. args.range = args0.Item("range") && decodeURIComponent(args0.Item("range"));
  1622. args.res = args0.Item("res");
  1623. if(args.res) {
  1624. args.res = args.res.split(",");
  1625. for(i=1;i<args.res.length;i++) { args.res[i]=parseInt(args.res[i],10); }
  1626. if(isNaN(args.res[2])) args.res[2] = 1;
  1627. if(isNaN(args.res[1])) { args.res[1] = 1; args.res[2] = 0; }
  1628. }
  1629. args.proxy = args0.Item("proxy");
  1630. args.httpsonly = args0.Exists("httpsonly");
  1631. args.skip = args0.Exists("skip");
  1632. args.imgonly = args0.Exists("imgonly");
  1633. args.outimg = (args0.Item("outimg") && replaceEnv(args0.Item("outimg")).replace(/[^\\\/]$/,"$&\\"));
  1634. args.deleteVch = args0.Exists("delete");
  1635. args.rebuild = args0.Exists("rebuild");
  1636. args.abn = (args0.Item("abn") != "no");
  1637. if(args.rebuild && !args.outimg) throw new Error("/rebuildを実行するには/outimgを指定してください");
  1638. }
  1639. function makeURLs() {
  1640. var urls,i,r,s,delNo,ln,title,abone,offset,replaceStrTxt;
  1641. var isNGs = { isNGNames : /^(.*?)<>/, isNGAddrs : /^.*?<>(.*?)<>/
  1642. , isNGID : /^.*?<>.*?<>(.*?)<>/, isNGWords : /^.*?<>.*?<>.*?<>(.+?)<>/
  1643. , isNGBE : /^.*?<>.*?<>.*? BE:(\d+).*?<>/ };
  1644. if(args.res) {
  1645. try { urls = loadTextFile(args.res[0]) }
  1646. catch(e) { throw new Error("datファイルが読み込めません: "+e.message); }
  1647. // datにtitleが埋め込まれてない場合もある
  1648. title = (urls.match(/^.*?<>.*?<>.*?<>.*?<>(.*)\r?$/m)||[])[1];
  1649.  
  1650. offset=0;
  1651. urls = urls.split(/\r?\n/);
  1652. if(args.res[1]) {
  1653. offset = args.res[1]-1;
  1654. ln = 0;
  1655. delNo = offset;
  1656. if(args.res[2]) {
  1657. delNo += args.res[2];
  1658. ln = urls.length-delNo;
  1659. }
  1660. if(ln>0) urls.splice(delNo, ln);
  1661. if(args.res[1]>1) urls.splice(0,args.res[1]-1);
  1662. }
  1663. if(!NO_ABONE) abone = new Abone(args.res[0].replace(/\.dat$/,".abn"));
  1664. for(i=0;i<urls.length;i++) {
  1665. if(!NO_ABONE) {
  1666. if(abone.isAbn(i+offset)) {urls[i]=""; continue; } //あぼーん・透明あぼーん
  1667. if(abone.isNoNG(i+offset)) continue; //自分・重要レス
  1668. for(j in isNGs) {
  1669. r = abone[j]( (urls[i].match(isNGs[j])||[])[1] );
  1670. if(r>=0) {
  1671. if(r<4) urls[i] = "";
  1672. break;
  1673. }
  1674. }
  1675. if(r<0) { //NGxxにマッチしなかった場合のみNGExを判定する
  1676. r = abone.isNGEx(urls[i], args.link, title);
  1677. if(r>=0 && r<4) urls[i] = "";
  1678. }
  1679. }
  1680.  
  1681. replaceStrTxt = new ReplaceStrTxt();
  1682. if(urls[i]) { //ReplaceStr.Txtによるテキスト変換
  1683. urls[i] = urls[i].replace(/^.*?<>.*?<>.*?<>(.*?)<>.*$/,"$1");
  1684. if(urls[i]) urls[i] = replaceStrTxt.execute(urls[i],args.link,title);
  1685. }
  1686. }
  1687. urls = urls.join("\n").replace(/&amp;/g,"&");
  1688. abone = replaceStrTxt = null;
  1689. } else {
  1690. urls = args.range;
  1691. }
  1692. urls = urls.replace(/h?(ttps?:\/\/)/g,"h$1");
  1693. var re = (args.httpsonly)
  1694. ? /https:\/\/[-.a-zA-Z0-9]+(?::\d+)?\/[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#\[\]]+/g
  1695. : /https?:\/\/[-.a-zA-Z0-9]+(?::\d+)?\/[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#\[\]]+/g;
  1696. return urls.match(re);
  1697. }
  1698.  
  1699. function main() {
  1700. var i, url;
  1701.  
  1702. if(!args.abn) NO_ABONE = true;
  1703. trace = args0.Exists("log") ? new Trace(args0.Item("log")) : function(){};
  1704. if(args0.Exists("i")) { if(CSCRIPT) Wrap.out2 = _out2_console; else ie = new IE(); }
  1705. if (USING_CURL) {
  1706. CURL_PATH = replaceEnv(CURL_PATH).replace(/[^\\\/]$/,"$&\\");
  1707. if(!fso.FileExists(CURL_PATH+CURL_EXE)) err.popup("File Not Found - "+CURL_PATH+CURL_EXE);
  1708. cURL = new CURL();
  1709. Wrap.readHTTP = cURL.readHTTP;
  1710. }
  1711. if(USING_GZIP||USING_7Z) {
  1712. if(!USING_GZIP) {
  1713. GZIP_EXE = GZIP_EXE_7Z;
  1714. GZIP_ARGS = GZIP_ARGS_7Z;
  1715. }
  1716. GZIP_PATH = replaceEnv(GZIP_PATH).replace(/[^\\\/]$/,"$&\\");
  1717. if(!fso.FileExists(GZIP_PATH+GZIP_EXE)) err.popup("File Not Found - "+GZIP_PATH+GZIP_EXE);
  1718. }
  1719.  
  1720. Wrap.initialize();
  1721. trace("--- start ---",1);trace("",1);
  1722. if(args.outimg) {
  1723. path(args.outimg);
  1724. ImageHashFile = new imageHashFile(args.outimg);
  1725. }
  1726. if(args.rebuild) {
  1727. ImageHashFile.rebuild();
  1728. } else {
  1729. if(ini.UseViewCache=="1") {
  1730. if(!args.range && !args.res) { Wrap.genVwCache(args.url, 0x3f); }
  1731. else {
  1732. url = Wrap.makeURLs();
  1733. if(url) {
  1734. for(i=0; i<url.length; i++) {
  1735. Wrap.genVwCache(url[i], 0x07);
  1736. outln2("");
  1737. if(event_IE_Quit) break;
  1738. }
  1739. } else outln2("URL抽出 0件");
  1740. }
  1741. } else {
  1742. outln("ビューア設定で「キャッシュを使用する」がチェックされていません");
  1743. }
  1744. }
  1745. Wrap.finalize();
  1746. outln2("--- finished. ---");
  1747. trace("--- end ---",1);
  1748.  
  1749. if(USING_CURL && CURL_DELTMP) {
  1750. try{ fso.DeleteFile(CURL_DATA); } catch(e) {}
  1751. try{ fso.DeleteFile(CURL_HEADER); } catch(e) {}
  1752. try{ fso.DeleteFile(CURL_OUTPUT); } catch(e) {}
  1753. }
  1754. }
  1755.  
  1756. //=================================================================
  1757.  
  1758. var args0 = WScript.Arguments.Named, args = {};
  1759. var trace, ie, ImageHashFile, cfg, cURL, event_IE_Quit = false;
  1760. var ruby, perl;
  1761.  
  1762. //----- オプションファイルの組み込み (genVwCache.cfg) -----
  1763. cfg = args0.Item("cfg") || CFG_FILE;
  1764. if(fso.FileExists(replaceEnv(cfg))) {
  1765. // "_autodetect"が効かないorz
  1766. var code = loadTextFile(cfg, null, null, "utf-8");
  1767. try{ eval(code);} catch(e) { shell.Popup("文法エラー又は文字コードがUTF-8で無い: "+e.message); q(); }
  1768. }
  1769. //---------------------------------------------------------
  1770.  
  1771. if (USING_PERL) { perl = new PERL(); }
  1772. if (USING_RUBY) { ruby = new RUBY(); }
  1773.  
  1774. try { Wrap.parseParms(); } catch(e) { err.popup(e.message); q(); }
  1775. try { Wrap.main(); } catch(e){}
  1776.  
  1777. if(!CSCRIPT) {
  1778. while(isExistsIE()) {
  1779. if(!err.isError && args0.Item("i")) {
  1780. if(!waitEvent(parseInt(args0.Item("i"),10))) try{ie.quit();}catch(e){};
  1781. } else { waitEvent(1000); }
  1782. }
  1783. }
  1784.  
  1785. var isError = err.isError;
  1786. cURL = trace = ie = ini = fso = shell = strm = http = cookies = Cookies = err = button = ImageHashFile = SearchNGFile = ImageViewURLReplaceDat = perl = ruby = null;
  1787.  
  1788. if(CSCRIPT && args0.Exists("i")) {
  1789. if(!isError && args0.Item("i")) WScript.Sleep(parseInt(args0.Item("i"),10));
  1790. else while(true){ WScript.Sleep(50); };
  1791. }
  1792.  
  1793. ]]>
  1794. </script>
  1795. <!--
  1796. //=========================================================
  1797. //修正履歴:
  1798. //2015.11.27: 新規作成
  1799. //2015.12.05: ver 0.2
  1800. // 抽出からのリンククリックでスレURLが無い場合でも取得作成可能とした
  1801. // ImageViewURLReplace.datの第4,5引数有($EXTRACT)の変換を可能にした
  1802. // /i:時、ImageViewURLReplace.datの検索結果を表示するようにした
  1803. // http読み込み中にIEウィンドウを閉じると処理を中断するようにした
  1804. //2015.12.10: ver 0.3
  1805. // ImageViewURLReplace.datの変換処理を修正
  1806. // ( url.replace(第1引数,第2引数)で処理していたところを、
  1807. // url.$&(=第1引数にマッチした全体のこと).replace(第1引数,第2引数)に変更した)
  1808. //2016.01.08: ver 0.4
  1809. // HTTPアクセスでアドレス末尾のURLフラグメント(#以降)を削除するようにした
  1810. // ImageViewURLReplace.datの変換処理を修正
  1811. // (第5引数の$nの部分を順次置換していくようにした、
  1812. // またこのとき第3引数をURLとしてアクセスする、第3引数の特殊変数$&,$1,…を置換する)
  1813. // 第2引数の$n,$EXTRACT[n]も同様に変更)
  1814. //2016.01.09: ver 0.5
  1815. // ImageViewURLReplace.datの変換処理を修正
  1816. // (第1,5引数のマッチングで大文字小文字の区別をしないようにした)
  1817. //2016.01.11: ver 0.6
  1818. // ImageViewURLReplace.datの変換処理を修正
  1819. // ($EXTRACTの場合、vchファイル名を第3引数から作成するようにした)
  1820. // HTTPアクセスでアドレスに &amp; が含まれている場合、& に変換する(独自仕様)
  1821. // HTTPアクセスでUser-Agent指定を変更
  1822. // (ver 0.4-0.5のUAだとo.8ch.netのブラックリストに載ってるようで弾かれる
  1823. // なお、UA指定をコメントアウトした場合のUAは、
  1824. // "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)" )
  1825. //2016.01.16: ver 0.7
  1826. // ImageViewURLReplace.datが存在してない場合、エラーになってたのを修正
  1827. // ビューア設定で「キャッシュを使用する」未チェックの場合、エラーになってたのを修正
  1828. // /i時、表示を少し修飾及びテキストエディタ起動ボタンを追加
  1829. // (先頭にあるユーザー設定エリアにテキストエディタの設定をしてください)
  1830. //2016.02.06: ver 0.8
  1831. // PROXY経由でのアクセスを可能とした(引数に /PROXY:server:port 指定を追加)
  1832. // ImageViewURLReplace.datの変換処理で、cookie処理及びreferer処理を追加
  1833. // (なお、Jane StyleのCookie Handlingは受信したSet-Cookie値をそのまま
  1834. // まるごと返すという荒っぽいものであることが判明した
  1835. // また、Set-Cookie2とCookie2のハンドリングはIEやChromeもしてないようなので無視する)
  1836. // HTTPアクセスにデフォルトで WinHttp.WinHttpRequest.5.1 を使うように変更
  1837. // WinHttpの2つのCOMの違いは上記備考参照
  1838. //2016.02.07: ver 0.9
  1839. // HTTP受信時、レスポンスヘッダにContent-Lengthが無い場合エラーになってたのを修正
  1840. //2016.02.08: ver 0.10
  1841. // ImageViewURLReplace.datの変換処理を修正
  1842. // (第4引数で、$EXTRACT={url}/$COOKIE={url}指定時、urlの$&,$n置換処理が抜けていた)
  1843. //2016.05.04: ver 0.11
  1844. // URIエンコードされたリンクで、正常に取得できないのを修正
  1845. // (ver 0.6でのエンバグで、無条件にURIエンコードするため%がさらにエンコードされる)
  1846. // 追加オプション /imgonly,/skip
  1847. // 以下のオプションも追加 (使い方のわかる人だけ自己責任で使ってください)
  1848. // (http://jane2ch.net/test/read.cgi/community/1432050479/938-939)
  1849. // /delete, /outimg:"DirPath", /rebuild (/outimg必須 genVwCache.txt再作成のみ)
  1850. // /range:$TEXTU, /res:"$LOCALDAT"[,ResNo.[,nums]], /httpsonly
  1851. // (nums: =0:ResNo and later,default 1, /httpsonly: extract URLs with "https://")
  1852. // 例: +cmd=wscript~ /res:"$LOCALDAT",$NUMBER /url:$URL /httpsonly /imgonly /skip /i
  1853. //2016.05.05: ver 0.12
  1854. // /imgonlyに大文字の拡張子(".JPG"など)も含まれるようにした
  1855. // /res時"&amp;"を"&"に変換する これ以外の文字参照が使われている場合は正常なURLにはならない
  1856. //2016.05.07: ver 0.13
  1857. // /outimgでNGFilesチェックが抜けてたのを修正
  1858. //2016.06.27: ver 0.14
  1859. // ImageViewURLReplace.datの最終防衛ラインでhttpsがhttpに置換されたものをhttpsに戻すようにした
  1860. // /range、/resでの複数URL処理中でIEウィンドウを閉じると以降の処理を中止する
  1861. // /resにAbone処理(.abn, NGxx.txt)とReplaceStr.txt処理を追加
  1862. // (各種設定ファイルを基に処理しているのでJane起動中に設定したファイルに未反映のもの
  1863. // は処理されない)
  1864. // 追加オプション /abn:no (/res指定時にAbone処理を無効化する)
  1865. // /outimgで出力imgファイル名を時刻からURLを基にした名前に変更した
  1866. // cfgファイルの組み込みを追加
  1867. // (バージョンアップの度に本スクリプトを書き換えなくても、一部の変数の値や関数の
  1868. // 差し替えなど外部ファイルでカスタマイズできるようにした)
  1869. // 【例】genVwCache.cfg
  1870. // // これはgenVwCache.wsfの外部定義ファイルです
  1871. //
  1872. // TEXT_EDITOR = "%SystemDrive%/bin/editor/newqx/newqx.exe";
  1873. //
  1874. // // out,outln: ログ出力及びIE表示 out2,outln2: IE表示のみ o:Echo表示 q:終了
  1875. // Wrap.initialize = function() {
  1876. // outln2("*** CFGファイルが組み込まれました ***\n");
  1877. // }
  1878. //
  1879. // //【WSHにPerlやRubyが組み込めるということでやってみた】
  1880. // // (使うなら<script>タグで記述を分けた方が$WScript->Echoとかも使えてベター)
  1881. // // Perlを使ってNGxx.txt,ReplaceStr.txt,ImageViewURLReplace.datの正規表現を処理する
  1882. // // PerlはActivePerl 5.20.3.2003で確認(5.22.1は動かなかった)
  1883. // // RubyはActiveScriptRuby1.8.3が必要
  1884. // // (Ruby2.3.1等にはActiveScriptRubyが含まれているがこちらでは動かなかった
  1885. // // 試したい人は、Language="RubyScript.2.3"又は"RubyScript"に変更)
  1886. // // 両方をインストールする場合は、ActiveScriptRuby1.8.3(ActiveRuby.msi)を先に、
  1887. // // Ruby2.3.1(Ruby-2.3.msi)を後にした方がトラブらないだろう
  1888. // USING_PERL = true;
  1889. // //USING_RUBY = true;
  1890. // // JS_xxx: JScript, PS_xxx: PerlScript, RS_xxx: RubyScript
  1891. // Wrap.match = PS_match;
  1892. // Wrap.test = PS_test;
  1893. // Wrap.replace = PS_replace;
  1894. //
  1895. // // range,res時もIE詳細情報表示を行う
  1896. // //detail 01:url 02:vchfilename 04:nghash 08:urlreplace 10:new header 20:old header
  1897. // Wrap.genVwCache = function(url,detail) { genVwCache(url,0x3f); }
  1898. //
  1899. // //----END-----
  1900. //2016.09.02: ver 0.15
  1901. // HTTP通信でstatus=30x(redirection)が返ってきた時は、レスポンスヘッダのLocationのURLで
  1902. // 再度取得するようにした(amazon対応 但し、画像認証には非対応)
  1903. //2016.09.15: ver 0.16
  1904. // ReplaceStr.txtが無いときエラーになっていたのを修正(ver.0.14での変数の初期化設定抜け)
  1905. // 30xリダイレクトでのWinhttpRequest5.1無限ループ回避処理を追加
  1906. // HTTP_REDIRECTION_COUNT = 3(初期値) ※合計 (WinHTTP内部でのリダイレクト回数=10)×HTTP_REDIRECTION_COUNT
  1907. // (残案件 相対アドレスのURL、metaタグでのリダイレクトへの対応)
  1908. //2016.10.19: ver 0.17
  1909. // /range,/res時、/iをつけていないと最初のURL1つしか処理されないのを修正
  1910. //2016.12.08: ver 0.18
  1911. // wscriptの代わりにcscriptで起動した場合には、/iオプションの情報表示をコンソールに出力するようにした
  1912. // HTTPアクセス用に外部プログラム:cURLを選択できるようにした
  1913. // (WSHのWinHttpのCOMではSSLの仕様が古くて取得できないものに対応するため)
  1914. // (http://jane2ch.net/test/read.cgi/community/1475970286/188,283
  1915. // https://img.barks.jp/image/review/1000078188/004.jpg
  1916. // https://nijiero-ch.com/wp-content/uploads/2016/09/nijich14748505504341260.jpg)
  1917. //2016.12.09: ver 0.19
  1918. // cscriptで起動した場合、/range,/res時、最初のURL1つしか処理されないのを修正
  1919. //2016.12.26: ver 0.20
  1920. // 受信データが "content-type: application/gzip(x-gzip)" 以外でgzip圧縮されたままの場合、
  1921. // 外部プログラム(7-Zip Extra: コマンドラインバージョン: 7za.exe)を使ってdecompressできるようにした
  1922. // (おそらくはサイト設定ミスぐらいしか無いとは思うがchromeでは正常に表示するんで一応組み込んでみた)
  1923. // ユーザ設定変数 USING_GZIPを true にすることで有効となる
  1924. // 本スクリプトのフォルダ以外に7za.exeを格納する場合は、ユーザ設定変数 GZIP_PATH に設定すること
  1925. // (7-Zip Extra: コマンドラインバージョンは、7z1604-extra.7z にて動作確認した)
  1926. // (http://jane2ch.net/test/read.cgi/community/1462621843/720)
  1927. //2016.12.27: ver 0.21
  1928. // gzip decompressに外部プログラム: 7za.exeの代わりにgzip.exeも使えるようにした
  1929. // (それにつれてver.0,20の定義変数を変更 USING_GZIP -> USING_7Z )
  1930. // 説明を本スクリプトヘッダの外部プログラムの項目に記述した
  1931. // 外部プログラム存在チェックを追加、gzip解凍に"application/x-tar-gz"も除外した
  1932. //2017.01.05: ver 0.22
  1933. // 外部定義ファイルでUSING_7Z=trueにした場合エラーになってたのを修正
  1934. // 既存のvchファイルがヌルの場合ダンマリとなってたのを修正
  1935. // /skipの条件を、vchファイルにヘッダ以外のデータがある場合に変更
  1936. // /outimgの内部処理(ファイル名リネーム)を変更
  1937. //2017.04.15: ver 0.23
  1938. // 引数エラー時、メッセージが出ないで終了していたのを修正
  1939. // CURL使用時、リクエストヘッダにReferer,Cookieが設定されないのを修正
  1940. // /outimgの内部処理(ファイル名リネーム)のファイル名ダメ文字変換処理(異常系)を追加
  1941. //
  1942. // 例のgzip圧縮されたデータが返ってくるのは、リクエストヘッダに、Accept-Encoding: gzip を追加すると
  1943. // ちゃんとデコードされてくれるんですが、今度は今まで正常だった所までもがgzip圧縮データを返してきて
  1944. // それが何故かデコードされてないんで結局ダメ
  1945. // この辺は不思議なんだが、自分に知識が無いせいで迷宮入りです
  1946. //2017.04.15: ver 0.24
  1947. // 最終防衛ラインによるhttpsをhttpに変換したものを、さらにhttpsに戻す場合
  1948. // refererを削除していたのを、こっちも削除しないでhttpに変換するようにした
  1949. //2017.10.20: ver 0.25
  1950. // cURL使用時、htmlの読み込みデータがなしになって正規表現変換できない場合があった
  1951. // (レスポンスヘッダの"Content-Type:"の抜き出しで大文字小文字の区別をしないようにした)
  1952. //2017.11.10: ver 0.26
  1953. // cfgファイルの文字コードを変更(SJIS→UTF-8)したので、全角を使ってる場合は修正して下さい
  1954. // cURL使用時は、データ圧縮可(gzip,deflate)でアクセスするようにした
  1955. // なお、WinHttpでは、自動的にgzip uncompressする機能が無いらしい
  1956. // (ver 0.23ではデコードされると言ったが、圧縮されてないだけだった)
  1957. // 以下のサイトはサーバー側の処理ミスだと思われる(備考欄に詳細を記載)
  1958. // http://www.sponichi.co.jp/entertainment/news/2017/09/08/jpeg/20170907s00041000378000p_view.jpg
  1959. // https://tokyolily.jp/upload/save_image/11071927_5a018aa30f4c5.jpg
  1960. // 一連(http://egg.5ch.net/test/read.cgi/software/1506934532/668-694)のやりとりを見て、
  1961. // キャッシュファイル名取得関数を追加(getVchFileName)
  1962. // この関数はImageViewURLReplace.datで$EXTRACT指定の場合でもHTTPアクセスはしない
  1963. // cfgファイル記述例
  1964. // Wrap.genVwCache = function(url,detail) {
  1965. // var vchFile = getVchFileName(url,detail);
  1966. // if(!fso.FileExists(vchFile)) genVwCache(url,detail);
  1967. // var exe = replaceEnv("%SystemDrive%/MassiGra/MassiGra.exe");
  1968. // shell.Run('"'+exe+'" "'+vchFile+'"');
  1969. // }
  1970. /**********************************************************/
  1971. -->
  1972. </job>
  1973. </package>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement