编写Greasemonkey脚本:日历可用日期出现时自动点击
Auto-Click Available Calendar Dates with Greasemonkey/Tampermonkey
Here's a script that will periodically check your calendar page for available dates (marked with the FULL class on the <td> element) and automatically click them as soon as they become accessible:
// ==UserScript== // @name Auto-Click Available Calendar Dates // @namespace http://tampermonkey.net/ // @version 0.1 // @description Automatically clicks available dates when they appear on the calendar // @match https://your-calendar-page-url.com/* // @grant none // ==/UserScript== (function() { 'use strict'; function checkAndClickAvailableDates() { // Target all unclicked available date links const availableDateLinks = document.querySelectorAll('td.FULL a:not(.already-clicked)'); availableDateLinks.forEach(link => { // Trigger the click event (matches manual user interaction) link.click(); // Mark the link as clicked to avoid repeated clicks link.classList.add('already-clicked'); console.log(`Auto-clicked date: ${link.textContent.trim()}`); }); } // Run the check immediately on script load checkAndClickAvailableDates(); // Repeat the check every 1 second (1000ms) - adjust this value as needed setInterval(checkAndClickAvailableDates, 1000); })();
Key Details & Customization Tips:
- Target URL: Replace
https://your-calendar-page-url.com/*in the@matchline with the actual URL of your calendar page. This ensures the script only runs where it's needed. - Check Interval: The
1000value insetIntervalis the time between checks in milliseconds. If dates become available less frequently, you can increase this (e.g.,5000for 5 seconds) to reduce unnecessary page checks. If they appear quickly, decrease it (but avoid going below 500ms to prevent performance issues). - Prevent Re-Clicks: The script adds an
already-clickedclass to each link after clicking it, so it won't click the same date multiple times. If you want to re-check dates (e.g., if the calendar resets), you can remove this part. - How It Works: The script looks for
<a>elements inside<td>tags with theFULLclass (the marker for available dates in your provided HTML). It simulates a user click, which triggers theschedule()function exactly like manual interaction would.
Installation Steps:
- Install Greasemonkey (Firefox) or Tampermonkey (Chrome/Edge) if you haven't already.
- Create a new userscript and paste the code above.
- Update the
@matchURL to your calendar page's URL. - Save the script and navigate to your calendar page—it will start working automatically.
内容的提问来源于stack exchange,提问作者kinase
相关产品推荐
相关产品推荐

