-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (86 loc) · 2.89 KB
/
index.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Import stylesheets
import "./style.css"
// Body element
const body = document.getElementById('body')
// Button elements
const btnSend = document.getElementById("btnSend")
const btnClose = document.getElementById("btnClose")
const btnShare = document.getElementById("btnShare")
const btnLogIn = document.getElementById("btnLogIn")
const btnLogOut = document.getElementById("btnLogOut")
const btnScanCode = document.getElementById("btnScanCode")
const btnOpenWindow = document.getElementById("btnOpenWindow")
// Profile elements
const email = document.getElementById("email")
const userId = document.getElementById("userId")
const pictureUrl = document.getElementById("pictureUrl")
const displayName = document.getElementById("displayName")
const statusMessage = document.getElementById("statusMessage")
// QR element
const code = document.getElementById("code")
const friendShip = document.getElementById("friendShip")
async function main() {
// Initialize LIFF app)
await liff.init({ liffId: "xxxxxxx" })
// Try a LIFF function Check open OS
//switch (liff.getOS()) {
// case "android": body.style.backgroundColor = "#d1f5d3"; break
// case "ios": body.style.backgroundColor = "#eeeeee"; break
// case "web": body.style.backgroundColor = "#eeefff"; break
//}
// call function get user profile
getUserProfile() // move
btnShare.style.display = "block"
btnSend.style.display = "block"
btnScanCode.style.display = "block"
btnOpenWindow.style.display = "block"
btnShare.onclick = () => {
shareMsg()
}
btnSend.onclick = () => {
sendMsg()
}
btnScanCode.onclick = () => {
scanCode()
}
btnOpenWindow.onclick = () => {
liff.openWindow({
url: window.location.href,
external: true
})
}
}
main()
async function getUserProfile() {
const profile = await liff.getProfile()
pictureUrl.src = profile.pictureUrl
userId.innerHTML = "<b>userId:</b> " + profile.userId
statusMessage.innerHTML = "<b>statusMessage:</b> " + profile.statusMessage
displayName.innerHTML = "<b>displayName:</b> " + profile.displayName
// add show email
email.innerHTML = "<b>email:</b> " + liff.getDecodedIDToken().email
}
async function sendMsg() {
if (liff.getContext().type !== "none" && liff.getContext().type !== "external") {
await liff.sendMessages([
{
"type": "text",
"text": "test message "
}
])
alert(" test send message")
}
}
async function shareMsg() {
await liff.shareTargetPicker([
{
type: "image",
originalContentUrl: "https://d.line-scdn.net/stf/line-lp/2016_en_02.jpg",
previewImageUrl: "https://d.line-scdn.net/stf/line-lp/2016_en_02.jpg"
}
])
}
async function scanCode() {
const result = await liff.scanCode()
code.innerHTML = "<b>Code: </b>" + result.value
}