KeepassWand補助スクリプト改良版

ちょっとだけよ

先日、Sleipnir×KeePass民歓喜なスクリプトが公開されたよにて公開したスクリプトの改良版です。

変更点としては…

  1. 誤爆が多かった処理の部分を削除した。
  2. UAスクリプトを実行した際に、KeePassが起動していないとKeePassを立ち上げます。

当然、UAスクリプト版のKeePassWandが使えることが前提です。
ちなみに2011-10-25にv005test1が出ています。

KeepassWandAux.js

(function(){

var keepath = "\"C:\\Program Files (x86)\\KeePass Password Safe 2\\KeePass.exe\"";

var shell = sleipnir.CreateObject("wscript.shell");

if(isProcessExists("KeePass.exe")) {
	var act = "", f;
	if(document.activeElement.id) {
		act = "i:" + document.activeElement.id
	}else if(document.activeElement.name) {
		act = "n:" + document.activeElement.name
	}
	if(act.match(/^i:/) != null) {
		f = document.getElementById(act.substring(2, act.length));
		f.style.background = "#ffc";
		f.style.imeMode = "disabled";
		f.focus();
	}else if(act.match(/^n:/) != null) {
		f = document.getElementsByName(act.substring(2, act.length))[0];
		f.style.background = "#ffc";
		f.style.imeMode = "disabled";
		f.focus();
	}
	sleipnir.api.ExecuteAction("KeepassWand");
}else {
	shell.run(keepath);
}

function isProcessExists(name) {
	var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
	var colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" + name + "'");
	return colProcessList.Count != 0;
}

})();

前回の時のようにさえ(仮称)使う必要は無いです……というか前回のも一文書くだけでさえ(仮称)は不要だったわけですがw*1
先頭の方の「var keepath = "\"C:\\Program Files (x86)\\KeePass Password Safe 2\\KeePass.exe\"";」の赤字部分を自分のKeePassの実行ファイルパスにしてください。*2
kdbxファイルがKeePassに関連付けられてる場合はkdbxファイルのパスを指定してもおkみたいです。

指定したプロセスを監視、そのプロセスの起動後、終了後に指定した動作を実行 | Windows XP/Vista/7の裏技を参考にしました。


あとは、たまにinputタグ間を上手く移動しないサイトがあるので可能ならその辺をどうにかしたい。
テキストにサイトURIを記述して場合分けぐらいしかないだろうけどね。

*1:理由はただ何となくw

*2:フォルダ区切りは"\\"とエスケープしなければいけません