Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 Cu.import("resource://gre/modules/Services.jsm"); | 5 Cu.import("resource://gre/modules/Services.jsm"); |
6 | 6 |
7 let {Prefs} = require("prefs"); | 7 let {Prefs} = require("prefs"); |
8 | 8 |
9 let win = null; | |
10 let surveyLang = null; | 9 let surveyLang = null; |
11 let surveyUrl = "http://urlfixer.org"; //"http://adblockplus.org/usersurvey/inde x.php?sid=68316"; | 10 let surveyUrl = "http://urlfixer.org"; //"http://adblockplus.org/usersurvey/inde x.php?sid=68316"; |
12 | 11 |
13 let langData = { | 12 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; |
14 en: { | 13 function incrementCorrectionsCounter() |
15 title: "Tell us your opinion", | 14 { |
16 question: "We would like to ask you a few questions about URL Fixer to help us improve it. If you can spare 5 minutes please click the button below to take the survey.", | 15 // Only users with 5 URL corrections |
17 note: "This is a one-time message and will not appear again.", | 16 if (++Prefs.corrections_count == 5) |
18 accept: "Take the survey", | 17 { |
19 decline: "Maybe some other time" | 18 initSurvey(); |
20 }, | |
21 de: { | |
22 title: "Sagen Sie uns Ihre Meinung", | |
23 question: "Wir w\xFCrden Ihnen gerne einige Fragen zu URL Fixer stellen, um es verbessern zu k\xF6nnen. Falls Sie gerade 5 Minuten haben, dr\xFCcken Sie bit te die Taste unten, um an der Nutzerumfrage teilzunehmen.", | |
24 note: "Das ist eine einmalige Nachricht, die nicht wieder erscheinen wird.", | |
25 accept: "An der Umfrage teilnehmen", | |
26 decline: "Vielleicht ein anderes Mal" | |
27 }, | |
28 ru: { | |
29 title: decodeURIComponent("%D0%9F%D0%BE%D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%B9%D1%81%D1%82%D0% B0%2C%20%D0%BD%D0%B0%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D1%83%2C%20%D1%87%D1%82%D0 %BE%D0%B1%D1%8B%20%D0%BF%D1%80%D0%B8%D0%BD%D1%8F%D1%82%D1%8C%20%D1%83%D1%87%D0%B 0%D1%81%D1%82%D0%B8%D0%B5%20%D0%B2%20%D0%BE%D0%BF%D1%80%D0%BE%D1%81%D0%B5."), | |
31 note: decodeURIComponent("%D0%AD%D1%82%D0%BE%20%D0%BE%D0%B4%D0%BD%D0%BE%D1%8 0%D0%B0%D0%B7%D0%BE%D0%B2%D0%BE%D0%B5%20%D1%81%D0%BE%D0%BE%D0%B1%D1%89%D0%B5%D0% BD%D0%B8%D0%B5%2C%20%D0%BE%D0%BD%D0%BE%20%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B5%20 %D0%BD%D0%B5%20%D0%B1%D1%83%D0%B4%D0%B5%D1%82%20%D0%BF%D0%BE%D0%BA%D0%B0%D0%B7%D 1%8B%D0%B2%D0%B0%D1%82%D1%8C%D1%81%D1%8F."), | |
32 accept: decodeURIComponent("%D0%9F%D1%80%D0%B8%D0%BD%D1%8F%D1%82%D1%8C%20%D1 %83%D1%87%D0%B0%D1%81%D1%82%D0%B8%D0%B5%20%D0%B2%20%D0%BE%D0%BF%D1%80%D0%BE%D1%8 1%D0%B5"), | |
33 decline: decodeURIComponent("%D0%9C%D0%BE%D0%B6%D0%B5%D1%82%20%D0%B2%20%D0%B 4%D1%80%D1%83%D0%B3%D0%BE%D0%B9%20%D1%80%D0%B0%D0%B7") | |
34 } | 19 } |
35 }; | |
36 | |
37 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; | |
38 function incrementCorrectionsCounter(window) | |
39 { | |
40 let count = typeof(Prefs.corrections_count)!="undefined" && JSON.parse(Prefs.c orrections_count) || 0; | |
41 | |
42 // Only users with 5 URL corrections | |
43 if(++count == 5) | |
44 { | |
45 initSurvey(window); | |
46 } | |
47 | |
48 Prefs.corrections_count = count; | |
49 } | 20 } |
50 | 21 |
51 function initSurvey(window) | 22 function initSurvey() |
52 { | 23 { |
53 // Don't do anything on Fennec. | |
54 if ("Browser" in window || "BrowserApp" in window) | |
55 return; | |
56 | |
57 // Don't ask after 2012-10-15 | 24 // Don't ask after 2012-10-15 |
58 if (Date.now() > 1350259200000) | 25 if (Date.now() > 1350259200000) |
59 return; | 26 return; |
60 | 27 |
61 // Only Firefox users | 28 // Only Firefox users |
62 if (Services.appinfo.ID != "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}") | 29 let {application} = require("info"); |
30 if (application != "firefox") | |
63 return; | 31 return; |
64 | 32 |
65 // Only Firefox 4 and higher | 33 // Only Firefox 4 and higher |
66 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0) | 34 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0) |
67 return; | 35 return; |
68 | 36 |
69 // Survey is only available in English/German/Russian | 37 // Survey is only available in English/German/Russian |
70 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory(" NSILOCALE_CTYPE"))) | 38 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory(" NSILOCALE_CTYPE"))) |
71 return; | 39 return; |
72 surveyLang = RegExp.$1; | 40 surveyLang = RegExp.$1; |
73 | 41 |
74 // Delay survey question by 5 seconds | 42 // Delay survey question by 5 seconds |
75 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 43 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
76 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); | 44 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); |
77 | |
78 win = window; | |
79 } | 45 } |
80 | 46 |
81 function runSurvey() | 47 function runSurvey() |
82 { | 48 { |
83 win.openDialog("chrome://url-fixer/content/survey.xul", "survey", "top=100,lef t=300,chrome,dialog,dependent"); | 49 //open panel |
50 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci. nsIXMLHttpRequest); | |
51 request.open("GET", "chrome://url-fixer/content/survey.xul"); | |
52 request.setRequestHeader("Content-Type", "text/html"); | |
Wladimir Palant
2012/09/28 09:29:34
What's that good for in a non-network request? Rem
| |
53 request.addEventListener("load", function(event) | |
54 { | |
55 let window = Services.wm.getMostRecentWindow("navigator:browser"); | |
56 let document = window.document; | |
57 | |
58 let style = document.createProcessingInstruction('xml-stylesheet', 'href="ch rome://url-fixer/skin/survey.css?' + (new Date().getTime()) + '" type="text/css" '); | |
Wladimir Palant
2012/09/28 09:29:34
Why randomize the URL here? It's a static file, no
| |
59 document.insertBefore(style, document.firstChild); | |
60 | |
61 let panel = new window.DOMParser().parseFromString(request.responseText, "te xt/xml").documentElement; | |
62 if (!document.getElementById(panel.id)) | |
63 { | |
64 document.getElementById("mainPopupSet").appendChild(panel); | |
65 } | |
66 else | |
67 { | |
68 panel = document.getElementById(panel.id); | |
Wladimir Palant
2012/09/28 09:29:34
Our panel is already in the browser document at th
| |
69 } | |
70 panel.querySelector("#icon").setAttribute("src", require("info").addonRoot + "icon64.png"); | |
Wladimir Palant
2012/09/28 09:29:34
If you use unique IDs then you can use document.ge
| |
71 panel.querySelector("#accept-button").addEventListener("click", function() | |
Wladimir Palant
2012/09/28 09:29:34
Don't listen to "click" events, these are mouse-on
| |
72 { | |
Wladimir Palant
2012/09/28 09:29:34
This bracket should not be indented...
| |
73 openSurvey(); | |
74 panel.hidePopup(); | |
75 } | |
76 ); | |
77 panel.querySelector("#cancel-button").addEventListener("click", function() | |
78 { | |
Wladimir Palant
2012/09/28 09:29:34
This bracket should not be indented...
| |
79 panel.hidePopup(); | |
80 } | |
81 ); | |
82 | |
83 let anchor = document.getElementById("identity-box"); | |
84 panel.openPopup(anchor, "after_start", 0, 0, false, true); | |
85 }, false); | |
86 request.send(null); | |
84 } | 87 } |
85 | 88 |
86 exports.openSurvey = openSurvey; | |
87 function openSurvey() | 89 function openSurvey() |
88 { | 90 { |
89 require("appIntegration").getBrowser(win).loadOneTab(surveyUrl + "&lang=" + su rveyLang, { | 91 require("appIntegration").getBrowser(Services.wm.getMostRecentWindow("navigato r:browser")).loadOneTab(surveyUrl + "&lang=" + surveyLang, { |
Wladimir Palant
2012/09/28 09:29:34
Taking over comment from previous review: line too
| |
90 referrerURI: Services.io.newURI("http://url.fixer/", null, null), | 92 referrerURI: Services.io.newURI("http://url.fixer/", null, null), |
91 inBackground: false | 93 inBackground: false |
92 }); | 94 }); |
93 } | 95 } |
94 | |
95 exports.getSurveyDialogTexts = getSurveyDialogTexts; | |
96 function getSurveyDialogTexts() | |
97 { | |
98 return langData[surveyLang]; | |
99 } | |
OLD | NEW |