-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathrateBox.js
More file actions
88 lines (79 loc) · 1.86 KB
/
rateBox.js
File metadata and controls
88 lines (79 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import config from "lib/config";
import template from "views/rating.hbs";
import box from "./box";
function rateBox() {
const $box = box("Did you like the app?", template, strings.cancel).onclick(
onInteract,
);
function onInteract(e) {
/**
* @type {HTMLSpanElement}
*/
const $el = e.target;
if (!$el) return;
let val = $el.getAttribute("value");
if (val) val = Number.parseInt(val);
const siblings = $el.parentElement.children;
const len = siblings.length;
for (let i = 0; i < len; ++i) {
const star = siblings[i];
star.classList.remove("stargrade", "star_outline");
if (i < val) star.classList.add("stargrade");
else star.classList.add("star_outline");
}
setTimeout(() => {
if (val === 5) {
system.openInBrowser(
`https://play.google.com/store/apps/details?id=${BuildInfo.packageName}`,
);
localStorage.dontAskForRating = true;
} else {
const stars = getStars(val);
const subject = "feedback - Acode editor";
const textBody = stars + "</br>%0A" + getFeedbackBody("</br>%0A");
const email = config.FEEDBACK_EMAIL;
system.openInBrowser(
`mailto:${email}?subject=${subject}&body=${textBody}`,
);
}
}, 100);
$box.hide();
}
}
/**
* Gets body for feedback email
* @param {String} eol
* @returns
*/
function getFeedbackBody(eol) {
const buildInfo = window.BuildInfo || {};
const device = window.device || {};
return (
"Version: " +
`${buildInfo.version} (${buildInfo.versionCode})` +
eol +
"Device: " +
(device.model || "") +
eol +
"Manufacturer: " +
(device.manufacturer || "") +
eol +
"Android version: " +
device.version +
eol +
"Info: "
);
}
/**
*
* @param {number} num
*/
function getStars(num) {
let star = num;
let noStar = 5 - num;
let str = "";
while (star--) str += "★";
while (noStar--) str += "☆";
return str;
}
export default rateBox;