// ==================== 选择器管理面板 ==================== window.SelectorPanel = { name: 'SelectorPanel', props: { selectors: { type: Object, required: true }, collapsed: { type: Boolean, default: true } }, emits: [ 'update:collapsed', 'add-selector', 'remove-selector', 'update-selector-key', 'update-selector-value', 'test-selector' ], data() { return { showMenu: false, fieldQuery: '', fieldFilter: 'all', editingSelectorKey: '', expandedField: 'input_box', auxiliaryExpanded: false, guideExpanded: false, openRenameKey: '', renameDrafts: {}, coreSelectorKeys: ['input_box', 'send_btn', 'result_container'] }; }, computed: { count() { return Object.keys(this.selectors || {}).length; }, selectorEntries() { const query = this.fieldQuery.trim().toLowerCase(); return Object.entries(this.selectors || {}).filter(([key, value]) => { // Keep the active field mounted while typing, even when its value stops matching. if (key === this.editingSelectorKey) return true; if (this.fieldFilter === 'core' && !this.coreSelectorKeys.includes(key)) return false; if (this.fieldFilter === 'empty' && this.isSelectorFilled(key)) return false; const meta = this.getSelectorMeta(key); return !query || [key, value, meta.title, meta.description].join(' ').toLowerCase().includes(query); }); }, selectorGroups() { return [ { id: 'core', title: '核心定位', note: '一次对话的三个关键位置', entries: this.selectorEntries.filter(([key]) => this.coreSelectorKeys.includes(key)) }, { id: 'auxiliary', title: '辅助与扩展', note: '对话管理、上传入口及自定义字段', entries: this.selectorEntries.filter(([key]) => !this.coreSelectorKeys.includes(key)) } ]; }, coreChecklist() { return this.coreSelectorKeys.map(key => ({ key, ...this.getSelectorMeta(key), ready: this.isSelectorFilled(key) })); }, coreReadyCount() { return this.coreChecklist.filter(item => item.ready).length; }, missingQuickAdds() { return this.coreChecklist.filter(item => !Object.prototype.hasOwnProperty.call(this.selectors || {}, item.key)); } }, watch: { selectors() { this.fieldQuery = ''; this.fieldFilter = 'all'; this.editingSelectorKey = ''; this.expandedField = Object.prototype.hasOwnProperty.call(this.selectors || {}, 'input_box') ? 'input_box' : Object.keys(this.selectors || {})[0] || ''; this.auxiliaryExpanded = false; this.closeRenameEditor(); } }, methods: { openCoreField(key) { this.fieldFilter = 'all'; this.fieldQuery = ''; if (!Object.prototype.hasOwnProperty.call(this.selectors || {}, key)) { this.addSelector(key); return; } this.expandedField = key; this.$nextTick(() => { const field = document.getElementById('selector-expression-' + key); if (field) { field.focus({ preventScroll: true }); field.scrollIntoView({ block: 'nearest' }); } }); }, toggle() { this.$emit('update:collapsed', !this.collapsed); }, toggleMenu(e) { e.stopPropagation(); this.showMenu = !this.showMenu; }, addSelector(type) { this.showMenu = false; const previous = Object.keys(this.selectors || {}); this.$emit('add-selector', type); this.$nextTick(() => { const key = Object.keys(this.selectors || {}).find(key => !previous.includes(key)); if (!key) return; this.fieldFilter = 'all'; this.fieldQuery = ''; this.expandedField = key; this.auxiliaryExpanded = !this.coreSelectorKeys.includes(key); }); }, closeMenu() { this.showMenu = false; }, openInNewTab(url) { const target = String(url || '').trim(); if (!target) { return; } window.open(target, '_blank', 'noopener,noreferrer'); }, openTutorial(anchor = 'selector-basics') { this.openInNewTab('/static/tutorial/index.html#' + encodeURIComponent(anchor)); }, openPracticeLab() { this.openInNewTab('/static/selector-practice.html'); }, isSelectorFilled(key) { return String((this.selectors || {})[key] || '').trim().length > 0; }, isBuiltInSelectorKey(key) { return [ 'input_box', 'send_btn', 'result_container', 'new_chat_btn', 'message_wrapper', 'generating_indicator', 'retry_send_btn', 'upload_btn', 'file_input', 'drop_zone', 'composer_root' ].includes(String(key || '').trim()); }, canRenameSelectorKey(key) { return !this.isBuiltInSelectorKey(key); }, openRenameEditor(key) { this.openRenameKey = key; this.renameDrafts = { ...this.renameDrafts, [key]: key }; this.$nextTick(() => { const ref = this.$refs['renameInput-' + key]; const input = Array.isArray(ref) ? ref[0] : ref; if (input && typeof input.focus === 'function') { input.focus(); if (typeof input.select === 'function') { input.select(); } } }); }, closeRenameEditor() { this.openRenameKey = ''; }, submitRenameKey(key) { const nextKey = String((this.renameDrafts || {})[key] || '').trim(); this.openRenameKey = ''; if (!nextKey || nextKey === key) { return; } this.$emit('update-selector-key', key, nextKey); this.$nextTick(() => { if (Object.prototype.hasOwnProperty.call(this.selectors || {}, nextKey) && !Object.prototype.hasOwnProperty.call(this.selectors || {}, key)) this.expandedField = nextKey; }); }, getSelectorMeta(key) { const metaMap = { input_box: { title: '输入框', description: '用户真正打字的地方。常见是 textarea、contenteditable 或 role=textbox。', hint: '先右键输入区域点“检查”。看到 textarea,或者看到可编辑的 div,通常就离答案很近了。', required: true, chip: '必填', placeholder: '例如:textarea, div[contenteditable="true"]' }, send_btn: { title: '发送按钮', description: '点一下就会把消息发出去的按钮,常见是纸飞机、箭头或“发送”字样。', hint: '优先找 button 上比较稳的属性,比如 type、aria-label、data-testid;只靠一串随机 class 往往不稳。', required: true, chip: '必填', placeholder: '例如:button[type="submit"], button[data-testid="send"]' }, result_container: { title: '回复容器', description: '包住 AI 回复正文的区域。尽量选整段回复的外层,不要只选某个 p 或 span。', hint: '看到整条 AI 回复后,先选能完整包住这条内容的外层块。范围太小,后面很容易漏字、漏代码块。', required: true, chip: '必填', placeholder: '例如:main article .markdown-body' }, new_chat_btn: { title: '新建对话按钮', description: '每次开始新会话前需要点的按钮,没有也可以先留空。', hint: '如果页面左上角有“新聊天”“新建对话”“清空上下文”之类的入口,这个字段通常就该填它。', required: false, chip: '选填', placeholder: '例如:button[aria-label*="新"], button.new-chat' }, message_wrapper: { title: '消息外层容器', description: '一条消息最外层的盒子。长回复、分段节点、复杂样式场景里很有帮助。', hint: '如果一条回复里有很多段落、代码块、图片,给它补上最外层容器,提取结果通常会稳很多。', required: false, chip: '辅助', placeholder: '例如:article[data-role="assistant-message"]' }, generating_indicator: { title: '生成中指示器', description: '能表明“模型还在继续输出”的元素,比如停止按钮、转圈、typing 提示。', hint: '有“停止生成”按钮时,这个字段通常很好找。它出现时代表还在生成,消失后通常代表结束。', required: false, chip: '辅助', placeholder: '例如:button[aria-label*="停止"], .typing-indicator' }, retry_send_btn: { title: '重试/重新运行按钮', description: '用于重新运行当前回复或把停止后的回复重新拉起,常见是圆形箭头按钮。', hint: 'Battle 或双栏对比模式里,通常需要先点这个按钮,再点右下角发送/停止态按钮完成本轮发送。', required: false, chip: '辅助', placeholder: '例如:button[aria-label="Rerun stopped messages"]' }, upload_btn: { title: '上传按钮', description: '点一下会弹出上传面板或系统文件选择窗口的按钮。', hint: '页面里有加号、回形针、图片图标时,先看那个按钮。很多站点把上传入口藏在工具栏里。', required: false, chip: '上传', placeholder: '例如:button[aria-label*="上传"], .toolbar-upload' }, file_input: { title: '原生文件输入框', description: '真正的 input[type=file] 元素,适合直接写入文件。', hint: '很多站点会把它藏起来。开发者工具里搜索 type="file" 往往最快。', required: false, chip: '上传', placeholder: '例如:input[type="file"]' }, composer_root: { title: '消息编辑区根节点', description: '限定自动查找文件输入框和附件观察的范围,避免匹配页面历史消息。', hint: '通常是包围输入框、附件预览和发送按钮的容器。配置 file_input 时仍优先使用指定入口。', required: false, chip: '上传', placeholder: '例如:.composer, form.chat-input' }, drop_zone: { title: '拖拽上传区域', description: '支持把文件拖到页面里的区域,适合不吃粘贴的网站。', hint: '拖一张图到页面上时,哪个区域会高亮、变色、出现提示,那个区域通常就是它。', required: false, chip: '上传', placeholder: '例如:div[data-dropzone="true"]' } }; const presetMeta = metaMap[key]; if (presetMeta) { return presetMeta; } return { title: '自定义字段', description: '你自己补的额外选择器,常用于临时按钮、模式切换、弹窗确认之类的操作。', hint: '自定义字段也建议优先用稳定属性。页面每次刷新都会变的随机 class,后面维护起来会很痛苦。', required: false, chip: '自定义', placeholder: '例如:button[data-role="mode-switch"]' }; }, getChipClass(key) { const chip = this.getSelectorMeta(key).chip; if (chip === '必填') { return 'dashboard-field-chip'; } if (chip === '自定义') { return 'dashboard-field-chip dashboard-field-chip--custom'; } return 'dashboard-field-chip dashboard-field-chip--optional'; } }, template: `
现在还是空白很正常。先把 input_box、send_btn、result_container 加出来,再开始一项一项测试。
{{ fieldFilter === 'empty' && !fieldQuery ? '接下来可以逐项测试,确认网页元素能被正确定位。' : '试试其他关键词,或切换到全部字段。' }}
{{ group.note }}
先找输入框、发送按钮、AI 回复容器。上传按钮、消息外层、生成中提示这些字段可以后面再慢慢补。第一轮目标很简单:先让页面能发、能收、能测。
当前核心字段进度:{{ coreReadyCount }}/3