Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/typoSurvey.js

Issue 8948027: Ported changes from Adblock Plus integration back into URL Fixer (Closed)
Patch Set: Created Nov. 23, 2012, 3:28 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/typoNetError.js ('K') | « lib/typoRules.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/typoSurvey.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/typoSurvey.js
@@ -0,0 +1,115 @@
+/*
Wladimir Palant 2012/12/13 16:07:00 Same question as for typoCollector.js - this has b
Thomas Greiner 2013/01/14 10:06:41 Same answer: IIRC yes.
+ * This file is part of the URL Fixer,
+ * Copyright (C) 2006-2012 Eyeo GmbH
+ *
+ * URL Fixer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * URL Fixer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with URL Fixer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+let {Prefs} = require("prefs");
+
+let surveyLang = null;
+let surveyUrl = null; //"http://urlfixer.org/usersurvey/...";
+
+exports.incrementCorrectionsCounter = incrementCorrectionsCounter;
+function incrementCorrectionsCounter()
+{
+ // Only if survey exists
+ if (!surveyUrl)
+ return;
+
+ // Only users with 5 URL corrections
+ if (++Prefs.corrections_count == 5)
+ {
+ initSurvey();
+ }
+}
+
+function initSurvey()
+{
+ // Don't ask after 2012-10-15
+ if (Date.now() > 1350259200000)
+ return;
+
+ // Only Firefox users
+ let {application} = require("info");
+ if (application != "firefox")
+ return;
+
+ // Only Firefox 4 and higher
+ if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0)
+ return;
+
+ // Survey is only available in English/German/Russian
+ if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory("NSILOCALE_CTYPE")))
+ return;
+ surveyLang = RegExp.$1;
+
+ // Delay survey question by 5 seconds
+ surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT);
+}
+
+function runSurvey()
+{
+ //open panel
+ let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
+ request.open("GET", "chrome://url-fixer/content/survey.xul");
+ request.addEventListener("load", function(event)
+ {
+ let window = Services.wm.getMostRecentWindow("navigator:browser");
+ let document = window.document;
+
+ let style = document.createProcessingInstruction('xml-stylesheet', 'href="chrome://url-fixer/skin/survey.css" type="text/css"');
+ document.insertBefore(style, document.firstChild);
+
+ let panel = new window.DOMParser().parseFromString(request.responseText, "text/xml").documentElement;
+ let oldPanel = document.getElementById(panel.id);
+ if (oldPanel)
+ oldPanel.parentNode.removeChild(oldPanel);
+ document.getElementById("mainPopupSet").appendChild(panel);
+ document.getElementById("url-fixer-icon").setAttribute("src", require("info").addonRoot + "icon64.png");
+ document.getElementById("url-fixer-accept-button").addEventListener("command", function()
+ {
+ openSurvey();
+ panel.hidePopup();
+ });
+ document.getElementById("url-fixer-cancel-button").addEventListener("command", function()
+ {
+ panel.hidePopup();
+ });
+ panel.addEventListener("popuphidden", function()
+ {
+ panel.parentNode.removeChild(panel);
+ style.parentNode.removeChild(style);
+ });
+
+ let anchor = document.getElementById("identity-box");
+ panel.openPopup(anchor, "after_start", 0, 0, false, true);
+ }, false);
+ request.send(null);
+}
+
+function openSurvey()
+{
+ let window = Services.wm.getMostRecentWindow("navigator:browser");
+ if (window)
+ {
+ let browser = require("typoAppIntegration").getBrowser(window);
+ browser.loadOneTab(surveyUrl + "&lang=" + surveyLang, {
+ referrerURI: Services.io.newURI("http://url.fixer/", null, null),
+ inBackground: false
+ });
+ }
+}
« lib/typoNetError.js ('K') | « lib/typoRules.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld