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:

JavaScript:
  1. GM_xmlhttprequest({
  2.     method:"GET",
  3.     url: url,
  4.     onload: function(response){
  5.         if(response.status == 301 || response.status == 302 || response.status == 303){
  6.             var loc = /Location: ([^\n]*)\n/.exec(response.responseHeaders)[1];
  7.             GM_xmlhttprequest({
  8.                 method:"GET",
  9.                 url:loc,
  10.                 onload:arguments.callee
  11.             });
  12.             return;
  13.         }
  14.         //go on with normal parsing...
  15.     }
  16.  })

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 版

無底深潭

Saturday, April 14, 2007

五天,究竟有多深?

Google Reader List

用 Dapp 製作 RSS Feed

Wednesday, January 17, 2007

最近幫朋友用 Dapper 製作了一個 MySinaBlog 的 Comment RSS Feed,製法簡單,在此公諸同好。雖然簡單,但要說明還是很複雜,所以錄了個 Screencast (首個!),以自己的舊 MySinaBlog 為例子。不過做得很簡陋,沒有什麼解說,而且上了 Youtube 後更是「矇查查」,敬請見諒:

背後原理我不詳細解釋了,只說說所需步驟吧!

先要條件: 在你的 MySinaBlog 的 Sidebar 裏開啟「最近留言」

步驟:

(一) 製作你的 Comment Dapp

  1. 點「Create a Dapp」
  2. 輸入網址 (例: http://jackysee.mysinablog.com)
  3. 進入 Dapp 的 virtual browser 後,按「Add to Basket」,然後按「Finish」
  4. Dapp 會分析你的網址,完了後請按「Go Play」
  5. 待三版的頁面都載入完畢,按右邊的「Proceed to next step」
  6. 按「Get started!」
  7. 在右下框格拖到頁底,找到「最近留言」後,點選留言者的名字,會在右邊欄的 Field Element 出現,按「Save and Continue」
  8. 輸入欄名字 (commenter)
  9. 點「Create another field」
  10. 照辦煮碗找「最近留言」,這次點留言內容,然後也是右邊的「Save and Continue」
  11. 輸入欄名字 (comment content)
  12. 可點「Preview Output」看看所抓取的資料是否正確
  13. 點「Create a Group」
  14. 在右邊欄以 ctrl-click 選擇全部欄位 (Commenter 和 Comment Content),點「Create group from selected fields」
  15. 輸入 group 名字 (comment)
  16. 點「Save your Dapp」,然後輸入 Dapp 的資料 (name, description, tag),再點「Save your Dapp」。你的 Comment Dapp 就已完成了!

(二) 製作 RSS

  1. 在 Dapp 頁面點選 RSS
  2. Item title 選 Comment content
  3. Item Description 複選 commenter, comment content
  4. Item link 選 comment content@href
  5. 按「Generate URL」
  6. 嘗試開啟該 URL,如在 Firefox 裏就會看到該 RSS 的樣子了!如果不滿意的話可以再自行調較參數。

必需留意的是,如果你沒有登入,這個 Dapp 會在 24 小時後變成 public 給其他人使用,而不可以再作修改。因此,請登記並登入你的 Dapp 戶口,Claim 你剛做好的 Dapp,選「save it to your sandbox」就可以變成私人用的 Dapp 了。

如果大家有心再研究的話,就會發現 Dapp 還有很多不同的功能,可以幫助你在不同的網頁抓取不同的資料,並以各種不同的專有格式發放,用途可以很廣泛。有興趣的話,可以看看官網的 Screencast 介紹。

二百萬與 RSS

Thursday, November 30, 2006

最近微軟發表的網誌研究發現 香港有二百萬 blogger ,其中:

(受訪者)認為至於最令人討厭的地方,網民指不知道網誌何時更新、內容乏味或無聊、對內容可靠性存疑,均會令他們生厭。

只說「不知道網誌何時更新」這一項,這證明受訪者多人寫 Blog,但沒有幾個懂 RSS 是什麼。

可以想像,他們的「訂閱」的方法就是 bookmark,然後定期去看看有沒有更新。一場到來卻沒有新貨,失望而回自然「令人討厭」。RSS 的好處,在於可以將所有的更新都聚合到 RSS reader,你只要從一個地方,就可以自動地被通知多個不同地方的更新,一時間 RSS reader 變成收消息、閱讀中心,機器背後幫你做了人手要做的東西,有效率多了。

記幾上個星期左右,HKBG 有位朋友寫了個 Blog system 想大家給給意見,一看之下竟然最基本的 RSS/Trackback 功能都沒有。連開發者都對 RSS 毫無意識,本地用家有多少認識就更是疑問。(當然,這只是個例子,並沒有代表性) 此討論串間,有人問:

想問一問, blog 是否需要有 rss / comment / permalink 一類的 features? 只以 blog / weblog 的發展來說,應該有「特定題材」及「時序」就應可以被定性為 blog …

這又回到 Blog 定義的老問題上。說到最原始的定義,其實你大可以手寫一個 html 每日更新,也可以算是 Blog。但科技一路走來,其實都是不停地將舊有意念再包裝再創新,增添新的價值。由飛鴿傳書、郵差叔叔到電子郵件,由個人家頁、網上日記到 Blog,由 Web 1.0 到 Web 2.0,當中每一步的「進化」,將舊概念提升改革,都提供了不少新的價值。

我們不手寫一個 Blog,而是使用 Blog software / BSP 服務,因為那樣比較方便快捷。我們用 RSS 去追踪 Blog 文章更新,因為那讓我更有效率地飽覽網絡資訊。 RSS / Trackback / Permalink 這些功能,已是 Blog 的 de facto standard (這個中文怎樣說?),你可以不支持這些技術,但就失卻了很多功能,也失卻了這些技術所帶來的價值:使 Blog 與 Blog 之間的聯繫更緊密,使社群間更有凝聚力,使個人力量得到放大,使世界推得更平。

早前 IE7 終於推出,有人認為其內置的 RSS 支援應該可使此一技術更能普及化,但事實上要看其滲透率如何。所以,這還不如多推介一下 Bloglines , Google Reader 讓人體驗 RSS 的方便之處。

相關閱讀: