Friday, February 5, 2010

Fixing the XPath problem in Firefox 3.6

In Greasemonkey development, it is a common practice to use GM_xmlhttpRequest + DOM Document Wrapper + XPath to process cross-origin content. However in Firefox 3.6, the XPath query stop working. Here is the fix:

Firefox 3.5 code

var doc = document.implementation.createDocument("", "", null);
div.innerHTML = html;
doc.appendChild(div);
var res = doc.evaluate("//p[@class='content']/span", div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
// res is null

Firefox 3.6 code

var isFF36up = false;
if (navigator.userAgent) {
var ffver = navigator.userAgent.match(/Firefox\/3\.(\d+)/);
isFF36up = ffver && parseInt(ffver[1], 10) >= 6;
}

var nsResolver = {
lookupNamespaceURI:function (prefix) {
if (isFF36up && prefix == "ns") {
return "http://www.w3.org/1999/xhtml";
}
else {
return "";
}
}
};

var doc = document.implementation.createDocument("", "", null);
div.innerHTML = html;
doc.appendChild(div);
var res = doc.evaluate("//ns:p[@class='content']/ns:span", div, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

Thursday, March 19, 2009

Better Mobile Twitter version 5

Better Mobile Twitter
Better Mobile Twitter
Just released the version 5 of Better Mobile Twitter greasemonkey script. You can install in http://userscripts.org/scripts/show/35396. There version adds image preview and auto expand short URL.

I prefer to use the mobile web version of Twitter because it is faster. Better Mobile Twitter is to enhance the user experience in Twitter's mobile version, with the following features:
  • Automatically load next page when scrolling to bottom of the page (continues browsing similar to Google Reader)
  • Display replies and direct messages in sidebar (New)
  • Images and Youtube thumbnail preview (supports twitpic, flickr, YouTube, hellotxt, ping.fm, TwinkleShots) (New)
  • Auto expand short URL (supports Tinyurl, bit.ly, Friendfeed, hellotxt, is.gd, Ping.fm, short.to, SnipURL, Tweetburner, tr.im) (New)
  • Add reply button like standard version (New)
  • Count the characters remaining as you typing
  • Check for new tweets in background and display number of new tweets in title bar
  • Wider input box
  • Add a user filter
  • An on/off button so you can turn off the auto-next-page function to access the links in the bottom of the page
Firefox users can first install the Greasemonkey add-on, install the script from http://userscripts.org/scripts/show/35396, then point your browser to http://m.twitter.com/home.

Chrome users please read this document to enable user scripts.

You can take a look on my other greasemonkey scripts in my user page in userscripts.org.

Tuesday, March 3, 2009

Better Mobile Twitter version 4

Better Mobile TwitterJust released the version 4 of Better Mobile Twitter greasemonkey script. You can install in http://userscripts.org/scripts/show/35396. There version adds image preview and auto expand short URL.

Better Mobile Twitter is to enhance the user experience in Twitter's mobile version, with the following features:
  • Automatically load the next page when scrolling to bottom of the page (similar to Google Reader)
  • Images and Youtube thumbnail preview (supports twitpic, flickr, YouTube and TwinkleShots) (New, Firefox only)
  • Auto expand short URL (supports Tinyurl, bit.ly, Friendfeed, hellotxt, is.gd, Ping.fm and SnipURL) (New, Firefox only)
  • Count the characters remaining as you typing
  • Check for new tweets in background and display number of new tweets in title bar (New)
  • Wider input box
  • Add a user filter (New)
  • An on/off button so you can turn off the auto-next-page function to access the links in the bottom of the page
Firefox users can first install the Greasemonkey add-on, install the script from http://userscripts.org/scripts/show/35396, then point your browser to http://m.twitter.com/home.

Chrome users please read this document to enable user scripts.

You can take a look on my other greasemonkey scripts in my user page in userscripts.org.

Thursday, December 18, 2008

ESPN FBA Player Rater userscript

For Fantasy Basketball lover! A small Greasemonkey script that show more information in ESPN FBA Player Rater page:
  • Positional ranking (PRK)
  • % owned
  • Average draft position (ADP)
Not very useful, but is funny for you to locate the sleepers and dusts. Watch Nene jump from ADP 96 to rank 21, Duhon from ADP 122 to 29 and Millsap from undrafted to 31.
Down to the table, you will feel sorry for the owners of Marion (11.5 to 72), Iverson (11.3 to 85) and Brand (17.2 to 111).
Install and download from http://userscripts.org/scripts/show/38843.  It supports Firefox and Chrome (Chrome users please read this post).

Tuesday, December 16, 2008

Chrome 1.0 (not Chromium) supports Greasemonkey now

ChromonkeyGoogle Chrome 1.0 supports Greasemonkey.  You can use Google Reader Unread Count and Better Mobile Twitter in Chrome now.

To enable Greasemonkey in Chrome, download and install the latest Chrome. Right click your Chrome shortcut, add "--enable-greasemonkey" to the end of the "Target" box (see below).  Finally, you have to put the scripts in the folder "C:\scripts\" and the script files' extension must be ".user.js".

Friday, December 5, 2008

Google Reader has new look



Google Reader has new look.  I like the collapsible section so I can free more space for the feed list.  And I'm please to tell you that my Google Reader Unread Count greasemonkey script still works for new look.  Enjoy it.

Thursday, November 20, 2008

Better Mobile Twitter version 3

Better Mobile TwitterJust finish the version 3 of Better Mobile Twitter greasemonkey script. You can install in http://userscripts.org/scripts/show/35396.

Better Mobile Twitter is to enhance the user experience in Twitter's mobile version, with the following features:
  • Automatically load the next page when scrolling to bottom of the page (similar to Google Reader)
  • Count the characters remaining as you typing
  • Check for new tweets in background
  • Wider input box
  • An on/off button so you can turn off the auto-next-page function to access the links in the bottom of the page
You can see how it works in the video below.

Firefox users can first install the Greasemonkey add-on, install the script from http://userscripts.org/scripts/show/35396, then point your browser to http://m.twitter.com/home.

Chrome users need to download the nightly build of Chromium, put the script in c:\scripts and run Chrome with command-line "chrome.exe --enable-greasemonkey", or create a shortcut for it.

You can take a look on my other greasemonkey scripts in my user page in userscripts.org.