From 76c82998b6c6fb1f44a7edae8705316f5c78720a Mon Sep 17 00:00:00 2001 From: edoylol <44335328+edoylol@users.noreply.github.com> Date: Wed, 13 Feb 2019 00:56:26 +0700 Subject: [PATCH 1/5] Add files via upload --- liff-starter.js | 497 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 431 insertions(+), 66 deletions(-) diff --git a/liff-starter.js b/liff-starter.js index 09454ee..dc6226e 100644 --- a/liff-starter.js +++ b/liff-starter.js @@ -1,88 +1,453 @@ window.onload = function (e) { - liff.init(function (data) { - initializeApp(data); + + liff.init(function () { + + getP(); + }); + }; -function initializeApp(data) { - document.getElementById('languagefield').textContent = data.language; - document.getElementById('viewtypefield').textContent = data.context.viewType; - document.getElementById('useridfield').textContent = data.context.userId; - document.getElementById('utouidfield').textContent = data.context.utouId; - document.getElementById('roomidfield').textContent = data.context.roomId; - document.getElementById('groupidfield').textContent = data.context.groupId; - - // openWindow call - document.getElementById('openwindowbutton').addEventListener('click', function () { - liff.openWindow({ - url: 'https://line.me' +function getP(){ + + var tipe = getParameterByName('type') + + if (!tipe) { + + document.getElementById('textx').addEventListener('click', function () { + + liff.sendMessages([{ + + type: 'text', + + text: atob('You've successfully sent a message! Hooray!') + + }]).then(function () { + + liff.closeWindow(); + + }); + + }); + + document.getElementById('imagex').addEventListener('click', function () { + + liff.sendMessages([{ + + type: 'text', + + text: atob('You've successfully sent a message! Hooray!') + + }]).then(function () { + + liff.closeWindow(); + + }); + + }); + + document.getElementById('videox').addEventListener('click', function () { + + liff.sendMessages([{ + + type: 'text', + + text: atob('You've successfully sent a message! Hooray!') + + }]).then(function () { + + liff.closeWindow(); + + }); + + }); + + document.getElementById('audiox').addEventListener('click', function () { + + liff.sendMessages([{ + + type: 'text', + + text: atob('You've successfully sent a message! Hooray!') + + }]).then(function () { + + liff.closeWindow(); + + }); + + }); + + document.getElementById('stickerx').addEventListener('click', function () { + + liff.sendMessages([{ + + type: 'text', + + text: atob('You've successfully sent a message! Hooray!=') + + }]).then(function () { + + liff.closeWindow(); + + }); + + }); + + } else { + + makeText(); + + makeImage(); + + makeVideo(); + + makeAudio(); + + makeSticker(); + + textFooter(); + + imageFooter(); + + meProfile(); + + Profil_e(); + + flexText(); + + bigImage(); + + } + + } + +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(){ + + 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.closeWindow(); + }); - }); - // closeWindow call - document.getElementById('closewindowbutton').addEventListener('click', function () { - liff.closeWindow(); }); - // sendMessages call - document.getElementById('sendmessagebutton').addEventListener('click', function () { +} + +function makeText(){ + + var tipe = getParameterByName('type'); + + if (tipe === 'text') { + liff.sendMessages([{ + type: 'text', - text: "You've successfully sent a message! Hooray!" - }, { - type: 'sticker', - packageId: '2', - stickerId: '144' + + text: getParameterByName('text') + }]).then(function () { - window.alert("Message sent"); - }).catch(function (error) { - window.alert("Error sending message: " + error); + + liff.closeWindow(); + }); - }); - // get access token - document.getElementById('getaccesstoken').addEventListener('click', function () { - const accessToken = liff.getAccessToken(); - document.getElementById('accesstokenfield').textContent = accessToken; - toggleAccessToken(); - }); + } + +} + +function makeImage(){ + + var tipe = getParameterByName('type'); + + if (tipe === 'image') { + + liff.sendMessages([{ + + type: 'image', + + originalContentUrl: getParameterByName('img'), + + previewImageUrl: getParameterByName('img') + + }]).then(function () { + + liff.closeWindow(); - // get profile call - document.getElementById('getprofilebutton').addEventListener('click', function () { - liff.getProfile().then(function (profile) { - document.getElementById('useridprofilefield').textContent = profile.userId; - document.getElementById('displaynamefield').textContent = profile.displayName; - - const profilePictureDiv = document.getElementById('profilepicturediv'); - if (profilePictureDiv.firstElementChild) { - profilePictureDiv.removeChild(profilePictureDiv.firstElementChild); - } - const img = document.createElement('img'); - img.src = profile.pictureUrl; - img.alt = "Profile Picture"; - profilePictureDiv.appendChild(img); - - document.getElementById('statusmessagefield').textContent = profile.statusMessage; - toggleProfileData(); - }).catch(function (error) { - window.alert("Error getting profile: " + error); }); - }); + + } + } -function toggleAccessToken() { - toggleElement('accesstokendata'); +function makeVideo(){ + + var tipe = getParameterByName('type'); + + if (tipe === 'video') { + + liff.sendMessages([{ + + type: 'video', + + originalContentUrl: getParameterByName('ocu'), + + previewImageUrl: getParameterByName('piu') + + }]).then(function () { + + liff.closeWindow(); + + }); + + } + } -function toggleProfileData() { - toggleElement('profileinfo'); +function makeAudio(){ + + var tipe = getParameterByName('type'); + + if (tipe === 'audio') { + + liff.sendMessages([{ + + type: 'audio', + + originalContentUrl: getParameterByName('link'), + + duration: 60000 + + }]).then(function () { + + liff.closeWindow(); + + }); + + } + } -function toggleElement(elementId) { - const elem = document.getElementById(elementId); - if (elem.offsetWidth > 0 && elem.offsetHeight > 0) { - elem.style.display = "none"; - } else { - elem.style.display = "block"; +function makeSticker(){ + + var tipe = getParameterByName('type'); + + if (tipe === 'sticker') { + + var stk = getParameterByName('stk'); + + var sid = getParameterByName('sid'); + + var pkg = getParameterByName('pkg'); + + var ep = ''; + + if (stk === 'anim') { + + ep = "/IOS/sticker_animation@2x.png"; + + } else { + + ep = "/IOS/sticker@2x.png"; + + } + + liff.sendMessages([{ + + type: "template", + + altText: "Sticker", + + template: { + + type: "image_carousel", + + columns: [{ + + imageUrl: "https://stickershop.line-scdn.net/stickershop/v1/sticker/"+sid+ep, + + action: { + + type: "uri", + + uri: "line://shop/sticker/detail/"+pkg}} + + ] + + } + + }]).then(function () { + + liff.closeWindow(); + + }); + } -} \ No newline at end of file + +} + +function textFooter(){ + + var tipe = getParameterByName('type'); + + liff.getProfile().then(function (prof) { + + var teks = getParameterByName('text'); + + if (tipe === 'fotext') { + + liff.sendMessages([{ + + type: 'text', + + text: getParameterByName('text'), + + sentBy: { + + label: prof.displayName, + + iconUrl: prof.pictureUrl, + + linkUrl: "line://app/1636361179-N9dnRpYg?type=fotext&text="+encodeURI(teks)} + + }]).then(function () { + + liff.closeWindow(); + + }); + + } + + }); + +} + +function imageFooter(){ + + var tipe = getParameterByName('type'); + + liff.getProfile().then(function (prof) { + + if (tipe === 'foimage') { + + liff.sendMessages([{ + + type: 'image', + + originalContentUrl: getParameterByName('img'), + + previewImageUrl: getParameterByName('img'), + + sentBy: { + + label: prof.displayName, + + iconUrl: prof.pictureUrl, + + linkUrl: "line://app/1636361179-N9dnRpYg?type=foimage&img="+getParameterByName('img')} + + }]).then(function () { + + liff.closeWindow(); + + }); + + } + + }); + +} + +function meProfile(){ + + var tipe = getParameterByName('type'); + + liff.getProfile().then(function (prof) { + + var stat = prof.statusMessage; + + if (stat == null) { + + var stat = " - "; + + } + + if (stat.length > 60) { + + var stat = "Status Message is too long! Max 60 words"; + + } + + if (tipe === 'profile') { + + liff.sendMessages([{ + + type: "template", + + altText: "Profile "+prof.displayName, + + template: { + + type: "buttons", + + thumbnailImageUrl: prof.pictureUrl, + + imageAspectRatio: "square", + + imageSize: "cover", + + title: prof.displayName, + + text: stat, + + actions: [ + + { + + type:"uri", + + label:"Me", + + uri:"line://app/1581589150-le0GNepN?type=profile" + + } + + ] + + } + + }]).then(function () { + + liff.closeWindow(); + + }); + + } + + }); + +} From 6189d0a1a588c886e1d1641b97f4bb52d4333d59 Mon Sep 17 00:00:00 2001 From: edoylol <44335328+edoylol@users.noreply.github.com> Date: Wed, 13 Feb 2019 00:57:42 +0700 Subject: [PATCH 2/5] Add files via upload --- index.html | 90 ++++-------------------- style.css | 201 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 193 insertions(+), 98 deletions(-) diff --git a/index.html b/index.html index ef3cec0..b2b5404 100644 --- a/index.html +++ b/index.html @@ -1,84 +1,24 @@
+ -| language | -- |
|---|---|
| context.viewType | -- |
| context.userId | -- |
| context.utouId | -- |
| context.roomId | -- |
| context.groupId | -- |