导航栏: 首页 评论列表

移动端调试工具vconsole

默认分类 2020/04/17 08:37

移动端调试工具vconsole

1.开启调试模式.

// 注:3秒内连续点击.float-advertise元素10次,开启调试模式,关闭同理
document.querySelector('.float-advertise').addEventListener('click', function(){
  window.dbg_md = window.dbg_md || {}
  var me = window.dbg_md
  var now = (new Date()).getTime()
  if (me.clickTime && now - me.clickTime < 3000) {
    me.clickCount++
  } else {
    me.clickCount = 1
    me.clickTime = now
  }
  if (me.clickTimer) window.clearTimeout(me.clickTimer)
  me.clickTimer = window.setTimeout(function() {
    window.dbg_md.clickTimer = ''
    if (window.dbg_md.clickCount > 7 && window.dbg_md.clickCount < 11) {
      switchDebugModel()
      window.location.reload()
    }
  }, 1000)
})
function switchDebugModel () {
  var sign = window.localStorage.getItem('debug_model')
  sign = sign ? '' : '1'
  window.localStorage.setItem('debug_model', sign)
}

2.根据debug_model开启调试vconsole

// [根据debug_model开启调试vconsole]
;(function(){
  if (!window.localStorage || !window.localStorage.getItem('debug_model')) return ''
  var script = document.createElement('script') 
  script.src = 'vconsole.min.js' 
  document.getElementsByTagName('head')[0].appendChild(script)
  script.onload = function () { new VConsole() } 

  // [JS错误监控]
  window.saveJsErrorLog = function (msg, file, line) {
    var encode = window.encodeURIComponent
    var str = []
    var url = [
      'http://i0.hdslb.com/bfs/activity-plat/static/487ed9538142fdbfc4221cf26c20bd50/YyJiC6Zol.png?hy=1',
      '&l=' + encode(line),
      '&m=' + encode(msg),
      '&f=' + encode(file),
      '&h=' + encode(window.location.href),
      '&u=' + encode(window.navigator.userAgent),
      '&p=' + encode('{' + str.join(',<br>') + '}'),
      '&r=' + Math.random()
    ].join('')

    var p = document.createElement('img')
    p.src = url
    p.id = Math.random()
    p.width = 1
    p.height = 1
    p.style.cssText = 'position:absolute;left:-1px;top:-1px;z-index:-1;border:0'
    document.documentElement.appendChild(p)

    var blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
    window.setTimeout(Function('document.getElementById("' + p.id + '").src = "' + blank + '";'), 4000)
  }
  window.saveJsErrorLog.version = '3.0.0'

  if (window.addEventListener) {
    window.addEventListener('error', function(e) {
      window.saveJsErrorLog(e.message, e.filename, e.lineno)
    }, false);
  } else if (window.attachEvent) {
    window.attachEvent('onerror', function(msg, file, line) {
      window.saveJsErrorLog(msg, file, line)
    })
  }
})();


>> 留言评论