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 版

取全文 greasemonkey 移到 google code

Sunday, October 28, 2007

趁著更新那三個取全文 greasemonkey scripts,順手將 code 到放到 google code 裏去,大家以後的更新請到 google code 網頁下載。

是次主要更新 yahoo 版本的 parser,因為 yahoo! blog 最近改了版。

取全文 Greasemonkey Bloglines (beta) 版本

Friday, August 31, 2007

Bloglines 終於改版面了,其 beta 版本推出,看上去有幾分 Google Reader 的味道。我將我本來的 取全文 油猴修改了出一個 Beta 版本專用的:

請到 Gresemonkey 取全文

用法一樣,在被選取和已展開的文格裏按 ‘g’ 取全文。

  • 2007-10-28 Update:28 將 scripts 移到 google code

取全文 Greasemonkey Bloglines 版

Wednesday, July 11, 2007

MySinaBlog 的 RSS 圖片問題又引來,因此我快速地將原本用在 Google Reader取全文 Greasemonkey Scripts Port 了一個 Bloglines 版本:

請到 Gresemonkey 取全文

用法差不多,在 Bloglines 的內容版面上,按 “j” 會將文章 highlight,然後再按 “g” 就能取得全文。現時支持: hk yahoo blog, my sina blog, xuite blog, roodo blog, yam blog, hk yahoo news 和幾個個人 blog: ESWN, 小奧, Moliulogy, Mr6, 案內人隨筆(他是全文的,不過 feed 排版難看,所以加了)

2007-07-11 Update: 加入了 Netvigator Hompy, Wretch.cc
2007-08-31 Update: 新增了給 beta 用的版本,詳情請看 取全文 Greasemonkey Bloglines (beta) 版本
2007-10-28 Update: 2007-10-28 將 scripts 移到 google code