nmbug.js: Sketch out the bookmarklet framework
[nmhive.git] / nmbug.js
1 nmbug = {
2         show: function (message_id) {
3                 alert(message_id);
4         },
5 };
6
7 var _gmane_handler = {
8         regexp: /gmane[.]org/,
9         handle: function (callback) {
10                 throw 'Extract the Message-ID from ' + document.URL;
11         },
12 };
13
14 var handlers = [
15         _gmane_handler,
16 ];
17
18 function _check_handler(handler) {
19         var match = handler.regexp.test(document.URL);
20         console.log('nmbug: testing', handler, match);
21         if (match) {
22                 console.log('nmbug: matched', handler);
23                 handler.handle(nmbug.show);
24         }
25         return match;  /* break after the first match */
26 }
27
28 function run() {
29         var matched = handlers.some(_check_handler);
30         if (!matched) {
31                 throw 'No handler for ' + document.URL;
32         }
33 }