[ Update, Mar 16th, 2011: Firefox 4’s Greasemonkey changed GM_getValue and it doesn’t support .toString() anymore, code updated accordingly. Added GM_deleteValue ]

As there’s no implementation for GM_getValue/setValue in user scripts (Greasemonkey) for Google Chrome, it makes a lot of user scripts unsupported.

Here’s a little code that brings the support of these methods to Chrome, by saving data in localStorage (HTML5’s way to store data on client side).

Include it in your Greasemonkey script to have it working on Chrome.

1
2
3
4
5
6
7
8
9
10
11
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
  this.GM_getValue=function (key,def) {
      return localStorage[key] || def;
  };
  this.GM_setValue=function (key,value) {
      return localStorage[key]=value;
  };
  this.GM_deleteValue=function (key) {
      return delete localStorage[key];
  };
}

This makes Google Reader Filter available for Chrome.

Comments