Greasemonkey @require libraries
- Problem:
- There is a shortage of well abstracted micro-libraries to @require in Greasemonkey scripts.
- Solution:
- Define useful, minimal feature sets, and implement and/or advertise their specs to prospective other implementors.
- Interfaces:
- $x(xpath, root) / $X(xpath, root)
- $x evaluates an XPath expression, returning an Array of nodes, a string, number or boolean, depending on the return type it evaluates to. $X returns the first match only (in document order). Both take an optional context node to resolve the expression from.
- wget(url, cb) / wget$x(url, cb, xpath) / wget$X(url, cb, xpath)
- wget does a GM_xmlhttpRequest fetch of an entity and renders it into a DOM that can be queried by XPath, and gets passed on to the callback (second parameter: url). The wget$x methods also do the slicing and pass the $x result, the document, url and xhr object to cb.
- MD5 singleton
- MD5.string(data) yields the binary MD5 hash, MD5.hex(data) will hex code it prior to returning the result. MD5.base64(data) similarly for Base64 encoding.
- SHA1 singleton
- Like MD5, but for SHA1 instead, and the string method is called "hash". Also takes an optional second argument 8 or 16 for string width. MD5 ought to be updated to mimic this API instead.
- Diff singleton
- Renders a text/html diff of two text/plain (unfortunately) inputs. Usage:
var diff = Diff.diff_main(text1, text2);
Diff.diff_cleanupSemantic(diff);
var html = Diff.diff_prettyHtml(diff);
- Notes:
- Incomplete.
- Update incrementally.
0 Comments:
Post a Comment ...in a popup window