sharePage.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import getParams from './getParams.js';
  2. sharePage = function () {
  3. //private menbers
  4. let category = 'kol';
  5. let kolName;
  6. let ordinaryId;
  7. const kolMan = ['Yang', 'Hao', 'Drangadrang', 'Cookingdairy', 'Ku', 'Betty', 'Ralf', 'Chefchouchou', 'Albee', 'commute_Chang', 'commute_Li', 'commute_He', 'ordinary']
  8. //private methods
  9. function init() {
  10. console.log('sharePage is loaded.');
  11. // 取得是哪位Kol
  12. if (getParams('kol') != null && kolMan.includes(getParams('kol'))) {
  13. kolName = getParams('kol')
  14. category = 'kol';
  15. }
  16. // 取得是哪位素人
  17. if (getParams('ordinary') != null && !isNaN(getParams('ordinary'))) {
  18. ordinaryId = getParams('ordinary')
  19. category = 'ordinary';
  20. }
  21. console.log("kolName: " + kolName)
  22. console.log("ordinaryId: " + ordinaryId)
  23. console.log("category: " + category)
  24. safariHacks();
  25. resizePage();
  26. $(".share__btn-line").click(function (e) {
  27. e.preventDefault();
  28. console.log("share__btn-fb")
  29. lineShare();
  30. });
  31. $(".share__btn-fb").click(function(e){
  32. e.preventDefault();
  33. console.log("share__btn-line")
  34. shareFB();
  35. });
  36. if (category == 'kol') {
  37. $(".share__pic img").attr("src", "https://d1xzlli46wohoc.cloudfront.net/images/sharePage/share-" + kolName + ".png");
  38. }else {
  39. $(".share__pic img").attr("src", "./images/sharePage_ordinary/" + ordinaryId+".jpg");
  40. }
  41. }
  42. function safariHacks() {
  43. let windowsVH = window.innerHeight / 100;
  44. document.querySelector('.share').style.setProperty('--vh', windowsVH + 'px');
  45. window.addEventListener('resize', function() {
  46. document.querySelector('.share').style.setProperty('--vh', windowsVH + 'px');
  47. });
  48. }
  49. function resizePage() {
  50. let shareContentH = 700;
  51. // let headerH = $(".header").height();
  52. let contentH = $(window).height();
  53. if (contentH < shareContentH) {
  54. let scaleNum = contentH / shareContentH;
  55. $(".share__content").css("transform", "scale(" + scaleNum + ")");
  56. console.log(scaleNum)
  57. }
  58. console.log("contentH: " + contentH)
  59. console.log("shareContentH: " + shareContentH)
  60. intoPage();
  61. }
  62. // shareFB
  63. function shareFB() {
  64. // var hostPath = window.location.host + window.location.pathname
  65. // if (hostPath.indexOf != -1) {
  66. // hostPath = hostPath.replace("index.html", "")
  67. // }
  68. const APP_ID = (window.location.host === 'www.pxfreshdelivery.tw') ? '729797861493746' : '547406236761668' ;
  69. var _date = new Date();
  70. var _time = _date.getTime();
  71. const base_url = window.location.host === 'www.our-work.com.tw' ? '/demosite/2022/2022-pxgo/justahour/' : '/'
  72. let _hashtag; //hashtag
  73. let redirect_url; // 導回連結
  74. let share_url; // 分享連結
  75. if(category == 'kol') {
  76. _hashtag = '感謝料理救星賜我靈感_食材一鍵買齊再賺加菜金';
  77. redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1&kol=${kolName}`;
  78. // console.log(redirect_url)
  79. if (window.location.host === 'www.pxfreshdelivery.tw') {
  80. share_url = `https://www.pxfreshdelivery.tw/share/share_fb_${kolName}.html?t=${_time}`;
  81. }
  82. else if (window.location.host === 'demo.pxfreshdelivery.tw') {
  83. share_url = `https://demo.pxfreshdelivery.tw/share/share_fb_${kolName}.html?t=${_time}`;
  84. }
  85. else {
  86. share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share/share_fb_${kolName}.html?t=${_time}`;
  87. }
  88. }else {
  89. _hashtag = '民間料理救星私房菜_一鍵打包食材再賺加菜金';
  90. redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1`;
  91. // console.log(redirect_url)
  92. if (window.location.host === 'www.pxfreshdelivery.tw') {
  93. share_url = `https://www.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`;
  94. }
  95. else if (window.location.host === 'demo.pxfreshdelivery.tw') {
  96. share_url = `https://demo.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`;
  97. }
  98. else {
  99. share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`;
  100. }
  101. }
  102. 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);
  103. console.log(share_url);
  104. setTimeout(function () {
  105. location.href = _url;
  106. }, 300);
  107. }
  108. function lineShare(){
  109. let _date = new Date();
  110. let _time = _date.getTime();
  111. let link = "http://line.naver.jp/R/msg/text/?";
  112. const base_url = window.location.host === 'www.our-work.com.tw' ? '/demosite/2022/2022-pxgo/justahour/' : '/'
  113. let redirect_url; // 導回連結
  114. let share_url; // 分享連結
  115. let text; //分享LINE訊息
  116. if(category == 'kol') {
  117. text = "不要說我沒揪你~今天煮什麼?這個都幫你想好了!還可以一鍵下單,菜就買好囉~趕快去用我的優惠碼賺加菜金>>"
  118. redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1&kol=${kolName}`;
  119. if (window.location.host === 'www.pxfreshdelivery.tw') {
  120. share_url = `https://www.pxfreshdelivery.tw/share/share_line_${kolName}.html?t=${_time}`;
  121. }
  122. else if (window.location.host === 'demo.pxfreshdelivery.tw') {
  123. share_url = `https://demo.pxfreshdelivery.tw/share/share_line_${kolName}.html?t=${_time}`;
  124. }
  125. else {
  126. share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share/share_line_${kolName}.html?t=${_time}`;
  127. }
  128. }else {
  129. text = "不要說我沒揪你~今天就來煮這道菜啦!食材還可以一鍵下單,到家就到貨!拿我的優惠碼還可以賺加菜金 >> "
  130. redirect_url = `${window.location.protocol}//${window.location.host}${base_url}index.html?shareback=1`;
  131. if (window.location.host === 'www.pxfreshdelivery.tw') {
  132. share_url = `https://www.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`;
  133. }
  134. else if (window.location.host === 'demo.pxfreshdelivery.tw') {
  135. share_url = `https://demo.pxfreshdelivery.tw/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`;
  136. }
  137. else {
  138. share_url = `https://www.our-work.com.tw/demosite/2022/2022-pxgo/justahour/share_ordinary/share_fb_${ordinaryId}.html?t=${_time}`;
  139. }
  140. }
  141. link += encodeURIComponent(text) + "%0D%0A" + encodeURIComponent(share_url);
  142. console.log(link)
  143. location.href = link;
  144. setTimeout(() => {
  145. console.log(redirect_url)
  146. location.replace(redirect_url);
  147. }, 3000);
  148. }
  149. function intoPage(){
  150. gsap.to(".share",{duration: 0.5,autoAlpha: 1})
  151. }
  152. {
  153. $(document).ready(function () {
  154. init();
  155. });
  156. }
  157. //public
  158. return {
  159. intoPage: function(){
  160. intoPage();
  161. },
  162. };
  163. };
  164. var sharePage = new sharePage();