由於內建了 WYSIWYG 的 HTML editor,Wordpress 2.0.* 的 posting bookmarklet 也可以直接以 WYSIWYG 的形式編輯文章了 (之前的 WYSIWYG 靠的是 plug-in,posting bookmarklet 沒有 plug 到)。

但是,官方的 posting bookmarklet 會取代掉目前的網頁,這樣在編輯文章時很麻煩,沒辦法回來參照原文編寫。所以只好下手改改這個 posting bookmarklet。基本上關鍵在這裡 (其中,Q 是目前被選取的文字,如果有的話):

location.href
	= 'http://www.jeffhung.idv.tw/blog/wp-admin/post.php?text='
	+ encodeURIComponent(Q)
	+ '&popupurl='
	+ encodeURIComponent(location.href)
	+ '&popuptitle='
	+ encodeURIComponent(document.title);

因為是更改 location.href 來啟動 blog 編輯,所以目前頁面會被替換掉,換成 window.open() 開新視窗,應該就可以了。所以我把這段改成這樣:

window.open(
	'http://www.jeffhung.idv.tw/blog/wp-admin/post.php?text='
	+ encodeURIComponent(Q)
	+ '&popupurl='
	+ encodeURIComponent(location.href)
	+ '&popuptitle='
	+ encodeURIComponent(document.title)
);

卻沒想到,雖然新的 blog 編輯視窗有正確出現了,但原來的頁面卻被切換成這樣:

[object Window]

研究了網路上其他的 bookmarklet 的寫法,才恍然大悟,如果 bookmarklet 的最後一個 statement 有「值」的話,browser (firefox) 就會把這個值顯示在頁面上。所以在最後加一個 void(null); 就可以了。最後的 wordpress posting bookmarklet 完整如下:

javascript:
if (navigator.userAgent.indexOf('Safari') >= 0) {
	Q = getSelection();
}
else {
	Q = document.selection
	  ? document.selection.createRange().text
	  : document.getSelection();
}
window.open(
	'http://www.jeffhung.idv.tw/blog/wp-admin/post.php?text='
	+ encodeURIComponent(Q)
	+ '&popupurl='
	+ encodeURIComponent(location.href)
	+ '&popuptitle='
	+ encodeURIComponent(document.title)
);
void(null);

縮成一行後如下 (為顯示美觀,以略做折行,請自行連接成一行),把裡面的 blog 網址改一改,複製製成 bookmark 即可使用:

javascript:if(navigator.userAgent.indexOf('Safari')>=0){Q=g
etSelection();}else{Q=document.selection?document.selection
.createRange().text:document.getSelection();}window.open('h
ttp://www.jeffhung.idv.tw/blog/wp-admin/post.php?text='+enc
odeURIComponent(Q)+'&popupurl='+encodeURIComponent(location
.href)+'&popuptitle='+encodeURIComponent(document.title));v
oid(null);

不過,最後還是有個缺陷,似乎是 Tab Mix Plus 的關係,跳出來的新視窗不會取得焦點 (focus),所以得手動切換把 blog 編輯視窗找回來才行。