fork(7) download
  1. //【登録場所】全体、及びiurlrpl.txt
  2. //【ラベル】Pixivログイン設定
  3. //【コマンド】${SCRIPT:STFrw} iurlrpl/pixivimage.js $OPTION
  4. //【内容】pixivの画像を画像ビューアで表示する
  5. //【更新日時】初版:2013/02/26 更新:2013/04/27
  6. /* 導入手順
  7.   1. 本スクリプトを V2C/script/iurlrpl/ フォルダに保存する。
  8.   2. iurlrpl.txtに以下の2行を貼り付ける。もしV2Cを起動している場合はImageViewURLRplace.datの再読み込みを行うかV2Cを再起動する
  9. -----------------------------
  10. //▽pixiv.netの画像を表示
  11.   http://[^\.]+\.pixiv\.net\/(member_illust\.php|index\.php)\?mode=(medium|big)&illust_id=\d+ ${SCRIPT:STFrw} iurlrpl/pixivimage.js
  12. http://(?:www\.|touch\.)?pixiv\.net/\w+\.php\?.*illust_id=(\d+) ${SCRIPT:STFrw} iurlrpl/pixivimage.js
  13. -----------------------------
  14.   3. V2Cを起動してメニューバー→設定→外部コマンド→一般→全体に上記のコマンドを登録する
  15.   4. メニューバー→コマンド→Pixivログイン設定を実行し、ログイン情報を入力する
  16.   5. 完了
  17. */
  18.  
  19. var SwingGui = JavaImporter(Packages.javax.swing,
  20. Packages.javax.swing.event,
  21. Packages.javax.swing.GroupLayout,
  22. Packages.javax.swing.LayoutStyle,
  23. java.lang.Short,
  24. java.awt,
  25. java.awt.Dialog,
  26. java.awt.BorderLayout,
  27. java.awt.Dimension,
  28. java.awt.event
  29. );
  30. function impl_mouseListener()
  31. {
  32. this.mouseClicked = function(e) {};
  33. this.mouseEntered = function(e) {};
  34. this.mouseExited = function(e) {};
  35. this.mousePressed = function(e) {};
  36. this.mouseReleased= function(e) {
  37. if (javax.swing.SwingUtilities.isRightMouseButton(e)) {
  38. var c = e.getSource();
  39. showPopup(c, e.getX(), e.getY());
  40. e.consume();
  41. }
  42. };
  43. function showPopup(c, x, y)
  44. {
  45. with(JavaImporter(Packages.javax.swing.text.DefaultEditorKit,
  46. Packages.javax.swing.JPopupMenu, Packages.javax.swing.KeyStroke, java.awt.event.KeyEvent)) {
  47. var pmenu = new JPopupMenu();
  48. var am = c.getActionMap();
  49. addMenu(pmenu, "切り取り(X)", am.get(DefaultEditorKit.cutAction), 'X', KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK));
  50. addMenu(pmenu, "コピー(C)", am.get(DefaultEditorKit.copyAction), 'C', KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK));
  51. addMenu(pmenu, "貼り付け(V)", am.get(DefaultEditorKit.pasteAction), 'V', KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK));
  52. addMenu(pmenu, "すべて選択(A)", am.get(DefaultEditorKit.selectAllAction), 'A', KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK));
  53. pmenu.show(c, x, y);
  54. }
  55. }
  56. function addMenu(pmenu, text, action, mnemonic, ks)
  57. {
  58. if (action != null) {
  59. var mi = pmenu.add(action);
  60. if (text != null) mi.setText(text);
  61. if (mnemonic != 0) mi.setMnemonic(mnemonic);
  62. if (ks != null) mi.setAccelerator(ks);
  63. }
  64. }
  65. }
  66. // ログイン設定画面
  67. var loginPage = {
  68. confName: 'pixivimage.settings',
  69. frame: null,
  70. isInitialized : function() { return (v2c.getScriptObject())? true : false; },
  71. account : {
  72. getValue : function() {
  73. var acc = v2c.getScriptObject();
  74. if (!acc) { loginPage.init(); acc = v2c.getScriptObject(); }
  75. return acc;
  76. }
  77. },
  78. userId : {
  79. getValue : function() { return loginPage.account.getValue().userId; },
  80. setValue : function(val) {
  81. var acc = loginPage.account.getValue();
  82. acc.userId = val;
  83. v2c.setScriptObject(acc);
  84. }
  85. },
  86. passwd : {
  87. getValue : function() { return loginPage.account.getValue().passwd; },
  88. setValue : function(val) {
  89. var acc = loginPage.account.getValue();
  90. acc.passwd = val;
  91. v2c.setScriptObject(acc);
  92. }
  93. },
  94. session : {
  95. getValue : function() { return loginPage.account.getValue().session; },
  96. setValue : function(val) {
  97. var acc = loginPage.account.getValue();
  98. acc.session = val;
  99. v2c.setScriptObject(acc);
  100. }
  101. },
  102. init : function() {
  103. if (this.isInitialized()) { return; }
  104. var accObj = {};
  105. var config = v2c.getScriptSubFile(this.confName);
  106. if (!config.exists()) { v2c.writeStringToFile(config, 'dummy'); }
  107. var d = String(v2c.readStringFromFile(config));
  108. accObj.userId = d.match(/^userId=(.*?)$/m) && RegExp.$1 || '';
  109. accObj.passwd = d.match(/^passwd=(.*?)$/m) && RegExp.$1 || '';
  110. v2c.setScriptObject(accObj);
  111. },
  112. show : function() {
  113. with (SwingGui) {
  114. var dialog = new JDialog();
  115. with (dialog) {
  116. title = 'Pixivログイン設定';
  117. defaultCloseOperation = DISPOSE_ON_CLOSE;
  118. setSize(new Dimension(450, 170));
  119. setResizable(false);
  120. alwaysOnTop = true;
  121. setLocationRelativeTo(null);
  122. var l1 = new JLabel("ログインID");
  123. l1.setHorizontalAlignment(SwingConstants.TRAILING);
  124. l1.setFont(l1.getFont().deriveFont(l1.getFont().getSize() + 2.0));
  125. var l2 = new JLabel("パスワード");
  126. l2.setHorizontalAlignment(SwingConstants.TRAILING);
  127. l2.setFont(l2.getFont().deriveFont(l2.getFont().getSize() + 2.0));
  128. var userIdTextField = new JTextField();
  129. userIdTextField.setColumns(10);
  130. userIdTextField.setText(this.userId.getValue());
  131. userIdTextField.addMouseListener(new MouseListener(new impl_mouseListener()));
  132. var passwdTextField = new JTextField();
  133. passwdTextField.setColumns(10);
  134. passwdTextField.setText(this.passwd.getValue());
  135. passwdTextField.addMouseListener(new MouseListener(new impl_mouseListener()));
  136. var bOK = new JButton("OK");
  137. with (bOK) {
  138. addActionListener(function(e) {
  139. loginPage.userId.setValue(String(userIdTextField.getText() || ''));
  140. loginPage.passwd.setValue(String(passwdTextField.getText() || ''));
  141. var sb = new java.lang.StringBuilder();
  142. sb.append('userId=' + loginPage.userId.getValue() + '\n');
  143. sb.append('passwd=' + loginPage.passwd.getValue() + '\n');
  144. v2c.writeStringToFile(v2c.getScriptSubFile(loginPage.confName), sb.toString());
  145. logout();
  146. dialog.dispose();
  147. });
  148. }
  149. var bCancel = new JButton("キャンセル");
  150. with (bCancel) {
  151. addActionListener(function(e) {
  152. dialog.dispose();
  153. });
  154. }
  155. var gl = new GroupLayout(getContentPane());
  156. gl.setHorizontalGroup(
  157. gl.createParallelGroup(GroupLayout.Alignment.LEADING)
  158. .addGroup(gl.createSequentialGroup()
  159. .addContainerGap()
  160. .addGroup(gl.createParallelGroup(GroupLayout.Alignment.LEADING)
  161. .addGroup(GroupLayout.Alignment.TRAILING, gl.createSequentialGroup()
  162. .addComponent(bOK, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
  163. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  164. .addComponent(bCancel, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
  165. .addGroup(gl.createSequentialGroup()
  166. .addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
  167. .addComponent(l2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  168. .addComponent(l1, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
  169. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  170. .addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
  171. .addComponent(passwdTextField, GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
  172. .addComponent(userIdTextField, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE))))
  173. .addContainerGap())
  174. );
  175. gl.setVerticalGroup(
  176. gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
  177. .addGroup(gl.createSequentialGroup()
  178. .addGap(21)
  179. .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
  180. .addComponent(l1, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
  181. .addComponent(userIdTextField, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
  182. .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  183. .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
  184. .addComponent(passwdTextField, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
  185. .addComponent(l2, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
  186. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
  187. .addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
  188. .addComponent(bOK, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
  189. .addComponent(bCancel, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
  190. .addContainerGap())
  191. );
  192. setLayout(gl);
  193. }
  194. dialog.show();
  195. }
  196. }
  197. };
  198. if (v2c.context && v2c.context.argLine.indexOf('$OPTION') >= 0) {
  199. loginPage.init();
  200. loginPage.show();
  201. }
  202.  
  203. function logout()
  204. {
  205. var old = loginPage.session.getValue();
  206. if (old) {
  207. var u = new java.net.URL('http://w...content-available-to-author-only...v.net/logout.php');
  208. var req = v2c.createHttpRequest(u);
  209. req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  210. req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
  211. req.setRequestProperty("Connection", "keep-alive");
  212. req.setRequestProperty("Host", u.getHost());
  213. req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
  214. req.setRequestProperty("Cookie", "PHPSESSID=" + old.sessId + "; login_ever=yes");
  215. req.getContentsAsBytes();
  216. }
  217. loginPage.session.setValue(null);
  218. }
  219.  
  220. function getPHPSESSID()
  221. {
  222. var old = loginPage.session.getValue();
  223. if (old) {
  224. var now = (new Date()).getTime();
  225. if ((old.expires - (1000 * 3600 - 300)) <= now && now < old.expires) {
  226. return old.sessId;
  227. }
  228. logout();
  229. }
  230. var u = new java.net.URL('http://w...content-available-to-author-only...v.net/login.php');
  231. var param = 'mode=login&pixiv_id=' + loginPage.userId.getValue() + '&pass=' + loginPage.passwd.getValue();
  232. var req = v2c.createHttpRequest(u, param);
  233. req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  234. req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
  235. req.setRequestProperty("Connection", "keep-alive");
  236. req.setRequestProperty("Host", u.getHost());
  237. req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
  238. req.setRequestProperty("Content-Length", param.length - 1);
  239. req.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  240. req.getContentsAsBytes();
  241.  
  242. var ret = '';
  243. if (req.getResponseCode() == 200 || req.getResponseCode() == 302) {
  244. ret = (String(req.getResponseHeader('Set-Cookie')).match(/PHPSESSID=([a-f0-9_]+)/i))? RegExp.$1 : '';
  245. }
  246. loginPage.session.setValue({sessId: ret, expires: (new Date()).getTime() + (1000 * 3600 - 300)});
  247.  
  248. return ret;
  249. }
  250.  
  251. function checkURL(u, cx) {
  252. loginPage.init();
  253. cx.applyImageViewURLReplace = true;
  254. if (loginPage.userId.getValue() == '' || loginPage.passwd.getValue() == '') {
  255. return u;
  256. }
  257. var phpsessid = getPHPSESSID();
  258. if (!phpsessid) { v2c.println('[pixivimage.js] ログインできませんでした。'); return u; }
  259. var illust_id = (String(u).match(/illust_id=(\d+)/i))? RegExp.$1 : '';
  260. if (!illust_id) { v2c.println('[pixivimage.js] illust_idがURL文字列に含まれていません。'); return u; }
  261. var umid = 'http://w...content-available-to-author-only...v.net/member_illust.php?mode=medium&illust_id=' + illust_id;
  262. var ubig = 'http://w...content-available-to-author-only...v.net/member_illust.php?mode=big&illust_id=' + illust_id;
  263. var req = v2c.createHttpRequest(new java.net.URL(umid));
  264. req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  265. req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
  266. req.setRequestProperty("Accept-Encoding", "gzip, deflate");
  267. req.setRequestProperty("Connection", "keep-alive");
  268. req.setRequestProperty("Host", u.getHost());
  269. req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
  270. req.setRequestProperty("Cookie", "PHPSESSID=" + phpsessid + "; login_ever=yes");
  271. var s1 = String(req.getContentsAsString());
  272. v2c.println(ubig);
  273. if (!s1) { v2c.println('[pixivimage.js] mode=middleのページが開けませんでした。サーバー落ちたか、未対応のURLかもしれません'); return u; }
  274. var manga = '';
  275. if (manga = /works_display"><a href="member_illust\.php\?mode=manga\&amp;illust_id=([^\"]+)/i.exec(s1)) {
  276. ubig = 'http://' + u.getHost() + '/member_illust.php?mode=manga_big&illust_id=' + manga[1] + '&page=0';
  277. }
  278. var req = v2c.createHttpRequest(new java.net.URL(ubig));
  279. req.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  280. req.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
  281. req.setRequestProperty("Accept-Encoding", "gzip, deflate");
  282. req.setRequestProperty("Connection", "keep-alive");
  283. req.setRequestProperty("Host", u.getHost());
  284. req.setRequestProperty("Referer", umid);
  285. req.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
  286. req.setRequestProperty("Cookie", "PHPSESSID=" + phpsessid + "; login_ever=yes");
  287. var s1 = String(req.getContentsAsString());
  288. if (!s1) { v2c.println('[pixivimage.js] mode=bigあるいはmode=manga_bigのページが開けませんでした。未対応のURLかもしれません'); return u; }
  289. var imgurl = '';
  290. if (imgurl = /<img src="([^\"]+)" onclick="\(window.open/i.exec(s1)) {
  291. imgurl = imgurl[1];
  292. }
  293. if (!imgurl) { v2c.println('[pixivimage.js] 画像URLが取得できませんでした。PixivのHTMLの内容が変わり正規表現がマッチしなくなったのかもしれません。'); return u; }
  294. cx.applyImageViewURLReplace = false;
  295. cx.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  296. cx.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
  297. cx.setRequestProperty("Accept-Encoding", "gzip, deflate");
  298. cx.setRequestProperty("Connection", "keep-alive");
  299. cx.setRequestProperty("Host", u.getHost());
  300. cx.setRequestProperty("Referer", umid);
  301. cx.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
  302. cx.setRequestProperty("Cookie", "PHPSESSID=" + phpsessid + "; login_ever=yes");
  303. return new java.net.URL(imgurl);
  304. }
  305.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty