1 var nmbug_server = 'http://localhost:5000';
4 show: function (message_id) {
5 this._get_tags(message_id, this._edit_tags.bind(this));
7 _get_tags: function (message_id, callback) {
11 encodeURIComponent(message_id),
13 console.log('nmbug: get tags from ' + url);
14 var request = new XMLHttpRequest();
15 request.onload = function () {
16 if (this.status == 200) {
17 var tags = JSON.parse(this.response);
18 console.log('nmbug: got tags', tags);
19 callback(message_id, tags);
21 throw 'Error fetching ' + url + ' (status ' + this.status + ')';
24 request.open('get', url, true);
27 _edit_tags: function (message_id, tags) {
28 alert('edit ' + tags + ' for ' + message_id);
32 var _gmane_handler = {
33 regexp: /gmane[.]org/,
34 handle: function (callback) {
35 var article = this._get_article();
36 this._get_message_id(article, callback);
38 _article_from_url: function (url) {
39 var regexp = new RegExp('http://article.gmane.org/([^/]+)/([0-9]+)');
40 var match = regexp.exec(url);
41 console.log('nmbug: get article from ' + url, match);
43 return {'group': match[1], 'id': parseInt(match[2])};
46 _get_article: function () {
47 var article = this._article_from_url(document.URL);
49 for (var i = 0; !article && i < window.frames.length; i++) {
50 article = this._article_from_url(window.frames[i].document.URL);
53 throw "Cannot extract an article from Gmane's " + document.URL;
57 _get_message_id: function (article, callback) {
64 console.log('nmbug: get Message-ID from ' + url);
65 var request = new XMLHttpRequest();
66 request.onload = function () {
67 var message_id = this.responseText;
70 request.open('get', url, true);
79 function _check_handler(handler) {
80 var match = handler.regexp.test(document.URL);
81 console.log('nmbug: testing', handler, match);
83 console.log('nmbug: matched', handler);
84 handler.handle(nmbug.show.bind(nmbug));
86 return match; /* break after the first match */
90 var matched = handlers.some(_check_handler);
92 throw 'No handler for ' + document.URL;