doubi / dadahelper

// ==UserScript==
// @name dadahelper
// @namespace Violentmonkey Scripts
// @match *://*/*
// @grant none
// @license MIT
// ==/UserScript==
// 

if (location.href.match('https://melody.shop.ele.me')) {
  var jq = document.createElement('script');
  jq.src = 'https://code.jquery.com/jquery-3.3.1.min.js'
  jq.type = 'text/javascript';
  document.body.appendChild(jq);

  var code = document.createElement('script');
  code.src = 'https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js'
  code.type = 'text/javascript';
  document.body.appendChild(code);

  jq.onload = function () {
    var helpCodeNode = document.createElement('div')
    var btn = document.createElement('div')
    var flag = false
    helpCodeNode.setAttribute('class', 'helper-code');
    btn.setAttribute('class', 'btn');
    $("body").append(helpCodeNode);
    $("body").append(btn);

    $('.btn').css({
      width: '60px',
      height: '20px',
      position: 'fixed',
      zIndex: 99999999,
      left: '520px',
      top: '18px',
      borderRadius: '10px',
      textAlign: 'center',
      lineHeight: '20px',
      border: '1px solid #ccc',
      userSelect: 'none',
      cursor: 'pointer'
    })
    $('.helper-code').css({
      width: '200px',
      height: '200px',
      position: 'fixed',
      zIndex: 99999999,
      left: '650px',
      top: '10px',
    })

    $('.btn').html('显示助手')
    $('.helper-code').hide()
    $('.btn').hide()
    
    code.onload = function () {
        $('.btn').show()
        $('.btn').click(function () {
          if (flag) {
            $('.helper-code').html('')
            $('.helper-code').hide()
            $('.btn').html('显示助手')
          }
          else {
            $('.helper-code').show()
            $('.btn').html('关闭助手')
            var a = btoa(localStorage['currentShopId'])
            var b = btoa(localStorage['ksid'])
            $('.helper-code').qrcode({
              render: "canvas",
              width: 200,
              height: 200,
              text: a + '\n ' + ' \n' + b
            })
          }
          flag = !flag
        })
    }
  }
}