// ==UserScript== // @name Dahlia Refresh and Click until 12:00:100 // @namespace http://tampermonkey.net/ // @version 0.5 // @description Refresh the page every 10ms until 12:00:100 PM, then check for and click the specified button // @match https://www.cotaiticketing.com/shows/hinscheung2024.html // @grant none // ==/UserScript== (function() { 'use strict'; const buttonTexts = ["Buy Now", "立即购票", "立即購票"]; let refreshCount = 0; let pollingIntervalId = null; // 检查当前时间是否达到或超过12:00:100 function shouldStartCheckingButtons() { const now = new Date(); const startHour = 12; const startMinute = 0; const startSecond = 0; const startMillisecond = 100; return now.getHours() >= startHour && now.getMinutes() >= startMinute && now.getSeconds() >= startSecond && now.getMilliseconds() >= startMillisecond; } function checkForButton() { for (let text of buttonTexts) { let button = Array.from(document.querySelectorAll('button, a')).find(el => el.textContent.includes(text)); if (button) { button.click(); console.log(`Clicked button with text: "${text}"`); return true; } } return false; } function startRefreshing() { const refreshIntervalId = setInterval(() => { refreshCount++; // 每10秒更新一次控制台中的刷新次数 if (refreshCount % 1000 === 0) { console.log(`Page refreshed ${refreshCount} times`); } // 检查时间,如果到了12:00:100则停止刷新并开始检查按钮 if (shouldStartCheckingButtons()) { clearInterval(refreshIntervalId); startPolling(); console.log('Stopped refreshing and started polling for buttons.'); } else { // 自动刷新页面 location.reload(); } }, 10); // 每隔10毫秒刷新一次页面 } function startPolling() { pollingIntervalId = setInterval(() => { if (checkForButton()) { clearInterval(pollingIntervalId); console.log('Button found and clicked. Stopping polling.'); } }, 10); // 每隔10毫秒检查一次按钮 } // 启动刷新流程 startRefreshing(); })();