form F1のtextarea T1のカーソル位置に時間を埋め込む(FF専用)

練習用に作った。まだアクティブな(もしくはフォーカスのある)テキストエリアを取得する方法がわからない。

javascript:(function(){dt=new Date();d=document.F1.T1;n=d.selectionStart;v=d.value;t=d.scrollTop;d.value=(v.substr(0,n)+(s=dt.getFullYear()+"/"+dt.getMonth()+"/"+dt.getDate())+v.substr(n,v.length));d.scrollTop=t;d.setSelectionRange(n+s.length,n+s.length)})()

Firefoxでは、

カーソル位置取得*1
document.(form).(textarea).selectionStart
カーソル位置設定*2
document.(form).(textarea).setSelectionRange(start,end)
スクロールバーの位置取得/設定
document.(form).(textarea).scrollTop

スクロールバーの位置を設定しないと最初に戻る。

参考URL
http://karetta.jp/article/blog/oneline/009098

追記:ちょっと短くした

javascript:(function(){n=(t=document.F1.T1).selectionStart;v=t.value;s=t.scrollTop;t.value=(v.substr(0,n)+(f=[(d=new Date()).getFullYear(),d.getMonth(),d.getDate()].join("/"))+v.substr(n,v.length));t.scrollTop=s;t.setSelectionRange((p=n+f.length),p)})()

javascriptはwithとかブロックが値を持たないのかもしれない。

js> a={}
[object Object]
js> a={b=1;c=1}
typein:2: SyntaxError: missing : after property id:
typein:2: a={b=1;c=1}
typein:2: ....^
js> a=with(new Date()){}
typein:3: SyntaxError: syntax error:
typein:3: a=with(new Date()){}
typein:3: ..^

まだなれないな。

*1:正確にはselectionの開始位置

*2:正確にはselectionの設定