完成多少秒内点击多少次小功能

145 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第2天,点击查看活动详情

需求

⛳ 运营活动小需求探索活动,需要手动在30秒内点击全部页面,点完就完事。

方案

产品给的需求很简单,定时器记录,超时重置,未超时判断不重复的页面点击次数是否达到,达到就触发成功。

当然拿到需求都能手工艺写出来,当然可以复制粘贴就更妙了,那么方法就贴出来了。

let pageArr = [],
timerId = null, //计时器
timerNum = 0, //秒数
clickNum = 0, //点击次数

const countClick = (page)=> {
      //隐藏任务,30秒点击9次
      if (this.taskConfi) return

      if (!this.clickComplete) {
        if (!this.pageArr.includes(page)) {
          this.clickNum++
          this.pageArr.push(page)
        }
        if (!this.timerId) {
          this.timerId = setInterval(() => {
            this.timerNum++
          }, 1000)
          setTimeout(() => {
            if (this.clickNum < 9) {
              this.resetTimer()
            }
          }, 30000)
        } else if (this.clickNum >= 9 && this.timerNum <= 30) {
          this.resetTimer()
        } else if (this.clickNum < 9 && this.timerNum >= 30) {
          this.resetTimer()
        }
      }
    }
    
// 清除重置计时
const resetTimer = ()=>{
// do...
}

思路很简单,验证页面点击是否重复,非重复计数,方便crt+v;

插曲

不出意外的情况下,意外就出来了,运营探索小活动,探索的话就有好事者不去看活动广告,开始探索页面源代码了,撸起了浏览器的代码,根据一些中文找到了捷径,好好的活动,因为混淆开关一时没开,被产品怼了!

// 混淆一开,鬼都难认
const JavaScriptObfuscator = require('webpack-obfuscator')
configureWebpack:config=>{
    config.plugins.push(
        new JavaScriptObfuscator(
          {
            compact: true,
            controlFlowFlattening: false,
            deadCodeInjection: false,
            debugProtection: false,
            debugProtectionInterval: false,
            disableConsoleOutput: true,
            identifierNamesGenerator: 'hexadecimal',
            log: false,
            renameGlobals: false,
            rotateStringArray: true,
            selfDefending: true,
            stringArray: true,
            stringArrayEncoding: ['rc4'],
            stringArrayThreshold: 0.75,
            unicodeEscapeSequence: false
          },
          []
        )
      )
}

✅很简单,记录下,需求来了下次直接copy