|
|
@@ -0,0 +1,114 @@
|
|
|
+function simulateTyping(searchBox, text, callBack) {
|
|
|
+
|
|
|
+ if (!searchBox) return;
|
|
|
+
|
|
|
+ // 确保搜索框获得焦点
|
|
|
+ searchBox.focus();
|
|
|
+
|
|
|
+ // 模拟逐个字符输入
|
|
|
+ text.split('').forEach((char, index) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ // 创建键盘事件
|
|
|
+ const keyDownEvent = new KeyboardEvent('keydown', {
|
|
|
+ key: char,
|
|
|
+ code: `Key${char.toUpperCase()}`,
|
|
|
+ bubbles: true
|
|
|
+ });
|
|
|
+
|
|
|
+ const keyPressEvent = new KeyboardEvent('keypress', {
|
|
|
+ key: char,
|
|
|
+ bubbles: true
|
|
|
+ });
|
|
|
+
|
|
|
+ const keyUpEvent = new KeyboardEvent('keyup', {
|
|
|
+ key: char,
|
|
|
+ bubbles: true
|
|
|
+ });
|
|
|
+
|
|
|
+ // 触发事件
|
|
|
+ searchBox.dispatchEvent(keyDownEvent);
|
|
|
+ searchBox.dispatchEvent(keyPressEvent);
|
|
|
+
|
|
|
+ // 插入字符
|
|
|
+ document.execCommand('insertText', false, char);
|
|
|
+
|
|
|
+ searchBox.dispatchEvent(keyUpEvent);
|
|
|
+
|
|
|
+ // 如果是最后一个字符,触发搜索
|
|
|
+ if (index === text.length - 1) {
|
|
|
+ const inputEvent = new Event('input', { bubbles: true });
|
|
|
+ searchBox.dispatchEvent(inputEvent);
|
|
|
+ }
|
|
|
+ }, index * 100 + 500); // 100ms 间隔模拟打字
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ // 触发所有可能的事件
|
|
|
+ const events = ['input', 'change', 'keyup', 'keydown', 'keypress', 'blur', 'focus'];
|
|
|
+
|
|
|
+ events.forEach(eventType => {
|
|
|
+ const event = eventType.startsWith('key')
|
|
|
+ ? new KeyboardEvent(eventType, { bubbles: true })
|
|
|
+ : new Event(eventType, { bubbles: true });
|
|
|
+
|
|
|
+ searchBox.dispatchEvent(event);
|
|
|
+ });
|
|
|
+ if (callBack) callBack()
|
|
|
+ }, text.split('').length * 100);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function simulateFullClick(element) {
|
|
|
+ // 鼠标按下
|
|
|
+ const mouseDownEvent = new MouseEvent('mousedown', {
|
|
|
+ view: window,
|
|
|
+ bubbles: true,
|
|
|
+ cancelable: true,
|
|
|
+ buttons: 1
|
|
|
+ });
|
|
|
+
|
|
|
+ // 鼠标抬起
|
|
|
+ const mouseUpEvent = new MouseEvent('mouseup', {
|
|
|
+ view: window,
|
|
|
+ bubbles: true,
|
|
|
+ cancelable: true,
|
|
|
+ buttons: 1
|
|
|
+ });
|
|
|
+
|
|
|
+ // 点击事件
|
|
|
+ const clickEvent = new MouseEvent('click', {
|
|
|
+ view: window,
|
|
|
+ bubbles: true,
|
|
|
+ cancelable: true,
|
|
|
+ buttons: 1
|
|
|
+ });
|
|
|
+
|
|
|
+ // 按顺序触发事件
|
|
|
+ element.dispatchEvent(mouseDownEvent);
|
|
|
+ element.dispatchEvent(mouseUpEvent);
|
|
|
+ element.dispatchEvent(clickEvent);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function searchText(text, sendText) {
|
|
|
+ const searchBox = document.querySelector('div[contenteditable="true"][aria-label="搜索输入内容文本框"]');
|
|
|
+ if (document.querySelector('._ah_y.x1eu8d0j')) {
|
|
|
+ document.querySelector('._ah_y.x1eu8d0j').click()
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ simulateTyping(searchBox, text, () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ const gridcellList = document.querySelectorAll('.x1n2onr6[role="gridcell"]')
|
|
|
+ if (gridcellList.length > 0) {
|
|
|
+ simulateFullClick(gridcellList[0].querySelector('._ak72'))
|
|
|
+ setTimeout(() => {
|
|
|
+ simulateTyping(document.querySelector('[aria-placeholder="输入消息"]'), sendText)
|
|
|
+ }, 2000);
|
|
|
+ }
|
|
|
+ }, 2000);
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
+}
|
|
|
+
|