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 = null; //"http://urlfixer.org/usersurvey/..."; |
12 | |
13 let langData = { | |
14 en: { | |
15 title: "Tell us your opinion", | |
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.", | |
17 note: "This is a one-time message and will not appear again.", | |
18 accept: "Take the survey", | |
19 decline: "Maybe some other time" | |
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%D0%B4%D0%B5%D0%BB%D0%B8%D1%82%D0%B5%
D1%81%D1%8C%20%D1%81%20%D0%BD%D0%B0%D0%BC%D0%B8%20%D1%81%D0%B2%D0%BE%D0%B8%D0%BC
%20%D0%BC%D0%BD%D0%B5%D0%BD%D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D%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 } | |
35 }; | |
36 | 11 |
37 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; | 12 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; |
38 function incrementCorrectionsCounter(window) | 13 function incrementCorrectionsCounter() |
39 { | 14 { |
40 let count = typeof(Prefs.corrections_count)!="undefined" && JSON.parse(Prefs.c
orrections_count) || 0; | 15 // Only if survey exists |
| 16 if (!surveyUrl) |
| 17 return; |
41 | 18 |
42 // Only users with 5 URL corrections | 19 // Only users with 5 URL corrections |
43 if(++count == 5) | 20 if (++Prefs.corrections_count == 5) |
44 { | 21 { |
45 initSurvey(window); | 22 initSurvey(); |
46 } | 23 } |
47 | |
48 Prefs.corrections_count = count; | |
49 } | 24 } |
50 | 25 |
51 function initSurvey(window) | 26 function initSurvey() |
52 { | 27 { |
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 | 28 // Don't ask after 2012-10-15 |
58 if (Date.now() > 1350259200000) | 29 if (Date.now() > 1350259200000) |
59 return; | 30 return; |
60 | 31 |
61 // Only Firefox users | 32 // Only Firefox users |
62 if (Services.appinfo.ID != "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}") | 33 let {application} = require("info"); |
| 34 if (application != "firefox") |
63 return; | 35 return; |
64 | 36 |
65 // Only Firefox 4 and higher | 37 // Only Firefox 4 and higher |
66 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0) | 38 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0) |
67 return; | 39 return; |
68 | 40 |
69 // Survey is only available in English/German/Russian | 41 // Survey is only available in English/German/Russian |
70 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory("
NSILOCALE_CTYPE"))) | 42 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory("
NSILOCALE_CTYPE"))) |
71 return; | 43 return; |
72 surveyLang = RegExp.$1; | 44 surveyLang = RegExp.$1; |
73 | 45 |
74 // Delay survey question by 5 seconds | 46 // Delay survey question by 5 seconds |
75 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 47 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
76 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); | 48 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); |
77 | |
78 win = window; | |
79 } | 49 } |
80 | 50 |
81 function runSurvey() | 51 function runSurvey() |
82 { | 52 { |
83 win.openDialog("chrome://url-fixer/content/survey.xul", "survey", "top=100,lef
t=300,chrome,dialog,dependent"); | 53 //open panel |
| 54 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.
nsIXMLHttpRequest); |
| 55 request.open("GET", "chrome://url-fixer/content/survey.xul"); |
| 56 request.addEventListener("load", function(event) |
| 57 { |
| 58 let window = Services.wm.getMostRecentWindow("navigator:browser"); |
| 59 let document = window.document; |
| 60 |
| 61 let style = document.createProcessingInstruction('xml-stylesheet', 'href="ch
rome://url-fixer/skin/survey.css" type="text/css"'); |
| 62 document.insertBefore(style, document.firstChild); |
| 63 |
| 64 let panel = new window.DOMParser().parseFromString(request.responseText, "te
xt/xml").documentElement; |
| 65 let oldPanel = document.getElementById(panel.id); |
| 66 if (oldPanel) |
| 67 oldPanel.parentNode.removeChild(oldPanel); |
| 68 document.getElementById("mainPopupSet").appendChild(panel); |
| 69 document.getElementById("url-fixer-icon").setAttribute("src", require("info"
).addonRoot + "icon64.png"); |
| 70 document.getElementById("url-fixer-accept-button").addEventListener("command
", function() |
| 71 { |
| 72 openSurvey(); |
| 73 panel.hidePopup(); |
| 74 }); |
| 75 document.getElementById("url-fixer-cancel-button").addEventListener("command
", function() |
| 76 { |
| 77 panel.hidePopup(); |
| 78 }); |
| 79 panel.addEventListener("popuphidden", function() |
| 80 { |
| 81 panel.parentNode.removeChild(panel); |
| 82 style.parentNode.removeChild(style); |
| 83 }); |
| 84 |
| 85 let anchor = document.getElementById("identity-box"); |
| 86 panel.openPopup(anchor, "after_start", 0, 0, false, true); |
| 87 }, false); |
| 88 request.send(null); |
84 } | 89 } |
85 | 90 |
86 exports.openSurvey = openSurvey; | |
87 function openSurvey() | 91 function openSurvey() |
88 { | 92 { |
89 require("appIntegration").getBrowser(win).loadOneTab(surveyUrl + "&lang=" + su
rveyLang, { | 93 let window = Services.wm.getMostRecentWindow("navigator:browser"); |
90 referrerURI: Services.io.newURI("http://url.fixer/", null, null), | 94 if (window) |
91 inBackground: false | 95 { |
92 }); | 96 let browser = require("appIntegration").getBrowser(window); |
| 97 browser.loadOneTab(surveyUrl + "&lang=" + surveyLang, { |
| 98 referrerURI: Services.io.newURI("http://url.fixer/", null, null), |
| 99 inBackground: false |
| 100 }); |
| 101 } |
93 } | 102 } |
94 | |
95 exports.getSurveyDialogTexts = getSurveyDialogTexts; | |
96 function getSurveyDialogTexts() | |
97 { | |
98 return langData[surveyLang]; | |
99 } | |
OLD | NEW |