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.
--- /dev/null
+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;
+ }
+}