-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
735 lines (661 loc) · 22.4 KB
/
script.js
File metadata and controls
735 lines (661 loc) · 22.4 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
// ==UserScript==
// @name 智谱 GLM Coding 终极抢购助手 (合并版)
// @namespace http://tampermonkey.net/
// @version 3.4
// @description 合并版:去除按钮disabled + 全自动抢购 + 双重校验 + 错误弹窗自动恢复 + 主动模式 + 定时触发(已修复二维码弹窗被关闭问题)
// @author YourName
// @match *://www.bigmodel.cn/*
// @match https://www.bigmodel.cn/glm-coding
// @match https://bigmodel.cn/glm-coding*
// @run-at document-start
// @grant none
// @buy me a coffee 邀请链接,邀请码新购,下单立减5%金额 https://www.bigmodel.cn/glm-coding?ic=ISKOMMVBRB
// @license MIT
// ==/UserScript==
(function () {
"use strict";
// ======================== 配置 ========================
const CFG = {
delay: 100,
maxRetry: 300,
PREVIEW: "/api/biz/pay/preview",
CHECK: "/api/biz/pay/check",
};
// ======================== 全局状态 ========================
const S = {
status: "idle",
count: 0,
bizId: null,
captured: null,
cache: null,
lastSuccess: null,
proactive: false,
timerId: null,
logs: [],
};
let stopRequested = false;
let recovering = false;
let recoveryAttempts = 0;
// ======================== 工具函数 ========================
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const ts = () => new Date().toLocaleTimeString("zh-CN", { hour12: false });
function log(msg) {
S.logs.push(`${ts()} ${msg}`);
if (S.logs.length > 80) S.logs.shift();
console.log(`[GLM抢购] ${msg}`);
refreshLog();
}
function extractHeaders(h) {
const o = {};
if (!h) return o;
if (h instanceof Headers) h.forEach((v, k) => (o[k] = v));
else if (Array.isArray(h)) h.forEach(([k, v]) => (o[k] = v));
else Object.entries(h).forEach(([k, v]) => (o[k] = v));
return o;
}
// ======================== JSON.parse 深层篡改 (UI 补丁) ========================
const _parse = JSON.parse;
JSON.parse = function (text, reviver) {
let result = _parse(text, reviver);
try {
(function fix(obj) {
if (!obj || typeof obj !== "object") return;
// ========== 合并两份逻辑 ==========
if (obj.isSoldOut === true) obj.isSoldOut = false;
if (obj.soldOut === true) obj.soldOut = false;
if (
obj.disabled === true &&
(obj.price !== undefined || obj.productId || obj.title)
)
obj.disabled = false;
if (obj.stock === 0) obj.stock = 999;
for (let k in obj)
if (obj[k] && typeof obj[k] === "object") fix(obj[k]);
})(result);
} catch (e) {}
return result;
};
// ======================== 核心重试引擎 ========================
const _fetch = window.fetch;
let _retryPromise = null;
async function retry(url, opts) {
if (_retryPromise) {
log("⏳ 合并到当前重试…");
return _retryPromise;
}
stopRequested = false;
_retryPromise = (async () => {
S.status = "retrying";
S.count = 0;
refreshUI();
const { signal, ...cleanOpts } = opts || {};
for (let i = 1; i <= CFG.maxRetry; i++) {
if (stopRequested) {
log("⏹ 重试被手动停止");
break;
}
S.count = i;
refreshUI();
try {
const resp = await _fetch(url, {
...cleanOpts,
credentials: "include",
});
const text = await resp.text();
let data;
try {
data = _parse(text);
} catch {
data = null;
}
if (data && data.code === 200 && data.data && data.data.bizId) {
const bizId = data.data.bizId;
log(`🔑 获取到 bizId=${bizId},正在校验 check 接口…`);
try {
const checkUrl = `${location.origin}${CFG.CHECK}?bizId=${bizId}`;
const checkResp = await _fetch(checkUrl, {
credentials: "include",
});
const checkText = await checkResp.text();
let checkData;
try {
checkData = _parse(checkText);
} catch {
checkData = null;
}
if (checkData && checkData.data === "EXPIRE") {
log(`#${i} bizId 已过期(EXPIRE),继续重试…`);
await sleep(CFG.delay);
continue;
}
S.status = "success";
S.bizId = bizId;
S.lastSuccess = { text, data };
log(`✅ 抢购成功! bizId=${bizId}, check 校验通过 (第${i}次)`);
refreshUI();
recoveryAttempts = 0;
setTimeout(autoRecover, 600);
return { ok: true, text, data, status: resp.status };
} catch (checkErr) {
log(`#${i} check 校验异常: ${checkErr.message},继续重试…`);
await sleep(CFG.delay);
continue;
}
}
const why = !data
? "非JSON响应"
: data.code === 555
? "系统繁忙(555)"
: data.data && data.data.bizId === null
? "售罄(bizId=null)"
: `未知(code=${data.code})`;
if (i <= 5 || i % 20 === 0) log(`#${i} ${why}`);
} catch (e) {
if (i <= 3 || i % 20 === 0) log(`#${i} 网络错误: ${e.message}`);
}
await sleep(CFG.delay);
}
if (!stopRequested) {
S.status = "failed";
log(`❌ 达到上限 ${CFG.maxRetry} 次`);
} else {
S.status = "idle";
}
refreshUI();
return { ok: false };
})();
try {
return await _retryPromise;
} finally {
_retryPromise = null;
}
}
// ======================== 错误弹窗自动恢复 ========================
function findErrorDialog() {
const selectors = [
".el-dialog",
".el-message-box",
".el-dialog__wrapper",
".ant-modal",
".ant-modal-wrap",
'[class*="modal"]',
'[class*="dialog"]',
'[class*="popup"]',
'[role="dialog"]',
];
for (const sel of selectors) {
for (const el of document.querySelectorAll(sel)) {
const style = window.getComputedStyle(el);
if (
style.display === "none" ||
style.visibility === "hidden" ||
style.opacity === "0"
)
continue;
if (!el.offsetParent && style.position !== "fixed") continue;
const text = el.textContent || "";
// ========== 排除二维码/支付弹窗 ==========
if (/二维码|扫码|支付|QRCode|qrcode|微信|支付宝/i.test(text)) continue;
if (
/购买人数过多|系统繁忙|稍后再试|请重试|繁忙|失败|出错|异常/.test(text)
) {
return el;
}
}
}
return null;
}
function dismissDialog(dialog) {
const closeSelectors = [
".el-dialog__headerbtn",
".el-message-box__headerbtn",
".el-dialog__close",
".ant-modal-close",
'[class*="close-btn"]',
'[class*="closeBtn"]',
'[aria-label="Close"]',
'[aria-label="close"]',
];
for (const sel of closeSelectors) {
const btn = dialog.querySelector(sel) || document.querySelector(sel);
if (btn && btn.offsetParent !== null) {
btn.click();
log("🔄 点击关闭按钮");
return true;
}
}
const btns = dialog.querySelectorAll('button, [role="button"]');
for (const btn of btns) {
const t = (btn.textContent || "").trim();
if (
/关闭|确定|取消|知道了|OK|Cancel|Close|确认/.test(t) &&
t.length < 10
) {
btn.click();
log(`🔄 点击 [${t}] 按钮`);
return true;
}
}
document.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Escape",
keyCode: 27,
bubbles: true,
}),
);
document.dispatchEvent(
new KeyboardEvent("keyup", { key: "Escape", keyCode: 27, bubbles: true }),
);
log("🔄 发送 Escape 键");
const masks = document.querySelectorAll(
'.el-overlay, .v-modal, .el-overlay-dialog, [class*="overlay"], [class*="mask"]',
);
for (const mask of masks) {
if (
mask.offsetParent !== null ||
window.getComputedStyle(mask).position === "fixed"
) {
mask.click();
log("🔄 点击遮罩层");
return true;
}
}
dialog.style.display = "none";
const overlays = document.querySelectorAll(".el-overlay, .v-modal");
overlays.forEach((o) => (o.style.display = "none"));
log("🔄 强制隐藏弹窗");
return true;
}
async function autoRecover() {
if (recovering || recoveryAttempts >= 3) return;
if (!S.lastSuccess) return;
const dialog = findErrorDialog();
if (!dialog) return;
recovering = true;
recoveryAttempts++;
log(`🔄 自动恢复 #${recoveryAttempts}:关闭弹窗…`);
dismissDialog(dialog);
await sleep(300);
if (S.cache) {
log("🔄 返回缓存的成功响应");
const c = S.cache;
S.cache = null;
const btn = findBuyButton();
if (btn) {
btn.click();
log("🔄 自动点击购买按钮");
}
} else {
log("⚠️ 无缓存,尝试重新点击购买按钮");
const btn = findBuyButton();
if (btn) btn.click();
}
recovering = false;
}
function setupDialogWatcher() {
setInterval(() => {
if (S.lastSuccess && !recovering && recoveryAttempts < 3) {
const dialog = findErrorDialog();
if (dialog) autoRecover();
}
}, 500);
}
// ======================== Fetch 拦截器 ========================
window.fetch = async function (input, init) {
const url = typeof input === "string" ? input : input?.url;
if (url && url.includes(CFG.PREVIEW)) {
S.captured = {
url,
method: init?.method || "POST",
body: init?.body,
headers: extractHeaders(init?.headers),
};
log("🎯 捕获 preview 请求 (Fetch)");
refreshUI();
if (S.cache) {
log("📦 返回缓存的成功响应");
const c = S.cache;
S.cache = null;
recoveryAttempts = 0;
return new Response(c.text, {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
const result = await retry(url, {
method: init?.method || "POST",
body: init?.body,
headers: extractHeaders(init?.headers),
signal: init?.signal,
});
if (result.ok) {
return new Response(result.text, {
status: result.status,
headers: { "Content-Type": "application/json" },
});
}
return _fetch.apply(this, [input, init]);
}
if (url && url.includes(CFG.CHECK) && url.includes("bizId=null")) {
log("🚫 拦截 check(bizId=null)");
return new Response(JSON.stringify({ code: -1, msg: "等待有效bizId" }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
return _fetch.apply(this, [input, init]);
};
// ======================== XHR 拦截器 ========================
const _xhrOpen = XMLHttpRequest.prototype.open;
const _xhrSend = XMLHttpRequest.prototype.send;
const _xhrSetHeader = XMLHttpRequest.prototype.setRequestHeader;
XMLHttpRequest.prototype.setRequestHeader = function (k, v) {
(this._h || (this._h = {}))[k] = v;
return _xhrSetHeader.call(this, k, v);
};
XMLHttpRequest.prototype.open = function (method, url) {
this._m = method;
this._u = url;
return _xhrOpen.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function (body) {
const url = this._u;
if (typeof url === "string" && url.includes(CFG.PREVIEW)) {
const self = this;
S.captured = { url, method: this._m, body, headers: this._h || {} };
log("🎯 捕获 preview 请求 (XHR)");
refreshUI();
if (S.cache) {
log("📦 返回缓存的成功响应 (XHR)");
const c = S.cache;
S.cache = null;
recoveryAttempts = 0;
fakeXHR(self, c.text);
return;
}
retry(url, { method: this._m, body, headers: this._h || {} }).then(
(result) => {
fakeXHR(
self,
result.ok ? result.text : '{"code":-1,"msg":"重试失败"}',
);
},
);
return;
}
if (
typeof url === "string" &&
url.includes(CFG.CHECK) &&
url.includes("bizId=null")
) {
log("🚫 拦截 check(bizId=null) (XHR)");
fakeXHR(this, '{"code":-1,"msg":"等待有效bizId"}');
return;
}
return _xhrSend.call(this, body);
};
function fakeXHR(xhr, text) {
setTimeout(() => {
const dp = (k, v) =>
Object.defineProperty(xhr, k, { value: v, configurable: true });
dp("readyState", 4);
dp("status", 200);
dp("statusText", "OK");
dp("responseText", text);
dp("response", text);
const rsc = new Event("readystatechange");
if (typeof xhr.onreadystatechange === "function")
xhr.onreadystatechange(rsc);
xhr.dispatchEvent(rsc);
const load = new ProgressEvent("load");
if (typeof xhr.onload === "function") xhr.onload(load);
xhr.dispatchEvent(load);
xhr.dispatchEvent(new ProgressEvent("loadend"));
}, 0);
}
// ======================== 主动抢购模式 ========================
async function startProactive() {
if (!S.captured) {
log("⚠️ 请先手动点一次购买/订阅按钮");
alert("请先手动点一次购买/订阅按钮,让脚本捕获请求参数");
return;
}
S.proactive = true;
log("🚀 主动抢购模式启动");
const { url, method, body, headers } = S.captured;
const result = await retry(url, { method, body, headers });
S.proactive = false;
if (result.ok) {
S.cache = { text: result.text, data: result.data };
log("🎉 主动模式成功! 触发购买流程…");
const errDlg = findErrorDialog();
if (errDlg) {
dismissDialog(errDlg);
await sleep(300);
}
const btn = findBuyButton();
if (btn) {
btn.click();
log("🖱 已自动点击购买按钮");
} else {
log("⚠️ 未找到按钮,请手动点击");
alert("已获取到商品!请立即点击购买按钮!");
}
}
}
function stopAll() {
stopRequested = true;
S.proactive = false;
S.status = "idle";
S.count = 0;
if (S.timerId) {
clearTimeout(S.timerId);
S.timerId = null;
}
log("⏹ 已停止");
refreshUI();
}
function findBuyButton() {
for (const el of document.querySelectorAll(
'button, a, [role="button"], div[class*="btn"], span[class*="btn"]',
)) {
const t = el.textContent.trim();
if (
/购买|抢购|立即|下单|订阅/.test(t) &&
t.length < 20 &&
el.offsetParent !== null
) {
return el;
}
}
return null;
}
// ======================== 定时触发 ========================
function scheduleAt(timeStr) {
if (S.timerId) {
clearTimeout(S.timerId);
S.timerId = null;
}
const parts = timeStr.split(":").map(Number);
const now = new Date();
const target = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
parts[0],
parts[1],
parts[2] || 0,
);
if (target <= now) {
log("⚠️ 目标时间已过");
return;
}
const ms = target - now;
log(`⏰ 已设定: ${timeStr} (${Math.ceil(ms / 1000)}秒后)`);
S.timerId = setTimeout(() => {
S.timerId = null;
log("⏰ 时间到! 启动抢购!");
if (S.captured) {
startProactive();
} else {
const btn = findBuyButton();
if (btn) {
btn.click();
log("🖱 定时: 已点击购买按钮");
} else {
log("⚠️ 未找到按钮");
alert("定时到了!请手动点击购买!");
}
}
}, ms - 50);
refreshUI();
}
// ======================== 浮动控制面板 ========================
function createPanel() {
const panel = document.createElement("div");
panel.id = "glm-rush";
panel.innerHTML = `
<style>
#glm-rush{position:fixed;top:10px;right:10px;width:340px;background:#1a1a2e;color:#e0e0e0;
border-radius:12px;box-shadow:0 4px 24px rgba(0,0,0,.6);z-index:999999;
font:13px/1.5 Consolas,'Courier New',monospace;user-select:none}
#glm-rush *{box-sizing:border-box;margin:0;padding:0}
.glm-hd{background:linear-gradient(135deg,#0f3460,#16213e);padding:9px 14px;
border-radius:12px 12px 0 0;display:flex;justify-content:space-between;align-items:center;cursor:move}
.glm-hd b{font-size:14px;letter-spacing:.5px}
.glm-mn{background:none;border:none;color:#aaa;cursor:pointer;font-size:20px;line-height:1;padding:0 4px}
.glm-mn:hover{color:#fff}
.glm-bd{padding:12px 14px 14px}
.glm-st{padding:8px;border-radius:8px;text-align:center;font-weight:700;margin-bottom:10px;transition:background .3s}
.glm-st-idle{background:#2d3436}
.glm-st-retrying{background:#e17055;animation:glm-pulse 1s infinite}
.glm-st-success{background:#00b894}
.glm-st-failed{background:#d63031}
@keyframes glm-pulse{50%{opacity:.7}}
.glm-cap{font-size:11px;padding:5px 8px;background:#2d3436;border-radius:6px;margin-bottom:10px;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.glm-row{display:flex;align-items:center;gap:6px;margin-bottom:8px;font-size:12px;flex-wrap:wrap}
.glm-row input[type=number],.glm-row input[type=time]{
width:72px;padding:4px 6px;border:1px solid #444;border-radius:4px;
background:#2d3436;color:#fff;text-align:center;font-size:12px}
.glm-btns{display:flex;gap:8px;margin-bottom:10px}
.glm-btns button{flex:1;padding:8px;border:none;border-radius:6px;cursor:pointer;
font-weight:700;font-size:12px;color:#fff;transition:opacity .2s}
.glm-btns button:hover{opacity:.85}
.glm-b-go{background:#0984e3}
.glm-b-stop{background:#d63031}
.glm-b-time{background:#6c5ce7;flex:0 0 auto !important;padding:4px 10px !important}
.glm-logs{max-height:170px;overflow-y:auto;background:#0d1117;border-radius:6px;
padding:6px 8px;font-size:11px;line-height:1.7}
.glm-logs div{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.glm-logs::-webkit-scrollbar{width:4px}
.glm-logs::-webkit-scrollbar-thumb{background:#444;border-radius:2px}
</style>
<div class="glm-hd" id="glm-drag">
<b>🎯 GLM 抢购助手 v3.4</b>
<button class="glm-mn" id="glm-min">−</button>
</div>
<div class="glm-bd" id="glm-bd">
<div class="glm-st glm-st-idle" id="glm-st">⏳ 等待中</div>
<div class="glm-cap" id="glm-cap">📡 请求: 未捕获 — 请先点一次购买按钮</div>
<div class="glm-row">
<span>间隔</span><input type="number" id="glm-delay" value="${CFG.delay}" min="50" max="5000" step="50"><span>ms</span>
<span style="margin-left:6px">上限</span><input type="number" id="glm-max" value="${CFG.maxRetry}" min="10" max="9999" step="10"><span>次</span>
</div>
<div class="glm-row">
<span>定时</span><input type="time" id="glm-time" step="1">
<button class="glm-b-time" id="glm-time-set">设定</button>
<span id="glm-timer-info" style="color:#6c5ce7;font-size:11px"></span>
</div>
<div class="glm-btns">
<button class="glm-b-go" id="glm-go">▶ 主动抢购</button>
<button class="glm-b-stop" id="glm-stop" style="display:none">■ 停止</button>
</div>
<div class="glm-logs" id="glm-logs"></div>
</div>`;
document.body.appendChild(panel);
const $ = (id) => document.getElementById(id);
$("glm-go").onclick = startProactive;
$("glm-stop").onclick = stopAll;
$("glm-delay").onchange = function () {
CFG.delay = Math.max(50, +this.value || 100);
};
$("glm-max").onchange = function () {
CFG.maxRetry = Math.max(10, +this.value || 300);
};
$("glm-time-set").onclick = function () {
const v = $("glm-time").value;
if (v) scheduleAt(v);
};
$("glm-min").onclick = function () {
const bd = $("glm-bd");
const hidden = bd.style.display === "none";
bd.style.display = hidden ? "" : "none";
this.textContent = hidden ? "−" : "+";
};
// 拖拽
let sx, sy, sl, st;
$("glm-drag").onmousedown = function (e) {
sx = e.clientX;
sy = e.clientY;
const rect = panel.getBoundingClientRect();
sl = rect.left;
st = rect.top;
const onMove = function (e) {
panel.style.left = sl + e.clientX - sx + "px";
panel.style.top = st + e.clientY - sy + "px";
panel.style.right = "auto";
};
const onUp = function () {
document.removeEventListener("mousemove", onMove);
document.removeEventListener("mouseup", onUp);
};
document.addEventListener("mousemove", onMove);
document.addEventListener("mouseup", onUp);
};
log("🚀 v3.3 已加载 (合并版)");
setupDialogWatcher();
}
function refreshUI() {
const stEl = document.getElementById("glm-st");
if (!stEl) return;
stEl.className = "glm-st glm-st-" + S.status;
stEl.textContent =
S.status === "idle"
? "⏳ 等待中"
: S.status === "retrying"
? `🔄 重试中… ${S.count}/${CFG.maxRetry}`
: S.status === "success"
? `✅ 成功! bizId=${S.bizId}`
: `❌ 失败 (${S.count}次)`;
const capEl = document.getElementById("glm-cap");
if (capEl) {
capEl.textContent = S.captured
? `📡 已捕获: ${S.captured.method} …${S.captured.url.split("?")[0].slice(-30)}`
: "📡 请求: 未捕获 — 请先点一次购买按钮";
}
const goBtn = document.getElementById("glm-go");
const stopBtn = document.getElementById("glm-stop");
if (goBtn && stopBtn) {
goBtn.style.display = S.status === "retrying" ? "none" : "";
stopBtn.style.display = S.status === "retrying" ? "" : "none";
}
}
function refreshLog() {
const el = document.getElementById("glm-logs");
if (!el) return;
const last = S.logs[S.logs.length - 1];
if (last) {
const div = document.createElement("div");
div.textContent = last;
el.appendChild(div);
el.scrollTop = el.scrollHeight;
}
}
// ======================== 启动 ========================
if (document.body) {
createPanel();
} else {
document.addEventListener("DOMContentLoaded", createPanel);
}
})();