const CONFIG = {
// 固定不变的前缀
prefix: 'HP3FREE-T',
// 随机后缀长度
suffixLen: 4,
// 随机字符集:大写字母 + 数字
charset: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
// 每次输入的间隔毫秒数
intervalMs: 800,
// 输入框 CSS 选择器
selector: '#promotionCode',
// 提交按钮选择器
submitSelector: '[class*="applyButton"]',
// 成功判定回调
successCheck: () =>
document.body.innerText.includes('输入正确') ||
document.body.innerText.includes('验证成功') ||
document.body.innerText.includes('正确'),
};
// ================================================================
// 优化后的脚本逻辑
// ================================================================
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// 安全且不重复的生成逻辑:使用 Set 去重
class CodeGenerator {
constructor(prefix, suffixLen, charset) {
this.prefix = prefix;
this.suffixLen = suffixLen;
this.charset = charset;
this.testedCodes = new Set();
}
generate() {
const cs = this.charset;
const len = this.suffixLen;
const maxAttempts = 100;
let attempts = 0;
while (attempts < maxAttempts) {
const arr = new Uint32Array(len);
crypto.getRandomValues(arr);
let suffix = '';
for (let i = 0; i < len; i++) {
suffix += cs[arr[i] % cs.length];
}
const code = this.prefix + suffix;
if (!this.testedCodes.has(code)) {
this.testedCodes.add(code);
return code;
}
attempts++;
}
throw new Error('穷举碰撞空间已满或随机碰撞率过高');
}
}
// 兼容现代前端框架的原生值设置
function setNativeValue(el, value) {
const prototype =
el.tagName === 'TEXTAREA'
? HTMLTextAreaElement.prototype
: HTMLInputElement.prototype;
const valueSetter = Object.getOwnPropertyDescriptor(prototype, 'value')?.set;
if (valueSetter) {
valueSetter.call(el, value);
} else {
el.value = value;
}
el.dispatchEvent(new Event('input', { bubbles: true }));
}
// 填充输入框
function fillInput(el, value) {
el.focus();
setNativeValue(el, value);
el.dispatchEvent(new Event('change', { bubbles: true }));
}
// 动态查找提交按钮(应对 DOM 重新渲染)
function getSubmitButton() {
if (CONFIG.submitSelector) {
const btn = document.querySelector(CONFIG.submitSelector);
if (btn) return btn;
}
return (
Array.from(document.querySelectorAll('button')).find(
(btn) => btn.textContent.trim().toLowerCase() === 'apply'
) || null
);
}
// 主执行函数
async function run() {
window.__stopGen = false;
window.__pauseGen = false;
const generator = new CodeGenerator(CONFIG.prefix, CONFIG.suffixLen, CONFIG.charset);
console.log('▶ [自动碰撞脚本已启动]');
console.log(` 固定前缀: ${CONFIG.prefix}`);
console.log(' ⏸ 暂停/恢复: 控制台输入 window.__pauseGen = !window.__pauseGen');
console.log(' ⏹ 完全停止: 控制台输入 window.__stopGen = true 或快捷键 [Alt + Q]');
// 改用 Alt+Q 避免占用全局复制快捷键 Ctrl+C
const onKeydown = (e) => {
if (e.altKey && e.key.toLowerCase() === 'q') {
e.preventDefault();
window.__stopGen = true;
console.log('⏹ 手动触发 [Alt + Q],强制终止碰撞程序。');
}
};
window.addEventListener('keydown', onKeydown);
let count = 0;
try {
while (!window.__stopGen) {
if (window.__pauseGen) {
await sleep(200);
continue;
}
// 动态获取最新 DOM 元素
const inputEl = document.querySelector(CONFIG.selector);
if (!inputEl) {
console.error('❌ 未匹配到输入框元素,将在 1 秒后重试...');
await sleep(1000);
continue;
}
const submitBtn = getSubmitButton();
const code = generator.generate();
fillInput(inputEl, code);
if (submitBtn) {
submitBtn.click();
}
count++;
console.log(`[${count}] 尝试提交验证码: ${code}`);
await sleep(CONFIG.intervalMs);
// 验证成功判定
if (CONFIG.successCheck()) {
console.log(`🎉 碰撞成功!正确激活码为: %c${code}`, 'color: green; font-weight: bold; font-size: 14px;');
console.log(`共计尝试次数: ${count}`);
window.__stopGen = true;
break;
}
}
} catch (err) {
console.error('❌ 脚本运行异常中止:', err.message);
} finally {
window.removeEventListener('keydown', onKeydown);
console.log('⏹ 脚本执行已安全结束。');
}
}
// 启动运行
run();
7
22
22 条回复
排序