File: GM_notification.js

package info (click to toggle)
greasemonkey 2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,820 kB
  • sloc: xml: 171; makefile: 10
file content (38 lines) | stat: -rw-r--r-- 1,400 bytes parent folder | download | duplicates (2)
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
Components.utils.import("resource://gre/modules/PopupNotifications.jsm");
Components.utils.import("resource://greasemonkey/prefmanager.js");
Components.utils.import('resource://greasemonkey/util.js');

var EXPORTED_SYMBOLS = ["GM_notification"];

var Cc = Components.classes;
var Ci = Components.interfaces;

var gStringBundle = Components
    .classes["@mozilla.org/intl/stringbundle;1"]
    .getService(Components.interfaces.nsIStringBundleService)
    .createBundle("chrome://greasemonkey/locale/greasemonkey.properties");

function mute(aTopic) {
  GM_prefRoot.setValue('notification.muted.' + aTopic, true);
}

function GM_notification(
    aMsg, aTopic) {
  var muted = GM_prefRoot.getValue('notification.muted.' + aTopic, false);
  if (muted) return;

  var action = {
      'label': gStringBundle.GetStringFromName('notification.ok.label'),
      'accessKey': gStringBundle.GetStringFromName('notification.ok.accesskey'),
      'callback': function() { },
      }
  var muteAction = {
      'label': gStringBundle.GetStringFromName('notification.neveragain.label'),
      'accessKey': gStringBundle.GetStringFromName('notification.neveragain.accesskey'),
      'callback': function() { mute(aTopic); },
      };
  var win = GM_util.getBrowserWindow();
  win.PopupNotifications.show(
      win.gBrowser.selectedBrowser, 'greasemonkey-notification',
      aMsg, null, action, [muteAction]);
};