Greasemonkey xhr redirection in Firefox 3
Tuesday, April 29, 2008
I found that my rssget script is not working in Firefox 3 beta for some of the link. After some investigation, the cause seems to be the difference in redirection handling. In Firefox 2, when GM_xmlhttpRequest() is fired, it would follow status like 302 to do the redirection to return the correct page response to the onload function. However, in Firefox 3, the onload would receive a status like 302 and thus the script would fail.
I don’t know whether it is the responsibility for the browser or the script to handle redirection like this. I have changed the script itself to follow the redirection. The code is like:
- GM_xmlhttprequest({
- method:"GET",
- url: url,
- onload: function(response){
- if(response.status == 301 || response.status == 302 || response.status == 303){
- var loc = /Location: ([^\n]*)\n/.exec(response.responseHeaders)[1];
- GM_xmlhttprequest({
- method:"GET",
- url:loc,
- onload:arguments.callee
- });
- return;
- }
- //go on with normal parsing...
- }
- })
I’ve only included status 301 to 303 for the time being. Then it will try to get the ‘Location’ from its header and finally invoke another GM_xmlhttpRequest(). A little trick here is to use arguments.callee to recur itself.
The updated script is tagged as 1.5 in the code site . You will only need it if your script fail in Firefox 3.
蘋果動新聞 RSS 加取全文油猴更新
Wednesday, February 20, 2008
蘋果日報最近推出了 動新聞 不過又沒有 RSS,所以特地用 Dapper 打造了其首頁連結的 RSS ,大家可以拿來用。
美中不足的是只有標題連結,沒有內文,所以我更新了 取全文油猴腳本 ,可以照辦煮碗按 ‘G’ 取全文,大家可以點選安裝: Google Reader 版 、 Bloglines 版 、 Bloglines Beta 版 。
用 Dapp 製作 RSS Feed
Wednesday, January 17, 2007
最近幫朋友用 Dapper 製作了一個 MySinaBlog 的 Comment RSS Feed,製法簡單,在此公諸同好。雖然簡單,但要說明還是很複雜,所以錄了個 Screencast (首個!),以自己的舊 MySinaBlog 為例子。不過做得很簡陋,沒有什麼解說,而且上了 Youtube 後更是「矇查查」,敬請見諒:
背後原理我不詳細解釋了,只說說所需步驟吧!
先要條件: 在你的 MySinaBlog 的 Sidebar 裏開啟「最近留言」
步驟:
(一) 製作你的 Comment Dapp
- 點「Create a Dapp」
- 輸入網址 (例: http://jackysee.mysinablog.com)
- 進入 Dapp 的 virtual browser 後,按「Add to Basket」,然後按「Finish」
- Dapp 會分析你的網址,完了後請按「Go Play」
- 待三版的頁面都載入完畢,按右邊的「Proceed to next step」
- 按「Get started!」
- 在右下框格拖到頁底,找到「最近留言」後,點選留言者的名字,會在右邊欄的 Field Element 出現,按「Save and Continue」
- 輸入欄名字 (commenter)
- 點「Create another field」
- 照辦煮碗找「最近留言」,這次點留言內容,然後也是右邊的「Save and Continue」
- 輸入欄名字 (comment content)
- 可點「Preview Output」看看所抓取的資料是否正確
- 點「Create a Group」
- 在右邊欄以 ctrl-click 選擇全部欄位 (Commenter 和 Comment Content),點「Create group from selected fields」
- 輸入 group 名字 (comment)
- 點「Save your Dapp」,然後輸入 Dapp 的資料 (name, description, tag),再點「Save your Dapp」。你的 Comment Dapp 就已完成了!
(二) 製作 RSS
- 在 Dapp 頁面點選 RSS
- Item title 選 Comment content
- Item Description 複選 commenter, comment content
- Item link 選 comment content@href
- 按「Generate URL」
- 嘗試開啟該 URL,如在 Firefox 裏就會看到該 RSS 的樣子了!如果不滿意的話可以再自行調較參數。
必需留意的是,如果你沒有登入,這個 Dapp 會在 24 小時後變成 public 給其他人使用,而不可以再作修改。因此,請登記並登入你的 Dapp 戶口,Claim 你剛做好的 Dapp,選「save it to your sandbox」就可以變成私人用的 Dapp 了。
如果大家有心再研究的話,就會發現 Dapp 還有很多不同的功能,可以幫助你在不同的網頁抓取不同的資料,並以各種不同的專有格式發放,用途可以很廣泛。有興趣的話,可以看看官網的 Screencast 介紹。






