// ==UserScript== // @name 智谱 GLM Coding 快速订阅助手 (优化版) // @name:en 智谱 GLM Coding Fast Subscription Helper (Optimized) // @namespace http://tampermonkey.net/ // @version 7.2.0 // @description 优化性能与结构,解除按钮限制,自动分配快捷键映射 // @description:en Optimize performance and structure, remove button restrictions, and automatically allocate shortcut key mappings // @author Tim // @match *://www.bigmodel.cn/* // @match https://www.bigmodel.cn/glm-coding // @match https://bigmodel.cn/glm-coding* // @run-at document-start // @grant none // @license MIT // @buy me a coff 邀请链接,邀请码新购,下单立减5%金额 https://www.bigmodel.cn/glm-coding?ic=EAADSLV8VZ // @downloadURL https://update.greasyfork.icu/scripts/573121/%E6%99%BA%E8%B0%B1%20GLM%20Coding%20%E5%BF%AB%E9%80%9F%E8%AE%A2%E9%98%85%E5%8A%A9%E6%89%8B%20%28%E4%BC%98%E5%8C%96%E7%89%88%29.user.js // @updateURL https://update.greasyfork.icu/scripts/573121/%E6%99%BA%E8%B0%B1%20GLM%20Coding%20%E5%BF%AB%E9%80%9F%E8%AE%A2%E9%98%85%E5%8A%A9%E6%89%8B%20%28%E4%BC%98%E5%8C%96%E7%89%88%29.meta.js // ==/UserScript== (function () { 'use strict'; // ========================================== // 配置与常量 // ========================================== const CONFIG = { KEYWORDS: /购买|订阅|立即|下单|选购/, SELECTORS: 'button, .ant-btn, .btn', CLOSE_SELECTOR: '.el-dialog__headerbtn', // 弹窗关闭按钮 DEBOUNCE_TIME: 150, PANEL_ID: 'glm-helper-panel', TIME_URL: 'https://time.is/zh/Beijing' }; // ========================================== // 工具函数 // ========================================== const Utils = { debounce(fn, delay) { let timer = null; return function (...args) { if (timer) clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), delay); }; }, deepModify(obj) { if (!obj || typeof obj !== 'object') return; // 处理当前层级 if ('isSoldOut' in obj) obj.isSoldOut = false; if ('soldOut' in obj) obj.soldOut = false; if ('stock' in obj && obj.stock === 0) obj.stock = 999; if ('disabled' in obj && (obj.price !== undefined || obj.productId || obj.title)) { obj.disabled = false; } // 递归子对象 for (let key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key] && typeof obj[key] === 'object') { this.deepModify(obj[key]); } } }, getPlanInfo(btn) { const btnText = btn.innerText.trim().replace(/\n/g, ' '); // 提取动作名:优先保留“订阅中”、“处理中”等状态词 const action = btnText.length > 5 ? btnText.substring(0, 5) : btnText; let container = btn.parentElement; let planName = ''; // 向上回溯 4 层寻找卡片容器 for (let i = 0; i < 4; i++) { if (!container) break; // 常见的标题识别逻辑:寻找卡片中字相对较少且在顶部的显著文字 const candidates = Array.from(container.querySelectorAll('div, span, h1, h2, p')) .filter(el => { const text = el.innerText.trim(); return text.length > 0 && text.length < 15 && !text.includes('¥') && !text.includes(btn.innerText.trim()); }); if (candidates.length > 0) { // 通常第一个匹配项(在 DOM 顺序上靠前)是标题 planName = candidates[0].innerText.trim(); break; } container = container.parentElement; } return planName ? `${action}-${planName}` : btn.innerText.trim().substring(0, 8); }, getSubscriptionPeriod() { // 扫描常见的激活态类名:active, is-active, selected, checked const periodElements = Array.from(document.querySelectorAll('div, span, li, button')) .filter(el => { const text = el.innerText.trim(); const isPeriod = /包月|包季|包年|按月|按年/.test(text); if (!isPeriod) return false; const activeClasses = ['active', 'is-active', 'selected', 'checked', 'current']; const hasActiveClass = activeClasses.some(cls => el.classList.contains(cls)) || el.getAttribute('aria-checked') === 'true' || el.getAttribute('aria-selected') === 'true'; return hasActiveClass; }); return periodElements.length > 0 ? periodElements[0].innerText.trim() : '未识别'; } }; // ========================================== // UI 管理器 // ========================================== const UIManager = { panel: null, init() { if (this.panel) return; this.panel = document.createElement('div'); this.panel.id = CONFIG.PANEL_ID; Object.assign(this.panel.style, { position: 'fixed', left: '20px', top: '50%', transform: 'translateY(-50%)', backgroundColor: 'rgba(0, 0, 0, 0.85)', color: '#fff', padding: '15px', borderRadius: '12px', zIndex: '10000', fontSize: '13px', lineHeight: '1.6', pointerEvents: 'auto', // 恢复交互以支持点击链接 boxShadow: '0 8px 24px rgba(0,0,0,0.4)', border: '1px solid #444', display: 'none', backdropFilter: 'blur(4px)', fontFamily: 'Inter, system-ui, sans-serif' }); document.documentElement.appendChild(this.panel); }, update(buttons) { if (!this.panel) this.init(); this.panel.style.display = 'block'; // 持久显示 const period = Utils.getSubscriptionPeriod(); const header = `