-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromfacts.js
85 lines (78 loc) · 3.89 KB
/
promfacts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/******************************************************************************
* *
* promfacts -- Jetpack feature for prometheus Facts *
* *
* Copyright (C) 2009-2011 Jens Wille *
* *
* promfacts is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Affero General Public License as published by the Free *
* Software Foundation; either version 3 of the License, or (at your option) *
* any later version. *
* *
* promfacts is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESSFOR A PARTICULAR PURPOSE. See the GNU Affero General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with promfacts. If not, see <http://www.gnu.org/licenses/>. *
* *
* @title prometheus Facts *
* @description Jetpack feature for prometheus Facts *
* @author Jens Wille <[email protected]> *
* @license AGPL *
* @version 0.0.4 *
* @url http://wiki.github.com/blackwinter/jetpacks/promfacts *
* @update http://github.com/blackwinter/jetpacks/raw/master/promfacts.js *
* *
******************************************************************************/
var Prom = function() {
var prefs = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefService)
.getBranch('jetpacks.promfacts.');
var get_pref = function(key, deflt) {
var type = prefs.getPrefType(key);
return type === prefs.PREF_STRING ? prefs.getCharPref(key) : deflt;
};
var url = 'http://prometheus.uni-koeln.de/pandora',
lang = get_pref('lang', 'en'), tr = {};
if (lang === 'de') {
tr.title = 'prometheus in Zahlen';
tr.none = 'Keine gefunden';
}
else {
tr.title = 'prometheus Facts';
tr.none = 'None found';
}
return {
icon: url + '/favicon.ico', tr: tr,
facts: function(callback) {
jQuery.ajax({
type: 'GET', dataType: 'json',
url: url + '/' + lang + '/pandora.json',
error: function(xhr, status) { callback(); },
success: function(data) {
var facts = data.facts;
callback(jQuery.isArray(facts) && facts.length > 0 && facts);
}
});
}
};
}();
jetpack.statusBar.append({
html: '<img src="' + Prom.icon + '" alt="promfacts">', width: 18,
onReady: function(widget) {
$('img', widget).css({ cursor: 'pointer' });
$(widget).click(function() {
Prom.facts(function(facts) {
jetpack.notifications.show({
title: Prom.tr.title, icon: Prom.icon,
body: facts ? '<table>' + jQuery.map(facts, function(i) {
var cells = '<td align="right">$1</td><td></td><td>$2</td>';
return '<tr>' + i.replace(/(\S+)\s+(.+)/, cells) + '</tr>';
}).join('') + '</table>' : Prom.tr.none + ' :-('
});
});
});
}
});