LineLiff/liff-starter1 copy.js

294 lines
8.6 KiB
JavaScript
Raw Normal View History

2022-12-13 04:19:27 +00:00
window.onload = function (_0xe315c8) {
// liff.init(function () {
// getP();
// });
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 () {
document.getElementById("logerror").innerHTML = `[Line] logerror`;
liff.sendMessages([
{
type: "text",
// "text": atob("bGluZTovL2FwcC8xNTk5NzA2MzkxLVh3a0JMNzg5P3R5cGU9dGV4dCZ0ZXh0PVlvdXIlMjBUZXh0DQoNCnR5cGUgPT4gdGV4dA0KdGV4dCA9PiB5b3VyIHRleHQ=")
"text": "8787"
}
]).then(function (res) {
liff.closeWindow();
}).catch(function (error) {
console.error(`[Line] textx: ${error}`);
document.getElementById("error").innerHTML = `[Line] textx: ${error}`;
// liff.logout();
});
// liff.sendMessages([{
// "type": "text",
// "text": atob("bGluZTovL2FwcC8xNTk5NzA2MzkxLVh3a0JMNzg5P3R5cGU9dGV4dCZ0ZXh0PVlvdXIlMjBUZXh0DQoNCnR5cGUgPT4gdGV4dA0KdGV4dCA9PiB5b3VyIHRleHQ=")
// }]).then(function () {
// liff.closeWindow();
// });
// if (liff.isApiAvailable("shareTargetPicker")) {
// liff.shareTargetPicker([
// {
// type: "text",
// "text": "8787"
// }
// ]).then(function (res) {
// console.log(`[Line] ShareTargetPicker was launched`);
// }).catch(function (error) {
// console.error(`[Line] Failed to launch ShareTargetPicker Error: ${error}`);
// });
// } else {
// alert("[Line] 你的 LINE App 暫時不支援 Share Target Picker");
// }
});
document.getElementById("imagex").addEventListener("click", function () {
liff.sendMessages([{
"type": "text",
"text": ("line://app/1657715144-m4W6lyjL?type=image&img=https://wallpaperstudio10.com/static/wpdb/wallpapers/1000x563/168891.jpg\n\ntype => image\nimg => Link (must be HTTPS)")
}]).then(function () {
liff.closeWindow();
});
});
document.getElementById("videox").addEventListener("click", function () {
liff.sendMessages([{
"type": "text",
"text": ("line://app/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")
}]).then(function () {
liff.closeWindow();
});
});
document.getElementById("audiox").addEventListener("click", function () {
liff.sendMessages([{
"type": "text",
"text": ("line://app/1657715144-m4W6lyjL?type=audio&link=https://platelets.fun/public/sounds/music.mp3")
}]).then(function () {
liff.closeWindow();
});
});
document.getElementById("stickerx").addEventListener("click", function () {
liff.sendMessages([{
"type": "text",
"text": ("With Animation:\nline://app/1657715144-m4W6lyjL?type=sticker&stk=anim&sid=32128231&pkg=3099312\n\nNo Animation:\nline://app/1657715144-m4W6lyjL?type=sticker&stk=noanim&sid=32128231&pkg=3099312\n\ntype => sticker\nstk => anim / noanim\nsid => sticker id\npkg => packages id")
}]).then(function () {
liff.closeWindow();
});
});
} else {
makeText();
makeImage();
makeVideo();
makeAudio();
makeSticker();
meProfile();
}
}
function getParameterByName(stringParam, window_href) {
// if (!window_href)
// window_href = window.location.href;
// stringParam = stringParam.replace(/[\[\]]/g, "");
// var regExp = new RegExp("null");
// var exec = regExp.exec(window_href);
// if (!exec)
// return null;
// if (!exec[2])
// return "";
// return decodeURIComponent(exec[2].replace(/\+/g, " "));
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") {
// liff.sendMessages([{
// "type": "text",
// "text": getParameterByName("text")
// }]).then(function () {
// liff.closeWindow();
// }).catch(function (error) {
// console.error(`[Line] textx: ${error}`);
// document.getElementById("error").innerHTML = `[Line] textx: ${error}`;
// });
if (liff.isApiAvailable("shareTargetPicker")) {
liff.shareTargetPicker([
{
type: "text",
"text": getParameterByName("text")
}
]).then(function (res) {
liff.closeWindow();
}).catch(function (error) {
console.error(`[Line] textx: ${error}`);
document.getElementById("error").innerHTML = `[Line] textx: ${error}`;
});
} else {
alert("[Line] 你的 LINE App 暫時不支援 Share Target Picker");
}
}
}
function makeImage() {
var type = getParameterByName("type");
if (type === "image") {
liff.sendMessages([{
"type": "image",
"originalContentUrl": getParameterByName("img"),
"previewImageUrl": getParameterByName("img")
}]).then(function () {
liff.closeWindow();
});
}
}
function makeVideo() {
var type = getParameterByName("type");
if (type === "video") {
liff.sendMessages([{
"type": "video",
"originalContentUrl": getParameterByName("ocu"),
"previewImageUrl": getParameterByName("piu")
}]).then(function () {
liff.closeWindow();
});
}
}
function makeAudio() {
var type = getParameterByName("type");
if (type === "audio") {
liff.sendMessages([{
"type": "audio",
"originalContentUrl": getParameterByName("link"),
"duration": 60000
}]).then(function () {
liff.closeWindow();
});
}
}
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";
}
if (liff.isApiAvailable("sendMessages")) {
liff.sendMessages([{
"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
}
}]
}
}]).then(function () {
liff.closeWindow();
}).catch(function (error) {
console.error(`[Line] makeSticker: ${error}`);
document.getElementById("error").innerHTML = `[Line] makeSticker: ${error}`;
});
} else {
alert("[Line] 你的 LINE App 暫時不支援 Send Messages");
document.getElementById("error").innerHTML = `[Line] 你的 LINE App 暫時不支援 Send Messages`;
}
// if (liff.isApiAvailable("shareTargetPicker")) {
// liff.shareTargetPicker([
// {
// 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
// }
// }]
// }
// }
// ]).then(function (res) {
// liff.closeWindow();
// }).catch(function (error) {
// console.error(`[Line] makeSticker: ${error}`);
// document.getElementById("error").innerHTML = `[Line] makeSticker: ${error}`;
// });
// } else {
// alert("[Line] 你的 LINE App 暫時不支援 Share Target Picker");
// }
}
}
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") {
liff.sendMessages([{
"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": "line://app/1657715144-m4W6lyjL?type=profile"
}]
}
}]).then(function () {
liff.closeWindow();
});
}
});
}