import getParams from './getParams.js'; sharePage = function () { //private menbers let category = 'kol'; let kolName; let ordinaryId; const kolMan = ['Yang', 'Hao', 'Drangadrang', 'Cookingdairy', 'Ku', 'Betty', 'Ralf', 'Chefchouchou', 'Albee', 'commute_Chang', 'commute_Li', 'commute_He', 'ordinary'] //private methods function init() { console.log('sharePage is loaded.'); // 取得是哪位Kol if (getParams('kol') != null && kolMan.includes(getParams('kol'))) { kolName = getParams('kol') category = 'kol'; } // 取得是哪位素人 if (getParams('ordinary') != null && !isNaN(getParams('ordinary'))) { ordinaryId = getParams('ordinary') category = 'ordinary'; } console.log("kolName: " + kolName) console.log("ordinaryId: " + ordinaryId) console.log("category: " + category) safariHacks(); resizePage(); $(".share__btn-line").click(function (e) { e.preventDefault(); console.log("share__btn-fb") lineShare(); }); $(".share__btn-fb").click(function(e){ e.preventDefault(); console.log("share__btn-line") shareFB(); }); if (category == 'kol') { $(".share__pic img").attr("src", "https://d1xzlli46wohoc.cloudfront.net/images/sharePage/share-" + kolName + ".png"); }else { $(".share__pic img").attr("src", "./images/sharePage_ordinary/" + ordinaryId+".jpg"); } } function safariHacks() { let windowsVH = window.innerHeight / 100; document.querySelector('.share').style.setProperty('--vh', windowsVH + 'px'); window.addEventListener('resize', function() { document.querySelector('.share').style.setProperty('--vh', windowsVH + 'px'); }); } function resizePage() { let shareContentH = 700; // let headerH = $(".header").height(); let contentH = $(window).height(); if (contentH < shareContentH) { let scaleNum = contentH / shareContentH; $(".share__content").css("transform", "scale(" + scaleNum + ")"); console.log(scaleNum) } console.log("contentH: " + contentH) console.log("shareContentH: " + shareContentH) intoPage(); } // shareFB function shareFB() { // var hostPath = window.location.host + window.location.pathname // if (hostPath.indexOf != -1) { // hostPath = hostPath.replace("index.html", "") // } const APP_ID = (window.location.host === 'www.pxfreshdelivery.tw') ? '729797861493746' : '547406236761668' ; var _date = new Date(); var _time = _date.getTime(); const base_url = window.location.host === 'www.our-work.com.tw' ? '/demosite/2022/2022-pxgo/justahour/' : '/' let _hashtag; //hashtag let redirect_url; // 導回連結 let share_url; // 分享連結 if(category == 'kol') { _hashtag = '感謝料理救星賜我靈感_食材一鍵買齊再賺加菜金'; redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1&kol=${kolName}`; // console.log(redirect_url) if (window.location.host === 'www.pxfreshdelivery.tw') { share_url = `https://www.pxfreshdelivery.tw/share/share_fb_${kolName}.html?t=${_time}`; } else if (window.location.host === 'demo.pxfreshdelivery.tw') { share_url = `https://demo.pxfreshdelivery.tw/share/share_fb_${kolName}.html?t=${_time}`; } else { share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share/share_fb_${kolName}.html?t=${_time}`; } }else { _hashtag = '民間料理救星私房菜_一鍵打包食材再賺加菜金'; redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1`; // console.log(redirect_url) if (window.location.host === 'www.pxfreshdelivery.tw') { share_url = `https://www.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`; } else if (window.location.host === 'demo.pxfreshdelivery.tw') { share_url = `https://demo.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`; } else { share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`; } } var _url = "https://www.facebook.com/dialog/share?app_id=" + APP_ID + "&hashtag=%23" + _hashtag + "&display=popup&href=" + encodeURIComponent(share_url) + "&redirect_uri=" + encodeURIComponent(redirect_url); console.log(share_url); setTimeout(function () { location.href = _url; }, 300); } function lineShare(){ let _date = new Date(); let _time = _date.getTime(); let link = "http://line.naver.jp/R/msg/text/?"; const base_url = window.location.host === 'www.our-work.com.tw' ? '/demosite/2022/2022-pxgo/justahour/' : '/' let redirect_url; // 導回連結 let share_url; // 分享連結 let text; //分享LINE訊息 if(category == 'kol') { text = "不要說我沒揪你~今天煮什麼?這個都幫你想好了!還可以一鍵下單,菜就買好囉~趕快去用我的優惠碼賺加菜金>>" redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1&kol=${kolName}`; if (window.location.host === 'www.pxfreshdelivery.tw') { share_url = `https://www.pxfreshdelivery.tw/share/share_line_${kolName}.html?t=${_time}`; } else if (window.location.host === 'demo.pxfreshdelivery.tw') { share_url = `https://demo.pxfreshdelivery.tw/share/share_line_${kolName}.html?t=${_time}`; } else { share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share/share_line_${kolName}.html?t=${_time}`; } }else { text = "不要說我沒揪你~今天就來煮這道菜啦!食材還可以一鍵下單,到家就到貨!拿我的優惠碼還可以賺加菜金 >> " redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1`; if (window.location.host === 'www.pxfreshdelivery.tw') { share_url = `https://www.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`; } else if (window.location.host === 'demo.pxfreshdelivery.tw') { share_url = `https://demo.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`; } else { share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`; } } link += encodeURIComponent(text) + "%0D%0A" + encodeURIComponent(share_url); console.log(link) location.href = link; setTimeout(() => { console.log(redirect_url) location.replace(redirect_url); }, 3000); } function intoPage(){ gsap.to(".share",{duration: 0.5,autoAlpha: 1}) } { $(document).ready(function () { init(); }); } //public return { intoPage: function(){ intoPage(); }, }; }; var sharePage = new sharePage();