-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
154 lines (140 loc) · 5.28 KB
/
index.html
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover">
<title>My LIFF App</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<p id="os"><b>OS:</b> </p>
<p id="language"><b>Language:</b> </p>
<p id="version"><b>Version:</b> </p>
<p id="isInClient"><b>isInClient:</b> </p>
<p id="accessToken"><b>AccessToken:</b> </p>
<img id="pictureUrl">
<p id="userId"><b>userId:</b> </p>
<p id="displayName"><b>displayName:</b> </p>
<p id="statusMessage"><b>statusMessage:</b> </p>
<p id="decodedIDToken"><b>email:</b> </p>
<p id="idToken"><b>ID Token:</b> </p>
<p id="type"><b>type:</b> </p>
<p id="viewType"><b>viewType:</b> </p>
<p id="utouId"><b>utouId:</b> </p>
<p id="roomId"><b>roomId:</b> </p>
<p id="groupId"><b>groupId:</b> </p>
<p id="friendship"><b>isFriendship:</b> </p>
<p id="scanCode"><b>Code:</b> </p>
<p id="isLoggedIn"><b>isLoggedIn:</b> </p>
<p id="universalLink1"><b>Universal Link:</b> </p>
<p id="universalLink2"><b>Universal Link with Query params:</b> </p>
<p><a href="https://jirawatee.github.io/liff/path/?param=1">Link to Path</a></p>
<button id="btnMsg" onclick="sendMsg()">Send Message</button>
<button id="btnShare" onclick="shareMsg()">Share Target Picker</button>
<button onclick="openWindow()">Open Window</button>
<button id="btnScanCode" onclick="scanCode()">Scan Code</button>
<button id="btnLogOut" onclick="logOut()">Log Out</button>
<button id="btnClose" onclick="closed()">Close</button>
<script src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
<script>
function createUniversalLink() {
const link1 = liff.permanentLink.createUrl()
document.getElementById("universalLink1").append(link1)
liff.permanentLink.setExtraQueryParam('param=9')
const link2 = liff.permanentLink.createUrl()
document.getElementById("universalLink2").append(link2)
}
async function shareMsg() {
await liff.shareTargetPicker([
{
type: "text",
text: "This message was sent by ShareTargetPicker"
}
])
}
function logOut() {
liff.logout()
window.location.reload()
}
function closed() {
liff.closeWindow()
}
async function scanCode() {
const result = await liff.scanCode()
document.getElementById("scanCode").append(result.value)
}
function openWindow() {
liff.openWindow({
url: "https://line.me",
external: true
})
}
async function getFriendship() {
const friend = await liff.getFriendship()
document.getElementById("friendship").append(friend.friendFlag)
if (!friend.friendFlag) {
if (confirm("คุณยังไม่ได้เพิ่ม Bot เป็นเพื่อน จะเพิ่มเลยไหม?")) {
window.location = "https://line.me/R/ti/p/@178yfyoa"
}
}
}
async function sendMsg() {
if (liff.getContext().type !== "none") {
await liff.sendMessages([
{
"type": "sticker",
"stickerId": 1,
"packageId": 1
}
])
alert("Message sent")
}
}
function getContext() {
document.getElementById("type").append(liff.getContext().type)
document.getElementById("viewType").append(liff.getContext().viewType)
document.getElementById("utouId").append(liff.getContext().utouId)
document.getElementById("roomId").append(liff.getContext().roomId)
document.getElementById("groupId").append(liff.getContext().groupId)
}
async function getUserProfile() {
const profile = await liff.getProfile()
document.getElementById("pictureUrl").src = profile.pictureUrl
document.getElementById("userId").append(profile.userId)
document.getElementById("statusMessage").append(profile.statusMessage)
document.getElementById("displayName").append(profile.displayName)
document.getElementById("decodedIDToken").append(liff.getDecodedIDToken().email)
document.getElementById("idToken").append(liff.getIDToken())
}
function getEnvironment() {
document.getElementById("os").append(liff.getOS())
document.getElementById("language").append(liff.getLanguage())
document.getElementById("version").append(liff.getVersion())
document.getElementById("accessToken").append(liff.getAccessToken())
document.getElementById("isInClient").append(liff.isInClient())
if (liff.isInClient()) {
document.getElementById("btnLogOut").style.display = "none"
} else {
document.getElementById("btnMsg").style.display = "none"
document.getElementById("btnScanCode").style.display = "none"
document.getElementById("btnClose").style.display = "none"
}
}
async function main() {
liff.ready.then(() => {
document.getElementById("isLoggedIn").append(liff.isLoggedIn())
if (liff.isLoggedIn()) {
getEnvironment()
getUserProfile()
getContext()
getFriendship()
createUniversalLink()
} else {
liff.login()
}
})
await liff.init({ liffId: "1653832360-w6QkQpV4" })
}
main()
</script>
</body>
</html>