斗鱼自动发弹幕

斗鱼自动发弹幕,复制到控制台运行即可
(function () {
      var _timer_ = null;
      var spred = ['.', '.', '.', '.', '.'];
      var start = 1;
      // 加载样式
      var fixInp = document.createElement('textarea');
      var fixSend = document.createElement('input');
      var fixStop = document.createElement('input');
      var tips1 = document.createElement('p');
      var tips2 = document.createElement('span');
      var times = document.createElement('input');
      var fixWrap = document.createElement('div');
      var outer = document.createElement('div');
      var hide = document.createElement('span');
      var show = document.createElement('span');
      var checkdiv = document.createElement('div');
      var checkTip = document.createElement('span');
      var check = document.createElement('input');
      fixSend.setAttribute('type', 'submit');
      fixSend.setAttribute('value', '发送');
      fixStop.setAttribute('type', 'submit');
      fixStop.setAttribute('value', '停止');
      times.setAttribute('type', 'number');
      check.setAttribute('type', 'checkbox');
      tips1.innerHTML = '内容:';
      tips2.innerHTML = '间隔(秒):';
      hide.innerHTML = '隐藏';
      show.innerHTML = '显示';
      checkTip.innerHTML = '防重复发言:';
      outer.style.cssText = 'position: fixed; right: 10px; bottom: 10px; display: block; width:200px;padding: 10px; background:#4CAF50;z-index: 9999999;';
      times.style.cssText = 'display: inline-block; width: 40px;';
      fixInp.style.cssText = 'display: block;width: 100%;height:62px;box-sizing: border-box;';
      tips1.style.cssText = 'margin:0;padding:0;';
      fixWrap.style.cssText = 'display: inline-block;width:100%;';
      show.style.cssText = 'position: fixed; right: 10px; bottom: 10px;display:none;padding:2px; background:#4CAF50;font-size: 12px;color: #fff; cursor: pointer;';
      hide.style.cssText = 'display:inline-block;padding:2px; background:#b22;font-size: 12px;color: #fff; cursor: pointer;';
      times.value = 10;
      fixWrap.appendChild(hide);
      fixWrap.appendChild(tips1);
      fixWrap.appendChild(fixInp);
      fixWrap.appendChild(tips2);
      fixWrap.appendChild(times);
      fixWrap.appendChild(fixSend);
      fixWrap.appendChild(fixStop);
      checkdiv.appendChild(checkTip);
      checkdiv.appendChild(check);
      fixWrap.appendChild(checkdiv);
      outer.appendChild(fixWrap);
      document.body.appendChild(outer);
      document.body.appendChild(show);
      // 发送弹幕
      function send(message, bool) {
        if (bool) {
          var s = spred.slice(0, start++);
          message += s.join('');
          if (start > spred.length) {
            start = 1
          }
        }
        document.querySelector('.ChatSend-txt').value = message;
        document.querySelector('.ChatSend-button').click();
      }
      // 事件
      fixSend.addEventListener('click', function () {
        var time = parseInt(times.value);
        var message = fixInp.value;
        var bool = check.checked;
        fixSend.style.display = 'none';
        send(message);
        _timer_ = setInterval(function () {
          send(message, bool);
        }, time * 1000);
      });
      fixStop.addEventListener('click', function () {
        fixSend.style.display = 'inline-block';
        clearInterval(_timer_);
        _timer_ = null;
      });
      hide.addEventListener('click', function () {
        outer.style.display = 'none';
        show.style.display = 'inline-block';
      });
      show.addEventListener('click', function () {
        outer.style.display = 'block';
        show.style.display = 'none';
      });
    })();

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐