// $Id: gm-api.js.txt,v 1.2 2006/06/22 11:27:44 tobez Exp $ // an example of using ISWEST API from Greasemonkey scripts /** ** ---------------------------------------------------------------------------- ** "THE BEER-WARE LICENSE" (Revision 42) ** wrote this file. As long as you retain this notice you ** can do whatever you want with this stuff. If we meet some day, and you think ** this stuff is worth it, you can buy me a beer in return. Anton Berezin ** ---------------------------------------------------------------------------- **/ function Iswest(base, rwid, roid) { var uri = base.replace(/\/$/, "") + "/json/"; var rwid = rwid; var roid = roid || rwid; var req = function(callback, reqname, data) { GM_xmlhttpRequest({ method: 'POST', url: uri + reqname, headers: { 'Content-type': 'application/x-www-form-urlencoded' }, data: data, onload: function (resp) { var r = eval("(" + resp.responseText + ")"); callback(r); } }); }; this.list = function (callback, prefix) { var data = "id=" + encodeURIComponent(roid); if (prefix) data += "&prefix=" + encodeURIComponent(prefix); req(callback, "list", data); }; this.get = function (callback, key) { var data = "id=" + encodeURIComponent(roid) + "&key=" + encodeURIComponent(key); req(callback, "get", data); }; this.put = function (callback, key, d) { var data = "id=" + encodeURIComponent(roid) + "&key=" + encodeURIComponent(key) + "&data=" + encodeURIComponent(d); req(callback, "put", data); }; }