适配任何网站的JS弹窗引导代码

// 判断存在jq资源
try {
  if($ || jQuery) {
    tipsFun();
  }
} catch(e) {
  let script=document.createElement("script");
  script.type="text/javascript";
  script.src="https://cdn.mac89.com/common/static/jquery.min.js";

  document.getElementsByTagName('head')[0].appendChild(script);

  script.onload = tipsFun;
}


function tipsFun() {
  // 判断用户是否是windows
  if((navigator.platform == "Win32") || (navigator.platform == "Windows")) {
    // let hostName = location.hostname;
    // if(hostName === 'mac.mac89.com') return;

    let curTime = new Date().getTime();
    if(!window.localStorage.hasTips || ((curTime - window.localStorage.hasTips) >= 86400000)) {
      setTimeout(()=> {
        $(document).ready(function(){
          let tipHtml = `
            <div class="tip-box" id="tip-box" style="position: fixed; z-index: 9999; width: 740px; height: 150px; background-color: #fff; border-radius: 0 0 20px 20px; text-align: center; font-size: 16px; top: 0; left: 50%; margin-left: -370px; box-shadow: 0 10px 20px 0 rgba(0, 0, 0, 0.2); display: none; transform: translateY(-100%); transition: all .6s;">
              <p class="tip" style="font-size: 18px; line-height: 1; margin: 38px 0 22px;">如果您当前使用的电脑是MacOS操作系统,请前往MacOS下载资源站点。</p>
              <button class="nomore" style="width: 120px; cursor: pointer; height: 40px; border: 1px solid #ddd; outline: none; border-radius: 5px; margin-right: 40px;">不再提醒</button>
              <button class="cancel" style="background-color: #333; color: #fff; width: 120px; cursor: pointer; height: 40px; border: none; outline: none; border-radius: 5px; margin-right: 40px;">继续浏览</button>
              <button class="sure" style="height: 40px; padding: 0 30px; background-color: #1B78F5; cursor: pointer; color: #fff; border-radius: 5px; outline: none; border: none;">立即前往 (10秒)</button>
            </div>`;

          $('body').append(tipHtml);

          const $tipBox = $('#tip-box');
          $tipBox.show().css('transform', 'translateY(0)');

          $tipBox.on('click', '.cancel', ()=> {
            removeTip();
          }).on('click', '.sure', ()=> {
            window.open("https://www.macw.com/");
          }).on('click', '.nomore', ()=> {
            removeTip();
            window.localStorage.hasTips = curTime;
          })

          let time = 10, timer;

          timer = setInterval(()=> {
            time--;
            $tipBox.find('.sure').text('立即前往 ('+ time +'秒)')
            if(time < 1) {
              removeTip();
            }
          }, 1000)

          function removeTip() {
            $tipBox.css('transform', 'translateY(-100%)');
            clearInterval(timer);
            setTimeout(function() {
              $tipBox.remove();
            }, 600)
          }
        });
      }, 1000);
    }
  }


  // pd广告地址
  let hostName = location.hostname;
  let pdAdress = "https://shop.macsc.com/pd19";

  // if(hostName === 'mac.macxf.com' || hostName === 'mac.orsoon.com') return; 

  let curTime = new Date().getTime();
  if(!window.localStorage.hasPdShowTime || ((curTime - window.localStorage.hasPdShowTime) >= 86400000)) {
    setTimeout(()=> {
      $(document).ready(function(){
        let hasLogin = true;

        let position_style = 'right: 50%; margin-right: -750px;';

        switch (hostName) {
          case 'mac.macxz.com':
            position_style = 'left: 50%; margin-left: -750px;';
            break;
          case 'mac.mac89.com':
          // case 'mac.macxf.com':
          case 'mac.macsc.com':
            hasLogin = !!$('.logined').length
            break;
          // case 'www.macz.com':
        //     hasLogin = !!$('.logined').children().length
        //     break;
        //   case 'www.macw.com':
        //   case 'www.macv.com':
        //     hasLogin = !!$('.header-login_logined').children().length
        //     break;
          default:
            hasLogin = true;
            break;
        }
        
        if(!hasLogin) return;

        let leftPdHtml = `
          <div class="pd-left" id="pd-left-box" style="position: fixed; width: 130px; height: 120px; ${position_style} top: 20%; z-index: 99; text-align: center; border-radius: 10px;background: linear-gradient(90deg,#5B95F2,#224FE8);padding-top: 8px; box-sizing: border-box; font-size: 13px;">
            <div class="close" style="cursor:pointer; position: absolute; width: 20px; height: 20px; line-height: 20px; right: -5px; top: -5px; border-radius: 50%; background-color: rgba(0,0,0,0.3); color: #fff;">X</div>
            <a href="${pdAdress}" target="_blank">
              <img src="https://cdn.mac89.com/single_page/single-store/images/pd19/pd19.png"  style="width: 60px; display: inline-block;">
              <p style="color: #fff;">Parallels Desktop 19</p>
              <span style="color: #FFC600;">永久授权许可证激活</span>
            </a>
          </div>
        `

         $('body').append(leftPdHtml);
         $('#pd-left-box').on('click', '.close', function() {
           window.localStorage.hasPdShowTime = curTime;
           $('#pd-left-box').remove();
         })
      });
    }, 1000);
  }


  // 底部商城广告
  let shopHtml = `<div class="shop-box {class}" id="shop-box" style="position: fixed; box-sizing: border-box; z-index: 199; width: 100%; height: 120px; left: 0; bottom: {bot}; background-color: #fff; box-shadow: 0 -10px 20px 0 rgba(0,0,0,.1); transition: all .2s; padding: 25px 0;">
  <div class="close" style="position: absolute; z-index: 1; width: 60px; height: 30px; {rotate} line-height: 30px; background: #fff; cursor: pointer; left: 0; top: -30px; text-align: center;">
    <i style="display: inline-block;transform: rotate(90deg);font-size: 24px;color: #666;">></i>
  </div>
  <div class="line" style="position: absolute; width: 100%;height: 10px;background-color: #fff;top: -10px;box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.15);"></div>
  <div class="items-box" style="display: flex; justify-content: center;">
    <p style="font-size: 24px; width: 50px; line-height: 1.4;">正版软件</p>
    <div class="item" style="width: 250px; height: 70px; box-sizing: border-box; box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1); border-radius: 15px; padding: 15px 20px; line-height: 40px; margin: 0 10px 0 20px;">
      <a href="${pdAdress}" target="_blank" style="display: block;">
        <img src="https://cdn.mac89.com/single_page/single-store/images/pd19/pd19.png" height="40"  style="display: inline-block; vertical-align: middle;">
        <span style="margin-left: 10px;">Parallels Desktop</span>
        <i style="float: right; width: 30px; height: 30px; line-height: 30px; margin-top: 5px; border-radius: 50%; background-color: #1c65f7; color: #fff; text-align: center; font-size: 16px; transform: rotate(-30deg);">➤</i>
      </a>
    </div>
    <div class="item" style="width: 200px; height: 70px; box-sizing: border-box; box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1); border-radius: 15px; padding: 15px 20px; line-height: 40px; margin: 0 10px;">
      <a href="https://shop.macsc.com/cad" target="_blank" style="display: block;">
        <img src="https://cdn.mac89.com/single_page/single-store/images/cad/cad2023.png" height="40"  style="display: inline-block; vertical-align: middle;">
        <span style="margin-left: 10px;">CAD</span>
        <i style="float: right; width: 30px; height: 30px; line-height: 30px; margin-top: 5px; border-radius: 50%; background-color: #1c65f7; color: #fff; text-align: center; font-size: 16px; transform: rotate(-30deg);">➤</i>
      </a>
    </div>
    <div class="item" style="width: 200px; height: 70px; box-sizing: border-box; box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1); border-radius: 15px; padding: 15px 20px; line-height: 40px; margin: 0 10px;">
      <a href="https://shop.macsc.com/maya" target="_blank" style="display: block;">
        <img src="https://cdn.mac89.com/single_page/single-store/images/maya/maya.png" height="40"  style="display: inline-block; vertical-align: middle;">
        <span style="margin-left: 10px;">Maya</span>
        <i style="float: right; width: 30px; height: 30px; line-height: 30px; margin-top: 5px; border-radius: 50%; background-color: #1c65f7; color: #fff; text-align: center; font-size: 16px; transform: rotate(-30deg);">➤</i>
      </a>
    </div>
    <div class="item" style="width: 200px; height: 70px; box-sizing: border-box; box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1); border-radius: 15px; padding: 15px 20px; line-height: 40px; margin: 0 10px;">
      <a href="https://shop.macsc.com/flame" target="_blank" style="display: block;">
        <img src="https://cdn.mac89.com/single_page/single-store/images/flame.png" height="40"  style="display: inline-block; vertical-align: middle;">
        <span style="margin-left: 10px;">Flame</span>
        <i style="float: right; width: 30px; height: 30px; line-height: 30px; margin-top: 5px; border-radius: 50%; background-color: #1c65f7; color: #fff; text-align: center; font-size: 16px; transform: rotate(-30deg);">➤</i>
      </a>
    </div>
  </div>
</div>
`;

//<div class="chat-gpt" style="display:none; position: fixed;z-index: 2;bottom: 220px;left: 30px;width: 100px;height: 100px;box-sizing: border-box;box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1);border-radius: 15px;padding: 16px;line-height: 40px;text-align: center;margin: 0 10px;background: linear-gradient(135deg, #9D4EFF, #2C52F4);">
//  <a href="https://chat.macjz.com/" target="_blank" style="display: block;color: #fff;">
//    <img src="https://cdn.mac89.com/images/gpt.png" height="40"  style="display: inline-block;vertical-align: middle;">
//    <p>Chat GPT</p>
//  </a>
//</div>

//<div class="item gpt" style="width: 200px;height: 70px;box-sizing: border-box;box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1);border-radius: 15px;padding: 15px 18px;line-height: 40px;margin: 0 10px;background: linear-gradient(135deg, #9D4EFF, #2C52F4);">
//  <a href="https://chat.macjz.com/" target="_blank" style="display: block;color: #fff;">
//    <img src="https://cdn.mac89.com/images/gpt.png" height="30"  style="display: inline-block;vertical-align: middle;">
//    <span style="margin-left: 10px;">Chat GPT人工智能</span>
//  </a>
//</div>

  let hasHide = window.localStorage.hideShop || '';
  if(hasHide === 'hide') {
    shopHtml = shopHtml.replace('{bot}', '-117px').replace('{class}', 'bot').replace('{rotate}', 'transform: rotate(180deg);')
  }  else {
    shopHtml = shopHtml.replace('{bot}', '0').replace('{class}', '').replace('{rotate}', '');
  }

  $('body').append(shopHtml);

  if(hostName === 'mac.mac89.com') {
    $('#shop-box').find('.gpt').hide();
  }

   $('#shop-box').on('click', '.close', function() {
    let $box = $('#shop-box')
     if($box.hasClass('bot')) {
       $box.css({'bottom': '0'})
       $(this).css({'transform': 'rotate(0)'})
       window.localStorage.hideShop = '';
     } else {
      $box.css({'bottom': '-117px'})
      $(this).css({'transform': 'rotate(180deg)'})
      window.localStorage.hideShop = 'hide';
     }

     $box.toggleClass('bot');
   })
}
  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

武恩赐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值