LineLiff/liff-starter.js
2022-12-13 12:24:21 +08:00

221 lines
5.9 KiB
JavaScript

window.onload = function (_0xe315c8) {
liff
.init({
liffId: '1657715144-m4W6lyjL', // Use own liffId
})
.then(() => {
if (!liff.isLoggedIn()) {
liff.login();
} else {
getP();
}
});
};
function getP() {
var type = getParameterByName("type");
if (!type) {
document.getElementById("textx").addEventListener("click", function () {
const data = [{
type: "text",
"text": atob("bGluZTovL2FwcC8xNTk5NzA2MzkxLVh3a0JMNzg5P3R5cGU9dGV4dCZ0ZXh0PVlvdXIlMjBUZXh0DQoNCnR5cGUgPT4gdGV4dA0KdGV4dCA9PiB5b3VyIHRleHQ=")
}];
sendMessages(data);
});
document.getElementById("imagex").addEventListener("click", function () {
const data = [{
"type": "text",
"text": ("https://liff.line.me/1657715144-m4W6lyjL?type=image&img=https://wallpaperstudio10.com/static/wpdb/wallpapers/1000x563/168891.jpg\n\ntype => image\nimg => Link (must be HTTPS)")
}];
sendMessages(data);
});
document.getElementById("videox").addEventListener("click", function () {
const data = [{
"type": "text",
"text": ("https://liff.line.me/1657715144-m4W6lyjL?type=video&ocu=https://tinyurl.com/y8og3or5&piu=https://images6.alphacoders.com/710/thumb-350-710132.png\n\ntype => video\nocu => video url\npiu => preview image")
}];
sendMessages(data);
});
document.getElementById("audiox").addEventListener("click", function () {
const data = [{
"type": "text",
"text": ("https://liff.line.me/1657715144-m4W6lyjL?type=audio&link=https://platelets.fun/public/sounds/music.mp3")
}];
sendMessages(data);
});
document.getElementById("stickerx").addEventListener("click", function () {
const data = [{
"type": "text",
"text": ("With Animation:\nhttps://liff.line.me/1657715144-m4W6lyjL?type=sticker&stk=anim&sid=32128231&pkg=3099312\n\nNo Animation:\nhttps://liff.line.me/1657715144-m4W6lyjL?type=sticker&stk=noanim&sid=32128231&pkg=3099312\n\ntype => sticker\nstk => anim / noanim\nsid => sticker id\npkg => packages id")
}];
sendMessages(data);
});
} else {
makeText();
makeImage();
makeVideo();
makeAudio();
makeSticker();
meProfile();
}
}
function getParameterByName(stringParam, window_href) {
const URLscheme = {};
let urlsearch = window.location.search;
if (urlsearch.indexOf("?") !== -1) {
let str = urlsearch.substring(1);
let strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
URLscheme[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
}
}
return URLscheme[stringParam];
}
function getProfile() {
liff.getProfile().then(function (data) {
document.getElementById("userid").textContent = "Hai " + data.displayName;
document.getElementById("main").src = data.pictureUrl;
document.getElementById("close").addEventListener("click", function () {
liff.closeWindow();
});
});
}
function makeText() {
var type = getParameterByName("type");
if (type === "text") {
const data = [{
"type": "text",
"text": getParameterByName("text")
}];
sendMessages(data);
}
}
function makeImage() {
var type = getParameterByName("type");
if (type === "image") {
const data = [{
"type": "image",
"originalContentUrl": getParameterByName("img"),
"previewImageUrl": getParameterByName("img")
}];
sendMessages(data);
}
}
function makeVideo() {
var type = getParameterByName("type");
if (type === "video") {
const data = [{
"type": "video",
"originalContentUrl": getParameterByName("ocu"),
"previewImageUrl": getParameterByName("piu")
}];
sendMessages(data);
}
}
function makeAudio() {
var type = getParameterByName("type");
if (type === "audio") {
const data = [{
"type": "audio",
"originalContentUrl": getParameterByName("link"),
"duration": 60000
}];
sendMessages(data);
}
}
function makeSticker() {
var type = getParameterByName("type");
if (type === "sticker") {
var stk = getParameterByName("stk");
var sid = getParameterByName("sid");
var pkg = getParameterByName("pkg");
var pngtype = "";
if (stk === "anim") {
pngtype = "/IOS/sticker_animation@2x.png";
} else {
pngtype = "/IOS/sticker@2x.png";
}
const data = [{
"type": "template",
"altText": "Sticker",
"template": {
"type": "image_carousel",
"columns": [{
"imageUrl": "https://stickershop.line-scdn.net/stickershop/v1/sticker/" + sid + pngtype,
"action": {
"type": "uri",
"uri": "line://shop/sticker/detail/" + pkg
}
}]
}
}];
sendMessages(data);
}
}
function meProfile() {
var type = getParameterByName("type");
liff.getProfile().then(function (data) {
var statusMessage = data.statusMessage;
if (statusMessage == null) {
var statusMessage = "";
}
if (statusMessage.length > 60) {
var statusMessage = "Status Message is to long! Max 60 words";
}
if (type === "profile") {
const data = [{
"type": "template",
"altText": "Profile " + data.displayName,
"template": {
"type": "buttons",
"thumbnailImageUrl": data.pictureUrl,
"imageAspectRatio": "square",
"imageSize": "cover",
"title": data.displayName,
"text": statusMessage,
"actions": [{
"type": "uri",
"label": "Me",
"uri": "https://liff.line.me/1657715144-m4W6lyjL?type=profile"
}]
}
}];
sendMessages(data);
}
});
}
function sendMessages(data) {
if (liff.isInClient()) {
liff.sendMessages(data).then(function () {
liff.closeWindow();
}).catch(function (error) {
console.error(`[Line] textx: ${error}`);
document.getElementById("error").innerHTML = `[Line] textx: ${error}`;
});
} else {
if (liff.isApiAvailable("shareTargetPicker")) {
liff.shareTargetPicker(data).then(function (res) {
liff.closeWindow();
}).catch(function (error) {
console.error(`[Line] textx: ${error}`);
document.getElementById("error").innerHTML = `[Line] textx: ${error}`;
});
} else {
document.getElementById("error").innerHTML = `你的 LINE App 暫時不支援 Share Target Picker`;
}
}
}