べるべる研究日誌

なんでもやる系エンジニアの日々

kawaraban用bookmarklet改良版

とりあえずいろいろ問題が出ていたので調べたらいろいろ判明。今の方式だとタグにするには"と'をすでに使っているのでうまくいかないという事が判明。あとこのままでは変数が汚染する可能性有り。ということでcreateElementを使ってちゃんと書き直した。たぶん、これで他のブラウザーでもちゃんと動くハズ。

javascript:(function(){if(msg=prompt('Kawara')){f=document.createElement('form');f.setAttribute('name','KawaraPostForm');f.setAttribute('action','http://k.osx.cc/create');f.setAttribute('accept-charset','UTF-8');f.setAttribute('method','POST');s=document.createElement('input');s.setAttribute('name','comment');s.setAttribute('value',msg);s.setAttribute('type','hidden');f.appendChild(s);c=document.createElement('input');c.setAttribute('name','content');c.setAttribute('value',decodeURIComponent(location.href));c.setAttribute('type','hidden');f.appendChild(c);document.body.appendChild(f);document.KawaraPostForm.submit();};})();

これなら以下のようなHTMLを入れれば簡単に登録できます。

<a href="javascript:(function(){if(msg=prompt('Kawara')){f=document.createElement('form');f.setAttribute('name','KawaraPostForm');f.setAttribute('action','http://k.osx.cc/create');f.setAttribute('accept-charset','UTF-8');f.setAttribute('method','POST');s=document.createElement('input');s.setAttribute('name','comment');s.setAttribute('value',msg);s.setAttribute('type','hidden');f.appendChild(s);c=document.createElement('input');c.setAttribute('name','content');c.setAttribute('value',decodeURIComponent(location.href));c.setAttribute('type','hidden');f.appendChild(c);document.body.appendChild(f);document.KawaraPostForm.submit();};})();">Kawaraに登録</a>	

ということで、再度登録お願いします。