-
Notifications
You must be signed in to change notification settings - Fork 3
/
liff-starter.js
143 lines (132 loc) · 5.06 KB
/
liff-starter.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
window.onload = function (e) {
liff.init(function () {
getProfile();
getP();
});
};
function toggleModal() {
var modal = document.querySelector(".modal");
var closeButton = document.querySelector(".close-button");
modal.classList.toggle("show-modal");
}
function windowOnClick(event) {
var modal = document.querySelector(".modal");
var closeButton = document.querySelector(".close-button");
if (event.target === modal) {
toggleModal();
}
}
function getP(){
var tipe = getParameterByName('type')
liff.sendMessages([{
type: "text",
text: "Quick",
quickReply: {
items: [
{
type: "action",
imageUrl:"https://www.example.com/a.png",
action: {
type: "cameraRoll",
label: "Send photo",
text:"send photo"
}
},
{
type: "action",
imageUrl:"https://www.example.com/a.png",
action: {
type: "camera",
label: "Open camera"
}
}
]
}}]).then(function () {
liff.closeWindow();
});
if (!tipe) {
var modal = document.querySelector(".modal");
var closeButton = document.querySelector(".close-button");
toggleModal();
closeButton.addEventListener("click", toggleModal);
window.addEventListener("click", windowOnClick);
document.getElementById('home').src = 'bg.jpg';
document.getElementById('fdata').textContent = 'Penggunaan: --> kirim ke chat format link seperti berikut --> line://app/1601769611-NVKq2lMZ?type=anim&pkgid=1234&stkid=1234,1235,1236 --> Note: Tidak untuk room square --> type=anim untuk sticker bergerak --> type=sttic untuk sticker tak bergerak dan popup --> pkgid=PackageID --> stkid=StickerID dalam bentuk list separator koma';
} else {
makeList();
}
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function getProfile(){
// https://developers.line.me/ja/reference/liff/#liffgetprofile()
liff.getProfile().then(function (profile) {
document.getElementById('userid').textContent = 'Hai ' + profile.displayName;
document.getElementById('main').src = profile.pictureUrl;
document.getElementById('close').addEventListener('click', function () {
liff.openWindow({
url: 'line://app/1570947238-9OaV05mK'
});
//liff.closeWindow();
});
});
}
function makeList(){
var tipe = getParameterByName('type');
var stri = getParameterByName('stkid');
var pkgi = getParameterByName('pkgid');
var isi = stri.split(',');
var ep = '';
var i;
document.getElementById('desk').textContent = 'Klik pada Gambar di Bawah untuk Mengirim Stiker';
if (tipe !== 'anim' && pkgi!=='1' && pkgi!=='3' && pkgi!=='4' && pkgi!=='5') {
ep = '/IOS/[email protected]';
} else if (tipe !== 'anim' || pkgi==='1' || pkgi==='3' || pkgi==='4' || pkgi==='5') {
ep = "/ANDROID/sticker.png";
} else if (tipe === 'anim'){
ep = "/IOS/[email protected]";
} else {
ep = "/IOS/[email protected]";
}
for (i = 0; i < isi.length; i++) {
//var a = document.createElement('a');
var a = document.createElement("img");
const idstk = isi[i]
a.id = 'imag';
a.src = 'https://stickershop.line-scdn.net/stickershop/v1/sticker/'+isi[i]+ep;
a.addEventListener('click', function () {
liff.sendMessages([{
type: "template",
altText: "Sticker",
template: {
type: "image_carousel",
columns: [{
imageUrl: "https://stickershop.line-scdn.net/stickershop/v1/sticker/"+idstk+ep,
action: {
type: "uri",
uri: "line://shop/sticker/detail/"+getParameterByName('pkgid')}}
]
}
}]).then(function () {
liff.closeWindow();
});
});
document.body.appendChild(a)
};
}
// closeWindow call
//function toggleProfileData() {
// var elem = document.getElementById('profileinfo');
// if (elem.offsetWidth > 0 && elem.offsetHeight > 0) {
// elem.style.display = "none";
// } else {
// elem.style.display = "block";
// }
//}