//【登録場所】全体、及びiurlrpl.txt
//【ラベル】Pixivログイン設定
//【コマンド】${SCRIPT:STFrw} iurlrpl/pixivimage.js $OPTION
//【内容】pixivの画像を画像ビューアで表示する
//【更新日時】初版:2013/02/26 更新:2013/04/27
/* 導入手順
1. 本スクリプトを V2C/script/iurlrpl/ フォルダに保存する。
2. iurlrpl.txtに以下の2行を貼り付ける。もしV2Cを起動している場合はImageViewURLRplace.datの再読み込みを行うかV2Cを再起動する
-----------------------------
//▽pixiv.netの画像を表示
http://[^\.]+\.pixiv\.net\/(member_illust\.php|index\.php)\?mode=(medium|big)&illust_id=\d+ ${SCRIPT:STFrw} iurlrpl/pixivimage.js
http://(?:www\.|touch\.)?pixiv\.net/\w+\.php\?.*illust_id=(\d+) ${SCRIPT:STFrw} iurlrpl/pixivimage.js
-----------------------------
3. V2Cを起動してメニューバー→設定→外部コマンド→一般→全体に上記のコマンドを登録する
4. メニューバー→コマンド→Pixivログイン設定を実行し、ログイン情報を入力する
5. 完了
*/
var SwingGui = JavaImporter(Packages.javax.swing,
Packages.javax.swing.event,
Packages.javax.swing.GroupLayout,
Packages.javax.swing.LayoutStyle,
java.lang.Short,
java.awt,
java.awt.Dialog,
java.awt.BorderLayout,
java.awt.Dimension,
java.awt.event
);
function impl_mouseListener()
{
this.mouseClicked = function(e) {};
this.mouseEntered = function(e) {};
this.mouseExited = function(e) {};
this.mousePressed = function(e) {};
this.mouseReleased= function(e) {
if (javax.swing.SwingUtilities.isRightMouseButton(e)) {
var c = e.getSource();
showPopup(c, e.getX(), e.getY());
e.consume();
}
};
function showPopup(c, x, y)
{
with(JavaImporter(Packages.javax.swing.text.DefaultEditorKit,
Packages.javax.swing.JPopupMenu, Packages.javax.swing.KeyStroke, java.awt.event.KeyEvent)) {
var pmenu = new JPopupMenu();
var am = c.getActionMap();
addMenu(pmenu, "切り取り(X)", am.get(DefaultEditorKit.cutAction), 'X', KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK));
addMenu(pmenu, "コピー(C)", am.get(DefaultEditorKit.copyAction), 'C', KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK));
addMenu(pmenu, "貼り付け(V)", am.get(DefaultEditorKit.pasteAction), 'V', KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK));
addMenu(pmenu, "すべて選択(A)", am.get(DefaultEditorKit.selectAllAction), 'A', KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK));
pmenu.show(c, x, y);
}
}
function addMenu(pmenu, text, action, mnemonic, ks)
{
if (action != null) {
var mi = pmenu.add(action);
if (text != null) mi.setText(text);
if (mnemonic != 0) mi.setMnemonic(mnemonic);
if (ks != null) mi.setAccelerator(ks);
}
}
}
// ログイン設定画面
var loginPage = {
confName: 'pixivimage.settings',
frame: null,
isInitialized : function() { return (v2c.getScriptObject())? true : false; },
account : {
getValue : function() {
var acc = v2c.getScriptObject();
if (!acc) { loginPage.init(); acc = v2c.getScriptObject(); }
return acc;
}
},
userId : {
getValue : function() { return loginPage.account.getValue().userId; },
setValue : function(val) {
var acc = loginPage.account.getValue();
acc.userId = val;
v2c.setScriptObject(acc);
}
},
passwd : {
getValue : function() { return loginPage.account.getValue().passwd; },
setValue : function(val) {
var acc = loginPage.account.getValue();
acc.passwd = val;
v2c.setScriptObject(acc);
}
},
session : {
getValue : function() { return loginPage.account.getValue().session; },
setValue : function(val) {
var acc = loginPage.account.getValue();
acc.session = val;
v2c.setScriptObject(acc);
}
},
init : function() {
if (this.isInitialized()) { return; }
var accObj = {};
var config = v2c.getScriptSubFile(this.confName);
if (!config.exists()) { v2c.writeStringToFile(config, 'dummy'); }
var d = String(v2c.readStringFromFile(config));
accObj.userId = d.match(/^userId=(.*?)$/m) && RegExp.$1 || '';
accObj.passwd = d.match(/^passwd=(.*?)$/m) && RegExp.$1 || '';
v2c.setScriptObject(accObj);
},
show : function() {
with (SwingGui) {
var dialog = new JDialog();
with (dialog) {
title = 'Pixivログイン設定';
defaultCloseOperation = DISPOSE_ON_CLOSE;
setSize(new Dimension(450, 170));
setResizable(false);
alwaysOnTop = true;
setLocationRelativeTo(null);
var l1 = new JLabel("ログインID");
l1.setHorizontalAlignment(SwingConstants.TRAILING);
l1.setFont(l1.getFont().deriveFont(l1.getFont().getSize() + 2.0));
var l2 = new JLabel("パスワード");
l2.setHorizontalAlignment(SwingConstants.TRAILING);
l2.setFont(l2.getFont().deriveFont(l2.getFont().getSize() + 2.0));
var userIdTextField = new JTextField();
userIdTextField.setColumns(10);
userIdTextField.setText(this.userId.getValue());
userIdTextField.addMouseListener(new MouseListener(new impl_mouseListener()));
var passwdTextField = new JTextField();
passwdTextField.setColumns(10);
passwdTextField.setText(this.passwd.getValue());
passwdTextField.addMouseListener(new MouseListener(new impl_mouseListener()));
var bOK = new JButton("OK");
with (bOK) {
addActionListener(function(e) {
loginPage.userId.setValue(String(userIdTextField.getText() || ''));
loginPage.passwd.setValue(String(passwdTextField.getText() || ''));
var sb = new java.lang.StringBuilder();
sb.append('userId=' + loginPage.userId.getValue() + '\n');
sb.append('passwd=' + loginPage.passwd.getValue() + '\n');
v2c.writeStringToFile(v2c.getScriptSubFile(loginPage.confName), sb.toString());
logout();
dialog.dispose();
});
}
var bCancel = new JButton("キャンセル");
with (bCancel) {
addActionListener(function(e) {
dialog.dispose();
});
}
var gl = new GroupLayout(getContentPane());
gl.setHorizontalGroup(
gl.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(gl.createSequentialGroup()
.addContainerGap()
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING, gl.createSequentialGroup()
.addComponent(bOK, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bCancel, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
.addGroup(gl.createSequentialGroup()
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
.addComponent(l2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(l1, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(passwdTextField, GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
.addComponent(userIdTextField, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE))))
.addContainerGap())
);
gl.setVerticalGroup(
gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addGroup(gl.createSequentialGroup()
.addGap(21)
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(l1, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
.addComponent(userIdTextField, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(passwdTextField, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
.addComponent(l2, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(bOK, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(bCancel, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
setLayout(gl);
}
dialog.show();
}
}
};
if (v2c.context && v2c.context.argLine.indexOf('$OPTION') >= 0) {
loginPage.init();
loginPage.show();
}
function logout()
{
var old = loginPage.session.getValue();
if (old) {
var u = new java.net.URL('http://w...content-available-to-author-only...v.net/logout.php');
var req = v2c.createHttpRequest(u);
req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
req.setRequestProperty("Connection", "keep-alive");
req.setRequestProperty("Host", u.getHost());
req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
req.setRequestProperty("Cookie", "PHPSESSID=" + old.sessId + "; login_ever=yes");
req.getContentsAsBytes();
}
loginPage.session.setValue(null);
}
function getPHPSESSID()
{
var old = loginPage.session.getValue();
if (old) {
var now = (new Date()).getTime();
if ((old.expires - (1000 * 3600 - 300)) <= now && now < old.expires) {
return old.sessId;
}
logout();
}
var u = new java.net.URL('http://w...content-available-to-author-only...v.net/login.php');
var param = 'mode=login&pixiv_id=' + loginPage.userId.getValue() + '&pass=' + loginPage.passwd.getValue();
var req = v2c.createHttpRequest(u, param);
req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
req.setRequestProperty("Connection", "keep-alive");
req.setRequestProperty("Host", u.getHost());
req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
req.setRequestProperty("Content-Length", param.length - 1);
req.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
req.getContentsAsBytes();
var ret = '';
if (req.getResponseCode() == 200 || req.getResponseCode() == 302) {
ret = (String(req.getResponseHeader('Set-Cookie')).match(/PHPSESSID=([a-f0-9_]+)/i))? RegExp.$1 : '';
}
loginPage.session.setValue({sessId: ret, expires: (new Date()).getTime() + (1000 * 3600 - 300)});
return ret;
}
function checkURL(u, cx) {
loginPage.init();
cx.applyImageViewURLReplace = true;
if (loginPage.userId.getValue() == '' || loginPage.passwd.getValue() == '') {
return u;
}
var phpsessid = getPHPSESSID();
if (!phpsessid) { v2c.println('[pixivimage.js] ログインできませんでした。'); return u; }
var illust_id = (String(u).match(/illust_id=(\d+)/i))? RegExp.$1 : '';
if (!illust_id) { v2c.println('[pixivimage.js] illust_idがURL文字列に含まれていません。'); return u; }
var umid = 'http://w...content-available-to-author-only...v.net/member_illust.php?mode=medium&illust_id=' + illust_id;
var ubig = 'http://w...content-available-to-author-only...v.net/member_illust.php?mode=big&illust_id=' + illust_id;
var req = v2c.createHttpRequest(new java.net.URL(umid));
req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
req.setRequestProperty("Accept-Encoding", "gzip, deflate");
req.setRequestProperty("Connection", "keep-alive");
req.setRequestProperty("Host", u.getHost());
req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
req.setRequestProperty("Cookie", "PHPSESSID=" + phpsessid + "; login_ever=yes");
var s1 = String(req.getContentsAsString());
v2c.println(ubig);
if (!s1) { v2c.println('[pixivimage.js] mode=middleのページが開けませんでした。サーバー落ちたか、未対応のURLかもしれません'); return u; }
var manga = '';
if (manga = /works_display"><a href="member_illust\.php\?mode=manga\&illust_id=([^\"]+)/i.exec(s1)) {
ubig = 'http://' + u.getHost() + '/member_illust.php?mode=manga_big&illust_id=' + manga[1] + '&page=0';
}
var req = v2c.createHttpRequest(new java.net.URL(ubig));
req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
req.setRequestProperty("Accept-Encoding", "gzip, deflate");
req.setRequestProperty("Connection", "keep-alive");
req.setRequestProperty("Host", u.getHost());
req.setRequestProperty("Referer", umid);
req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
req.setRequestProperty("Cookie", "PHPSESSID=" + phpsessid + "; login_ever=yes");
var s1 = String(req.getContentsAsString());
if (!s1) { v2c.println('[pixivimage.js] mode=bigあるいはmode=manga_bigのページが開けませんでした。未対応のURLかもしれません'); return u; }
var imgurl = '';
if (imgurl = /<img src="([^\"]+)" onclick="\(window.open/i.exec(s1)) {
imgurl = imgurl[1];
}
if (!imgurl) { v2c.println('[pixivimage.js] 画像URLが取得できませんでした。PixivのHTMLの内容が変わり正規表現がマッチしなくなったのかもしれません。'); return u; }
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", u.getHost());
cx.setRequestProperty("Referer", umid);
cx.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
cx.setRequestProperty("Cookie", "PHPSESSID=" + phpsessid + "; login_ever=yes");
return new java.net.URL(imgurl);
}