Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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.
| |
2 * This file is part of the URL Fixer, | |
3 * Copyright (C) 2006-2012 Eyeo GmbH | |
4 * | |
5 * URL Fixer is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 3 as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * URL Fixer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with URL Fixer. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 Cu.import("resource://gre/modules/Services.jsm"); | |
19 | |
20 let {Prefs} = require("prefs"); | |
21 | |
22 let surveyLang = null; | |
23 let surveyUrl = null; //"http://urlfixer.org/usersurvey/..."; | |
24 | |
25 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; | |
26 function incrementCorrectionsCounter() | |
27 { | |
28 // Only if survey exists | |
29 if (!surveyUrl) | |
30 return; | |
31 | |
32 // Only users with 5 URL corrections | |
33 if (++Prefs.corrections_count == 5) | |
34 { | |
35 initSurvey(); | |
36 } | |
37 } | |
38 | |
39 function initSurvey() | |
40 { | |
41 // Don't ask after 2012-10-15 | |
42 if (Date.now() > 1350259200000) | |
43 return; | |
44 | |
45 // Only Firefox users | |
46 let {application} = require("info"); | |
47 if (application != "firefox") | |
48 return; | |
49 | |
50 // Only Firefox 4 and higher | |
51 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0) | |
52 return; | |
53 | |
54 // Survey is only available in English/German/Russian | |
55 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory(" NSILOCALE_CTYPE"))) | |
56 return; | |
57 surveyLang = RegExp.$1; | |
58 | |
59 // Delay survey question by 5 seconds | |
60 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | |
61 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); | |
62 } | |
63 | |
64 function runSurvey() | |
65 { | |
66 //open panel | |
67 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci. nsIXMLHttpRequest); | |
68 request.open("GET", "chrome://url-fixer/content/survey.xul"); | |
69 request.addEventListener("load", function(event) | |
70 { | |
71 let window = Services.wm.getMostRecentWindow("navigator:browser"); | |
72 let document = window.document; | |
73 | |
74 let style = document.createProcessingInstruction('xml-stylesheet', 'href="ch rome://url-fixer/skin/survey.css" type="text/css"'); | |
75 document.insertBefore(style, document.firstChild); | |
76 | |
77 let panel = new window.DOMParser().parseFromString(request.responseText, "te xt/xml").documentElement; | |
78 let oldPanel = document.getElementById(panel.id); | |
79 if (oldPanel) | |
80 oldPanel.parentNode.removeChild(oldPanel); | |
81 document.getElementById("mainPopupSet").appendChild(panel); | |
82 document.getElementById("url-fixer-icon").setAttribute("src", require("info" ).addonRoot + "icon64.png"); | |
83 document.getElementById("url-fixer-accept-button").addEventListener("command ", function() | |
84 { | |
85 openSurvey(); | |
86 panel.hidePopup(); | |
87 }); | |
88 document.getElementById("url-fixer-cancel-button").addEventListener("command ", function() | |
89 { | |
90 panel.hidePopup(); | |
91 }); | |
92 panel.addEventListener("popuphidden", function() | |
93 { | |
94 panel.parentNode.removeChild(panel); | |
95 style.parentNode.removeChild(style); | |
96 }); | |
97 | |
98 let anchor = document.getElementById("identity-box"); | |
99 panel.openPopup(anchor, "after_start", 0, 0, false, true); | |
100 }, false); | |
101 request.send(null); | |
102 } | |
103 | |
104 function openSurvey() | |
105 { | |
106 let window = Services.wm.getMostRecentWindow("navigator:browser"); | |
107 if (window) | |
108 { | |
109 let browser = require("typoAppIntegration").getBrowser(window); | |
110 browser.loadOneTab(surveyUrl + "&lang=" + surveyLang, { | |
111 referrerURI: Services.io.newURI("http://url.fixer/", null, null), | |
112 inBackground: false | |
113 }); | |
114 } | |
115 } | |
OLD | NEW |