設定閾值(%),當生成進度高於閾值的時候生成失敗,則自動點擊生成。
当前为
// ==UserScript==
// @name 自動點擊生成 (Grok Imagine) v1.0
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 設定閾值(%),當生成進度高於閾值的時候生成失敗,則自動點擊生成。
// @match https://grok.com/*
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
const targetClassString = 'text-xs font-semibold w-[4ch] mb-[1px]';
const selector = `div[class="${targetClassString}"]`;
let lastValue = null;
let wasPresent = false;
let autoMode = true;
let threshold = 50;
// === 時間格式 ===
function getTimeString() {
const now = new Date();
const pad = n => n.toString().padStart(2, '0');
return `[${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}]`;
}
// === 數值解析 ===
function parseNumber(text) {
if (!text) return null;
const match = text.match(/-?\d+(\.\d+)?/);
return match ? parseFloat(match[0]) : null;
}
// === 建立控制面板 ===
function createControlPanel() {
const panel = document.createElement('div');
panel.style.position = 'fixed';
panel.style.top = '80px'; // 🔹往下移動避免被遮擋
panel.style.right = '10px';
panel.style.zIndex = '99999';
panel.style.background = 'rgba(30,30,30,0.9)';
panel.style.color = '#fff';
panel.style.padding = '10px 15px';
panel.style.borderRadius = '10px';
panel.style.fontSize = '14px';
panel.style.fontFamily = 'monospace';
panel.style.boxShadow = '0 4px 12px rgba(0,0,0,0.6)';
panel.style.backdropFilter = 'blur(5px)';
panel.style.width = '320px';
panel.style.maxHeight = '420px';
panel.style.overflow = 'hidden';
panel.style.display = 'flex';
panel.style.flexDirection = 'column';
panel.style.pointerEvents = 'auto';
// 控制區
const controlsHTML = `
<div style="margin-bottom:6px; font-weight:bold;">Grok 檢查控制</div>
<label style="display:flex; align-items:center; gap:6px; margin-bottom:4px;">
<input type="checkbox" id="autoModeToggle" checked />
自動模式
</label>
<label style="display:flex; align-items:center; gap:6px; margin-bottom:6px;">
閥值:
<input type="number" id="thresholdInput" value="${threshold}" min="0" max="100" step="1"
style="width:60px; padding:2px; border-radius:4px; border:none; text-align:center;">
</label>
`;
// console 區
const consoleBox = document.createElement('div');
consoleBox.id = 'grok-console';
consoleBox.style.flex = '1';
consoleBox.style.background = 'rgba(0,0,0,0.3)';
consoleBox.style.padding = '6px';
consoleBox.style.borderRadius = '6px';
consoleBox.style.overflowY = 'auto';
consoleBox.style.fontSize = '12px';
consoleBox.style.lineHeight = '1.4';
consoleBox.style.whiteSpace = 'pre-wrap';
// 清除按鈕(可選)
const clearBtn = document.createElement('button');
clearBtn.textContent = '🧹 清空紀錄';
clearBtn.style.marginTop = '6px';
clearBtn.style.background = 'rgba(255,255,255,0.1)';
clearBtn.style.border = 'none';
clearBtn.style.color = '#ccc';
clearBtn.style.padding = '4px 8px';
clearBtn.style.borderRadius = '4px';
clearBtn.style.cursor = 'pointer';
clearBtn.style.fontSize = '12px';
clearBtn.addEventListener('mouseenter', () => clearBtn.style.color = '#fff');
clearBtn.addEventListener('mouseleave', () => clearBtn.style.color = '#ccc');
clearBtn.addEventListener('click', () => (consoleBox.innerHTML = ''));
panel.innerHTML = controlsHTML;
panel.appendChild(consoleBox);
panel.appendChild(clearBtn);
document.body.appendChild(panel);
// 綁定控制事件
const autoModeToggle = panel.querySelector('#autoModeToggle');
const thresholdInput = panel.querySelector('#thresholdInput');
autoModeToggle.addEventListener('change', () => {
autoMode = autoModeToggle.checked;
console.log(`${getTimeString()} 自動模式: ${autoMode ? '啟用' : '停用'}`);
});
thresholdInput.addEventListener('change', () => {
threshold = parseFloat(thresholdInput.value);
console.log(`${getTimeString()} 閥值更新為 ${threshold}`);
});
return consoleBox;
}
// === 攔截 console.log ===
function hookConsole(consoleBox) {
const originalLog = console.log;
console.log = (...args) => {
originalLog.apply(console, args);
const msg = args.join(' ');
const entry = document.createElement('div');
if (msg.includes('成功')) entry.style.color = '#6eff9f';
else if (msg.includes('失敗')) entry.style.color = '#ff7b7b';
else if (msg.includes('閥值') || msg.includes('模式')) entry.style.color = '#ffd966';
else entry.style.color = '#ccc';
entry.textContent = msg;
consoleBox.appendChild(entry);
consoleBox.scrollTop = consoleBox.scrollHeight;
};
}
// === 主邏輯 ===
function check() {
if (!autoMode) return;
const elem = document.querySelector(selector);
if (elem) {
wasPresent = true;
const val = parseNumber(elem.textContent.trim());
if (!isNaN(val)) lastValue = val;
} else if (wasPresent) {
wasPresent = false;
const progress = lastValue !== null ? `${lastValue}%` : "未知";
const container = document.querySelector('div.relative.mx-auto.rounded-2xl.overflow-hidden');
let success = false;
if (container) {
const grid = container.querySelector('div.grid');
if (grid && grid.querySelector('video#sd-video')) {
console.log(`${getTimeString()} 生成成功 (進度:${progress})`);
success = true;
}
}
if (!success) {
if (lastValue !== null && lastValue >= threshold) {
console.log(`${getTimeString()} 生成失敗 (進度:${progress})`);
const button = document.querySelector('button[aria-label="製作影片"]');
if (button) {
const section = document.querySelector('section[aria-label="Notifications alt+T"]');
let attempts = 0;
const maxAttempts = 100;
const intervalId = setInterval(() => {
const exists = section && section.querySelector('span')?.textContent.trim() === "Content Moderated. Try a different idea.";
attempts++;
if (exists) {
button.click();
console.log(`${getTimeString()} 已點擊製作影片按鈕`);
clearInterval(intervalId);
} else if (attempts >= maxAttempts) {
console.log(`${getTimeString()} 失敗訊息超時仍未出現`);
clearInterval(intervalId);
}
}, 500);
} else {
console.log(`${getTimeString()} 找不到製作影片按鈕`);
}
}else{
console.log(`${getTimeString()} 生成失敗且低於閾值 (進度:${progress})`);
}
}
lastValue = null;
}
}
// === 啟動 ===
const consoleBox = createControlPanel();
hookConsole(consoleBox);
setInterval(check, 500);
})();