@@ -78,16 +78,17 @@ export async function pasteIntoPostBoxFacebook(
7878 const [ element ] = activated . evaluate ( )
7979 element . focus ( )
8080 await sleep ( 100 )
81- if ( 'value' in document . activeElement ! ) dispatchCustomEvents ( 'input' , text )
82- else dispatchCustomEvents ( 'paste' , text )
83- element . dispatchEvent ( new CustomEvent ( 'input' , { bubbles : true , cancelable : false , composed : true } ) )
81+ // HACK: the is workaround
82+ // https://github.com/eraeco/party.lol/blob/f63ae89b0b339b52aac12f65eb7a0865e522530a/content.js#L102
83+ element . querySelector ( 'br' ) ?. replaceWith ( document . createTextNode ( text ) )
84+ onToggleInput ( element )
8485 await sleep ( 400 )
8586 if ( isMobileFacebook ) {
8687 const e = document . querySelector < HTMLDivElement | HTMLTextAreaElement > ( '.mentions-placeholder' )
8788 if ( e ) e . style . display = 'none'
8889 }
8990 // Prevent Custom Paste failed, this will cause service not available to user.
90- if ( element . innerText . indexOf ( text ) === - 1 && 'value' in element && element . value . indexOf ( text ) === - 1 ) {
91+ if ( ! ( element . innerText . includes ( text ) || ( 'value' in element && element . value . includes ( text ) ) ) ) {
9192 copyFailed ( )
9293 }
9394 } catch {
@@ -99,3 +100,18 @@ export async function pasteIntoPostBoxFacebook(
99100 prompt ( warningText , text )
100101 }
101102}
103+
104+ function onToggleInput ( element : Element ) {
105+ try {
106+ const init = { bubbles : true , cancelable : true }
107+ for ( const name of [ 'input' , 'change' ] ) {
108+ element . dispatchEvent ( new Event ( name , init ) )
109+ }
110+ for ( const name of [ 'keydown' , 'keypress' , 'keyup' ] ) {
111+ element . dispatchEvent ( new KeyboardEvent ( name , init ) )
112+ }
113+ } catch {
114+ return false
115+ }
116+ return true
117+ }
0 commit comments