一键复制吱口令,支付宝红包js代码

可实现点击任意位置复制吱口令

  • zhifubao.js
{
  var Zhi = '123456'; #更改吱口令
  var newscript = document.createElement('script');
  newscript.setAttribute('type','text/javascript');
  newscript.setAttribute('src','https://cdn.bootcss.com/clipboard.js/2.0.1/clipboard.js');
  var head = document.getElementsByTagName('head')[0];
  head.appendChild(newscript);
  document.writeln('<input id="foo" readonly="readonly" style="position: fixed;left:-100%;top:50%" value="'+Zhi+'">');
  function zhiFuBaoUrlSearch(str) {
    var name, value;
    var num = str.indexOf("?");
    var params = [];
    str = str.substr(num + 1);
    var arr = str.split("&");
    for (var i = 0; i < arr.length; i++) {
      num = arr[i].indexOf("=");
      if (num > 0) {
        name = arr[i].substring(0, num);
        value = arr[i].substr(num + 1);
        params[name] = value;
      }
    }
    return params;
  }
  function zhiFuBaoSetClassAndAttribute(elements){
    for (var e = 0;e<elements.length;e++){
      Celement = document.querySelectorAll(elements[e]);
      for (var i = 0;i<Celement.length;i++){
        Celement[i].className += ' Clipboard';
        Celement[i].setAttribute("data-clipboard-target", "#foo");
      }
    }
  }
  window.onload = function () {
    js_url = document.getElementById('zhifubaoJs').src;
    $_GET = zhiFuBaoUrlSearch(js_url);
    if ($_GET['hasInput'] === undefined){
      zhiFuBaoSetClassAndAttribute(['body']);
    }else{
      zhiFuBaoSetClassAndAttribute(['button',"input[type='button']",'img','span','a','h1','h2','h3','p']);
    }
    new ClipboardJS('.Clipboard');
  };
}
  • 运用
<html>
<head></head>
<body>
    <!-- <input type="text"/> -->
</body>
    <!-- 有input 一定要加?hasInput=1 否则会导致input框无法正常输入的问题-->
    <!-- <script id="zhifubaoJs" src="./zhifubao.js?hasInput=1"></script> -->
    <!-- 没有input -->
    <script id="zhifubaoJs" src="./zhifubao.js"></script>
</html>
# JavaScript   工具   扩展包  

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×