You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自动点击网站中指定人员的ASK按钮?

Solution: Filter & Click ASK Buttons for Names Ending with "KE"

Got it, let's tweak your existing script to target only the ASK buttons linked to people whose names end with "KE" (case-insensitive, so it catches both JAKE and Spike). We'll keep all your original timeout settings and add a counter to maintain the 1-second interval between valid clicks.

Modified Code

function clickAsk(){
  // Keep your existing click handler (updated to log the person's name instead of button HTML)
  $('button.ASK').on( 'click', function(){
    const personName = $(this).closest('.position').find('.name').text().trim();
    console.log('You clicked the ASK button for', personName);
  } );

  let validButtonCounter = 0; // Counter to track only matching buttons for consistent timing

  $('button.ASK').each( function(){
    // Get the associated person's name (adjust this selector to match your site's actual DOM structure!)
    const personName = $(this).closest('.position').find('.name').text().trim();

    // Check if the name ends with "KE" (case-insensitive to cover JAKE, Spike, etc.)
    if (personName.toLowerCase().endsWith('ke')) {
      // Use the valid counter for timing instead of the global loop index
      setTimeout(() => {
        $(this).click();
      }, validButtonCounter * 1000);
      validButtonCounter++; // Only increment for buttons that match our filter
    }
  } );
}

// Keep your original initial delay
setTimeout(clickAsk, 850);

Key Changes Explained

  • Name Matching Logic: We use toLowerCase().endsWith('ke') to make the check case-insensitive, so it works for uppercase, lowercase, and mixed-case names alike.
  • DOM Selector Adjustment: The line $(this).closest('.position').find('.name').text() assumes your site's HTML structure looks something like this:
    <div class="position">
      <span class="name">JAKE</span>
      <button class="ASK">ASK</button>
    </div>
    
    If your actual structure is different (e.g., the name is a direct sibling with a unique class), update this selector to correctly grab the person's name tied to each ASK button.
  • Valid Button Counter: Instead of using the global index from the each loop, we use validButtonCounter to only count buttons that meet our filter criteria. This ensures the 1-second interval between clicks stays consistent, even when we skip non-matching buttons.
  • Useful Console Log: The log now shows the person's name, making it easier to verify you're clicking the correct targets.

Quick Note

Double-check the selector for personName to match your site's actual DOM structure—this is the most critical part for the filter to work as expected. All your original timeout settings are preserved exactly as requested.

内容的提问来源于stack exchange,提问作者Fabian Montossi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:12:13