function checkURL(u, cx) {
var hr = createPresetRequest(u);
var s1 = hr.getContentsAsString();
if (s1) {
// MIMEタイプが画像以外の場合はスクリプトで処理しない
if (!s1.match('<b>MIME</b></span><span class="right">image/(jpeg|png|bmp|gif|vnd\\.wap\\.wbmp)</span>')) {
v2c.browseURLDefExt(u);
cx.applyImageViewURLReplace = false;
return '';
}
// パスワードが何も入力されてないときポップアップ表示で入力させる
var matches = '';
if (matches = /キーワード: <input size="20" type="text" name="keyword" value="([^"]+)?">/i.exec(s1)) {
var pass = '';
if (matches.length > 1 && typeof(matches[1]) != 'undefined' && matches[1] !== '') {
pass = matches[1];
} else {
pass = v2c.prompt('画像表示 ('+ u +')\nこの画像にはパスワードが設定されています。\n2分以内にパスワードを入力して下さい。', '');
}
}
var sid = s1.match('<input type="hidden" name="sid" value="(\\d+)">')[1];
var dqn = s1.match('<input type="hidden" name="dqn" value="(\\d+)">')[1];
var param = 'sid=' + sid + '&dqn=' + dqn;
if (pass) { param += '&keyword=' + pass; }
param += '&origfilename=1&attachement=1';
var cookie = cookieGen(hr.getResponseHeader('Set-Cookie'));
var u2 = new java.net.URL('http://' + u.getHost().toString() + '/uploader/dl.pl');
hr = createPresetRequest(u2, param);
hr.setRequestProperty("Host", u.getHost());
hr.setRequestProperty("Referer", u);
hr.setRequestProperty("Content-Length", java.lang.Integer.valueOf(param.length - 1));
hr.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
hr.setRequestProperty("Cookie", cookie);
s1 = hr.getContentsAsString();
if (s1 && s1.match('<a href="\\./(link\\.pl?[^"]+)">')) {
u2 = new java.net.URL('http://' + u2.getHost() + '/uploader/' + RegExp.$1);
cookie = cookieGen(hr.getResponseHeader('Set-Cookie'));
hr = createPresetRequest(u2);
hr.setRequestProperty("Host", u2.getHost());
hr.setRequestProperty("Cookie", cookie);
s1 = hr.getContentsAsString();
if (s1 && s1.match('<meta http-equiv="refresh" CONTENT="3; URL=([^"]+)')) {
u = RegExp.$1;
cx.applyImageViewURLReplace = false;
cx.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
cx.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
cx.setRequestProperty("Accept-Encoding", "gzip, deflate");
cx.setRequestProperty("Connection", "keep-alive");
cx.setRequestProperty("Host", u2.getHost());
cx.setRequestProperty("Referer", u2);
cx.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
cx.setRequestProperty('Cookie', cookie);
}
}
}
return u;
}
function createPresetRequest(u)
{
var hr;
if (arguments.length > 1) { hr = v2c.createHttpRequest(u, arguments[1]); }
else { hr = v2c.createHttpRequest(u); }
hr.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
hr.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
hr.setRequestProperty("Accept-Encoding", "gzip, deflate");
hr.setRequestProperty("Connection", "keep-alive");
hr.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
return hr;
}
function cookieGen(c)
{
var ret = '';
ret = (c.match('(u_ses=\\d+;)'))? RegExp.$1 : '';
ret += (c.match('(dl_n=\\d+;)'))? ' '+ RegExp.$1 : '';
return ret;
}