From: W. Trevor King Date: Sat, 20 Sep 2014 18:46:37 +0000 (-0700) Subject: nmbug.js: Sketch out the bookmarklet framework X-Git-Tag: v0.1.0~37 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fe31ab80e42372f2b4ad9b7b21f7027cea37c2e6;p=nmhive.git nmbug.js: Sketch out the bookmarklet framework We'll have a generic nmbug.show() to handle the UI for tagging a given message (using its Message-ID). To get that Message-ID, we'll have a list of potential handlers. When the bookmarklet fires (run()), we'll iterate through the handlers unril handler.regexp matches document.URL. For the first match, we'll run handler.handle, which will do whatever it needs to figure out the Message-ID, and then launch nmbug.show (passed in via 'callback') with the extracted id. --- diff --git a/nmbug.js b/nmbug.js new file mode 100644 index 0000000..214c9f2 --- /dev/null +++ b/nmbug.js @@ -0,0 +1,33 @@ +nmbug = { + show: function (message_id) { + alert(message_id); + }, +}; + +var _gmane_handler = { + regexp: /gmane[.]org/, + handle: function (callback) { + throw 'Extract the Message-ID from ' + document.URL; + }, +}; + +var handlers = [ + _gmane_handler, +]; + +function _check_handler(handler) { + var match = handler.regexp.test(document.URL); + console.log('nmbug: testing', handler, match); + if (match) { + console.log('nmbug: matched', handler); + handler.handle(nmbug.show); + } + return match; /* break after the first match */ +} + +function run() { + var matched = handlers.some(_check_handler); + if (!matched) { + throw 'No handler for ' + document.URL; + } +}