123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, ($0, $1, $2) => {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- var qs = parseQueryString(window.location.href);
- var tkl = '';
- var serverTime = 1000; //服务器时间,毫秒数
- $().ready(function() {
- todayTbkPassword()
- writeLogH5({'action':qs.appName,channel:'H5',url:window.location.href});//H5页面埋点
- })
- //获取淘口令
- function todayTbkPassword () {
- $.ajax({
- type:"post",
- url:"/api/v2/goods/tbkPassWordToActive",
- typeData:'json',
- success: function (res){
- if(res && res.errno == 0){
- if(res.rst.password){
- tkl = res.rst.password;
- }
- }
- $("#taokouling").text(tkl);
- count_down('2018-10-20 00:00:00');
- }
- });
- }
- function copyPassword() {
- var data=document.getElementById("taokouling").innerHTML;
- copy_2.innerHTML = data;
- copy_1.value = data;
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
- //区分iPhone设备
- window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
- var Url2=document.getElementById("copy_2");//要复制文字的节点
- var range = document.createRange();
- // 选中需要复制的节点
- range.selectNode(Url2);
- // 执行选中元素
- window.getSelection().addRange(range);
- // 执行 copy 操作
- var successful = document.execCommand('copy');
- // 移除选中的元素
- window.getSelection().removeAllRanges();
- }else{
- var Url2=document.getElementById("copy_1");//要复制文字的节点
- Url2.select(); // 选择对象
- document.execCommand("Copy"); // 执行浏览器复制命令
- }
- showMsg('口令复制成功,打开淘宝领取吧!')
- }
- //提示弹框
- function showMsg(msg) {
- var msgBox = $('.alert-info');
- msgBox.children('p').text(msg);
- msgBox.show();
- setTimeout(function() {
- msgBox.hide();
- }, 3000);
- }
- //倒计时
- function count_down(o){
- var html = null;//页面
- var time = null;
- time = setTimeout(function(){count_down(o)},1000);
- var datatime=/^[\d]{4}-[\d]{1,2}-[\d]{1,2}( [\d]{1,2}:[\d]{1,2}(:[\d]{1,2})?)?$/ig,str='',conn,s;
- if(!o.match(datatime)){
- // alert('参数格式为2020-01-01[ 01:01[:01]].\r其中[]内的内容可省略');
- return false;
- }
- var sec=(new Date(o.replace(/-/ig,'/')).getTime() - new Date().getTime())/1000;
- // if(sec > 0){
- // conn='';
- // }else{
- // conn='已过去';
- // sec*=-1;
- // }
- if(sec == 0 || sec < 0){
- //倒计时结束时----都为0
- html = `<img class="img" src="https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/chaojihongbao/yure_hongbao.png" />`
- $('.daojishi').html(html);
- $(".button").addClass('buttonActive');
- $(".button").click(function () {
- copyPassword();
- })
- clearTimeout(time);
- }else{
- s={'天':sec/24/3600,'时':Math.floor(sec/3600%24),'分':Math.floor(sec/60%60),'秒':Math.floor(sec%60)};
- for(i in s){
- if(s[i] < 10){s[i] = '0' + s[i]};
- if(i != '天'){
- str += '<span>' + s[i] + '</span>' + i;
- }
- }
- html = `<div class="count_down"><img src="https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/chaojihongbao/daojishi.png" alt="" /></div>
- <div id="endtime">${str}</div>`;
- $('.daojishi').html(html);
- $(".button").removeClass('buttonActive');
- $(".button").click(function () {
- showMsg('今晚0点再来领取哦~')
- })
- }
- }
- //H5页面埋点
- function writeLogH5 (data) {
- $.ajax({
- type:'post',
- url:'/api/v2/channel/writeLogH5',
- dataType:'json',
- data:data,
- success:function (res) {
- // console.log(res)
- }
- })
- }
|