Skip to content

Commit c7dee81

Browse files
committed
Add questionnaire after uninstalled (#101)
1 parent 590421c commit c7dee81

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/background/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import VersionManager from "./version-manager"
1515
import ActiveTabListener from "./active-tab-listener"
1616
import badgeTextManager from "./badge-text-manager"
1717
import metaService from "@service/meta-service"
18+
import UninstallListener from "./uninstall-listener"
1819

1920
// Open the log of console
2021
openLog()
@@ -46,4 +47,8 @@ new ActiveTabListener()
4647
.listen()
4748

4849
// Collect the install time
49-
chrome.runtime.onInstalled.addListener(detail => detail.reason === "install" && metaService.updateInstallTime(new Date()))
50+
chrome.runtime.onInstalled.addListener(async detail => {
51+
detail.reason === "install" && await metaService.updateInstallTime(new Date())
52+
// Questionnaire for uninstall
53+
new UninstallListener().listen()
54+
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (c) 2022 Hengyang Zhang
3+
*
4+
* This software is released under the MIT License.
5+
* https://opensource.org/licenses/MIT
6+
*/
7+
8+
import metaService from "@service/meta-service"
9+
import { UNINSTALL_QUESTIONNAIRE } from "@util/constant/url"
10+
import { locale } from "@util/i18n"
11+
12+
/**
13+
* The percentage for gray
14+
*/
15+
const GRAY_PERCENTAGE = 20
16+
17+
function judgeGray(timeRand: Date) {
18+
if (!timeRand) {
19+
return false
20+
}
21+
return timeRand.getTime() % 100 < GRAY_PERCENTAGE
22+
}
23+
24+
async function listen() {
25+
try {
26+
const installTime = await metaService.getInstallTime()
27+
const uninstallUrl = UNINSTALL_QUESTIONNAIRE[locale]
28+
uninstallUrl && judgeGray(installTime) && chrome.runtime.setUninstallURL(uninstallUrl)
29+
} catch (e) {
30+
console.error(e)
31+
}
32+
}
33+
34+
/**
35+
* @since 0.9.6
36+
*/
37+
export default class UninstallListener {
38+
listen = listen
39+
}

src/util/constant/url.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export const FEEDBACK_QUESTIONNAIRE: Partial<{ [locale in Timer.Locale]: string
5555
en: 'https://docs.google.com/forms/d/e/1FAIpQLSdNq4gnSY7uxYkyqOPqyYF3Bqlc3ZnWCLDi5DI5xGjPeVCNiw/viewform?usp=sf_link',
5656
}
5757

58+
/**
59+
* @since 0.9.6
60+
*/
61+
export const UNINSTALL_QUESTIONNAIRE: { [locale in Timer.Locale]: string } = {
62+
zh_CN: 'https://www.wjx.cn/vj/YDgY9Yz.aspx',
63+
zh_TW: 'https://docs.google.com/forms/d/e/1FAIpQLSdK93q-548dK-2naoS3DaArdc7tEGoUY9JQvaXP5Kpov8h6-A/viewform?usp=sf_link',
64+
ja: 'https://docs.google.com/forms/d/e/1FAIpQLSdsB3onZuleNf6j7KJJLbcote647WV6yeUr-9m7Db5QXakfpg/viewform?usp=sf_link',
65+
en: 'https://docs.google.com/forms/d/e/1FAIpQLSflhZAFTw1rTUjAEwgxqCaBuhLBBthwEK9fIjvmwWfITLSK9A/viewform?usp=sf_link'
66+
}
67+
5868
/**
5969
* The page of extension detail
6070
* @since 0.1.8

0 commit comments

Comments
 (0)