@@ -25,34 +25,30 @@ async function fillToutiaoContent(content, waitFor, setInputValue) {
2525 const { title, body, markdown } = content
2626 const contentToFill = body || markdown || ''
2727
28- // 填充标题 - 头条使用 textarea 作为标题输入
29- const titleInput = await waitFor ( 'textarea[placeholder*="标题"], input[placeholder*="标题"], .editor-title textarea, .title-input textarea ' )
28+ // 填充标题 - 头条使用 textarea
29+ const titleInput = await waitFor ( 'textarea[placeholder*="标题"]' )
3030 if ( titleInput ) {
3131 titleInput . focus ( )
32- // 使用 nativeInputValueSetter 触发 React 状态更新
33- const nativeInputValueSetter = Object . getOwnPropertyDescriptor ( window . HTMLTextAreaElement . prototype , 'value' ) ?. set
34- || Object . getOwnPropertyDescriptor ( window . HTMLInputElement . prototype , 'value' ) ?. set
35- if ( nativeInputValueSetter ) {
36- nativeInputValueSetter . call ( titleInput , title )
37- } else {
38- titleInput . value = title
39- }
40- titleInput . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) )
32+ // 模拟用户输入
33+ const nativeSetter = Object . getOwnPropertyDescriptor ( window . HTMLTextAreaElement . prototype , 'value' ) . set
34+ nativeSetter . call ( titleInput , title )
35+ titleInput . dispatchEvent ( new InputEvent ( 'input' , { bubbles : true , data : title , inputType : 'insertText' } ) )
4136 titleInput . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) )
42- console . log ( '[COSE] 头条标题填充成功' )
37+ titleInput . dispatchEvent ( new Event ( 'blur' , { bubbles : true } ) )
38+ console . log ( '[COSE] 头条标题填充成功:' , title )
4339 } else {
4440 console . log ( '[COSE] 头条未找到标题输入框' )
4541 }
4642
4743 // 等待编辑器加载
48- await new Promise ( resolve => setTimeout ( resolve , 1000 ) )
44+ await new Promise ( resolve => setTimeout ( resolve , 500 ) )
4945
50- // 头条使用富文本编辑器
51- const editor = document . querySelector ( '.ProseMirror, [contenteditable="true"], .editor-content ' )
46+ // 头条使用 ProseMirror 富文本编辑器
47+ const editor = document . querySelector ( '.ProseMirror' )
5248 if ( editor ) {
5349 editor . focus ( )
5450 editor . innerHTML = contentToFill . replace ( / \n / g, '<br>' )
55- editor . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) )
51+ editor . dispatchEvent ( new InputEvent ( 'input' , { bubbles : true } ) )
5652 console . log ( '[COSE] 头条内容填充成功' )
5753 } else {
5854 console . log ( '[COSE] 头条未找到编辑器' )
0 commit comments