Greasy Fork

猫站刮刮乐自动化

徽章抽取处标题后会出现抽取按钮,网页左上角每次抽取成功会提示。

// ==UserScript==
// @name         猫站刮刮乐自动化
// @version      1.1
// @author       PoppyGuy
// @description  徽章抽取处标题后会出现抽取按钮,网页左上角每次抽取成功会提示。
// @match        https://pterclub.com/lottery*
// @grant        GM_xmlhttpRequest
// @license      MIT
// @namespace https://greasyfork.org/users/1304869
// ==/UserScript==

(function() {
  'use strict';

  const logdiv = document.createElement('div');
  logdiv.style.cssText = `
    position: fixed;
    top: 20px;
    left: 20px;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background-color: rgba(255, 255, 0, 0.5);
    color: #333;
    font-weight: bold;
    z-index: 100000;
    border-radius: 5px;
    box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
  `;

  document.body.appendChild(logdiv);

  let logCount = 0;

  const trArray = document.querySelectorAll('tbody tr');
  for (let i = 0; i < trArray.length; i++) {
    const tdArray = trArray[i].querySelectorAll('td');
    for (let j = 0; j < tdArray.length; j++) {
      if (tdArray[j].innerText.includes('徽 章 抽 取 处')) {
        const button = document.createElement('button');
        button.innerText = '自动抽取';
        button.style.marginLeft = '5px';
        button.style.backgroundColor = '#ff5733'; // 设置按钮背景颜色
        button.style.color = '#fff'; // 设置按钮文字颜色
        button.style.border = 'none'; // 移除按钮边框
        button.style.padding = '5px 10px'; // 设置按钮内边距
        button.style.borderRadius = '5px'; // 设置按钮圆角

        tdArray[j].appendChild(button);

        let timerId = null;

        button.addEventListener('click', function() {
          if (timerId) {
            clearInterval(timerId);
            logdiv.innerHTML += '自动抽取已停止<br>';
            button.innerText = '自动抽取';
            timerId = null;
          } else {
            logdiv.innerHTML += '自动抽取已开始<br>';
            button.innerText = '停止自动抽取';
            timerId = setInterval(sendPostRequest, 10000);
          }
        });

        function sendPostRequest() {
          const currentPage = window.location.href;
          const currentPageNum = currentPage.substr(-2);
          const postUrl = 'https://pterclub.com/dolottery.php?set=' + currentPageNum;

          GM_xmlhttpRequest({
            method: 'POST',
            url: postUrl,
            onload: function(response) {
              logdiv.innerHTML += 'POST请求已完成<br>';
              logCount++;
              if (logCount >= 10) {
                logdiv.innerHTML = '';
                logCount = 0;
              }
            }
          });
        }

        break;
      }
    }
  }
})();