https://www.nodeseek.com/post-197252-1
传统意义上的脚本抢应该都是反复去请求一个生成订单的url吧,然后拿着获取到的订单号生成订单,但是我在实验过程中跨域问题很难解决,索性我直接上油猴脚本,监控控件然后去刷新点点点,虽然效率上比不上直接请求,但好歹给我们这些不会整代码的与脚本哥一战之力,毕竟油猴脚本代码交给ai去生成即可(后面测试代码claude3.5生成的,也就四五条对话)
受人以渔,
f12打开开发者,左上角选取你在网页里需要点点点的控件,右击复制元素下来,比如一些优惠吗,协议条款,机器配置,你需要监控的特殊按钮,你需要一些逻辑思维,比如监控可用数元素,为0时刷新网页继续监控,非0时去点击下单控件,告诉ai你的需求,详细描述他会给你意想不到的答案的
当然你点击了下单成功跳转到了另一个页面,你就可能要配置一套针对这个下单后这个页面的油猴脚本了,或者你直接盯着电脑,运气好网好就直接抢到了
至于频繁刷新被一些反机器人,这个需要调整访问频率看运气,总之慢慢调试
总觉得我的表达能力好差。。
放个ak的枪机油猴脚本,拿我这个去试试抢到就nb了,先得手动兑换以下优惠券 2024BlackFriday
https://akile.io/shop/server?type=traffic&areaId=5&nodeId=9&planId=898&shop_code=2024-blackfriday
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
// ==UserScript== // @name AkileCloud 商品监控助手 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 监控 AkileCloud 商品库存并自动下单 // @author You // @match https://akile.io/shop/server* // @icon https://www.google.com/s2/favicons?sz=64&domain=akile.io // @grant none // ==/UserScript== (function() { 'use strict'; const config = { refreshInterval: 5000, // 页面刷新间隔 clickInterval: 1000, // 购买按钮点击间隔 maxRetries: 999999, targetUrl: 'https://akile.io/shop/server?type=traffic&areaId=5&nodeId=9&planId=898&shop_code=2024-blackfriday', selectors: { buyButton: 'button.arco-btn.buy-btn', checkboxes: '.arco-checkbox-icon', confirmButton: '.confirm-button', couponSelect: '.arco-select-view-single', couponOption: '.arco-select-option' } }; let running = false; let retryCount = 0; let timer = null; let clickTimer = null; function getTime() { return new Date().toLocaleTimeString(); } function createStatusPanel() { const panel = document.createElement('div'); panel.id = 'monitor-status'; panel.style.cssText = ` position: fixed; top: 20px; right: 20px; background: rgba(0, 0, 0, 0.8); color: #fff; padding: 10px; border-radius: 5px; z-index: 9999; font-size: 12px; `; document.body.appendChild(panel); return panel; } function updateStatus(message) { const panel = document.getElementById('monitor-status') || createStatusPanel(); panel.innerHTML = ` <div>当前时间: ${getTime()}</div> <div>运行状态: ${running ? '监控中' : '已停止'}</div> <div>刷新次数: ${retryCount}</div> <div>最新状态: ${message}</div> `; } // 预选优惠券 async function selectCoupon() { try { const couponSelect = document.querySelector(config.selectors.couponSelect); if (!couponSelect) { updateStatus('未找到优惠券选择框'); return false; } updateStatus('点击优惠券选择框...'); couponSelect.click(); await new Promise(resolve => setTimeout(resolve, 500)); const couponOptions = document.querySelectorAll(config.selectors.couponOption); let couponFound = false; for (const option of couponOptions) { if (option.textContent.includes('2024BlackFriday')) { updateStatus('找到BlackFriday优惠券,正在选择...'); option.click(); couponFound = true; break; } } if (!couponFound) { updateStatus('未找到可用的优惠券'); return false; } await new Promise(resolve => setTimeout(resolve, 500)); return true; } catch (error) { console.error('选择优惠券时出错:', error); return false; } } // 预选协议 async function ensureAgreementsChecked() { const checkboxes = document.querySelectorAll(config.selectors.checkboxes); let allChecked = true; for (const checkbox of checkboxes) { if (!checkbox.querySelector('svg')) { checkbox.click(); allChecked = false; await new Promise(resolve => setTimeout(resolve, 100)); } } return allChecked; } // 预选所有必要选项 async function preSelectAll() { await selectCoupon(); await ensureAgreementsChecked(); } async function checkAndClick() { const buyButton = document.querySelector(config.selectors.buyButton); if (!buyButton) { updateStatus('未找到购买按钮'); return false; } const buttonText = buyButton.textContent.trim(); const isDisabled = buyButton.hasAttribute('disabled'); // 无论商品状态如何,都保持优惠券和协议的选中状态 await preSelectAll(); if (buttonText === '售罄' || isDisabled) { updateStatus('商品售罄,等待刷新...'); return false; } if (buttonText.includes('购买')) { updateStatus('找到可购买按钮,开始持续点击...'); return new Promise((resolve) => { const startUrl = window.location.href; let clickCount = 0; if (clickTimer) { clearInterval(clickTimer); } clickTimer = setInterval(() => { clickCount++; buyButton.click(); updateStatus(`正在点击第 ${clickCount} 次...`); if (window.location.href !== startUrl) { clearInterval(clickTimer); updateStatus('购买成功,页面已跳转!'); resolve(true); } }, config.clickInterval); // 设置超时 setTimeout(() => { if (clickTimer) { clearInterval(clickTimer); updateStatus('点击超时,准备重新开始...'); resolve(false); } }, 10000); }); } updateStatus('按钮状态未知,继续监控...'); return false; } function refreshPage() { window.location.href = config.targetUrl; } async function monitor() { if (!running) return; retryCount++; const result = await checkAndClick(); if (!result && running) { timer = setTimeout(() => { updateStatus('准备刷新页面...'); refreshPage(); }, config.refreshInterval); } } function stopMonitor() { running = false; if (timer) { clearTimeout(timer); } if (clickTimer) { clearInterval(clickTimer); } updateStatus('监控已停止'); } function addStopButton() { const container = document.createElement('div'); container.style.cssText = ` position: fixed; top: 150px; right: 20px; z-index: 9999; `; const stopButton = document.createElement('button'); stopButton.textContent = '停止监控'; stopButton.style.cssText = ` padding: 8px 16px; background: #f44336; color: white; border: none; border-radius: 4px; cursor: pointer; `; stopButton.onclick = stopMonitor; container.appendChild(stopButton); document.body.appendChild(container); } function startMonitoring() { if (!running) { running = true; retryCount = 0; updateStatus('开始监控...'); monitor(); } } async function init() { if (window.location.href.includes('shop/server')) { createStatusPanel(); addStopButton(); updateStatus('正在加载页面...'); // 等待页面加载完成后自动开始监控 const checkPageLoaded = setInterval(async () => { const buyButton = document.querySelector(config.selectors.buyButton); const checkboxes = document.querySelectorAll(config.selectors.checkboxes); if (buyButton && checkboxes.length > 0) { clearInterval(checkPageLoaded); updateStatus('页面加载完成,准备开始监控...'); // 页面加载完成后立即进行预选 await preSelectAll(); startMonitoring(); } }, 500); } } if (document.readyState === 'complete') { init(); } else { window.addEventListener('load', init); } })(); |
