Permalink
Browse files

UI to prompt users to opt-in to statistics gathering.

Fixes #1651
  • Loading branch information...
1 parent 68adc2d commit 5b42344a2a7336b4db5cdfd8cb80d6d9b1fe5305 @arantius committed Nov 7, 2012
Showing with 48 additions and 1 deletion.
  1. +5 −0 locale/en-US/greasemonkey.properties
  2. +43 −1 modules/stats.js
@@ -18,3 +18,8 @@ warning.scripts-should-grant.read-docs=Read documentation
warning.scripts-should-grant.read-docs.key=R
warning.scripts-should-grant.dont-show=Don't show this message again
warning.scripts-should-grant.dont-show.key=D
+stats-prompt.msg=Please help improve Greasemonkey by submitting anonymous usage statistics.
+stats-prompt.optin=Opt In
+stats-prompt.optin.accesskey=O
+stats-prompt.readmore=Read More
+stats-prompt.readmore.accesskey=R
View
@@ -14,6 +14,10 @@ Components.utils.import('resource://greasemonkey/prefmanager.js');
Components.utils.import('resource://greasemonkey/util.js');
var gPrefMan = new GM_PrefManager();
+var gStringBundle = Components
+ .classes["@mozilla.org/intl/stringbundle;1"]
+ .getService(Components.interfaces.nsIStringBundleService)
+ .createBundle("chrome://greasemonkey/locale/greasemonkey.properties");
// Check once, soon.
GM_util.timeout(check, 1000 * 10) // ms = 10 seconds
@@ -24,7 +28,10 @@ GM_util.timeout(
function check() {
- if (!gPrefMan.getValue('stats.optedin')) return;
+ if (!gPrefMan.getValue('stats.optedin')) {
+ promptUser();
+ return;
+ }
var lastSubmit = new Date(gPrefMan.getValue('stats.lastsubmittime'));
var nextSubmit = new Date(
@@ -142,3 +149,38 @@ function getStatsObj() {
return stats;
}
+
+
+function promptUser() {
+ if (gPrefMan.getValue('stats.prompted')) return;
+ gPrefMan.setValue('stats.prompted', true);
+
+ var win = GM_util.getBrowserWindow();
+ var browser = win.gBrowser;
+
+ var notificationBox = browser.getNotificationBox();
+ notificationBox.appendNotification(
+ gStringBundle.GetStringFromName('stats-prompt.msg'),
+ "greasemonkey-stats-opt-in",
+ "chrome://greasemonkey/skin/icon16.png",
+ notificationBox.PRIORITY_INFO_MEDIUM,
+ [{
+ 'label': gStringBundle.GetStringFromName('stats-prompt.readmore'),
+ 'accessKey': gStringBundle.GetStringFromName('stats-prompt.readmore.accesskey'),
+ 'popup': null,
+ 'callback': function() {
+ browser.loadOneTab(
+ 'http://www.greasespot.net/2012/11/anonymous-statistic-gathering.html',
+ {'inBackground': false});
+ }
+ },{
+ 'label': gStringBundle.GetStringFromName('stats-prompt.optin'),
+ 'accessKey': gStringBundle.GetStringFromName('stats-prompt.optin.accesskey'),
+ 'popup': null,
+ 'callback': function() {
+ gPrefMan.setValue('stats.optedin', true);
+ check();
+ }
+ }]
+ );
+}

0 comments on commit 5b42344

Please sign in to comment.