Created
August 3, 2018 07:01
-
-
Save maicong/67446ba8ddfe832a8fe0f59078bd31e1 to your computer and use it in GitHub Desktop.
自动回复鸡 => https://fiora.suisuijiang.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 自动回复,粘贴在控制台 | |
* | |
* 开始: startLoop() | |
* 停止: stopLoop() | |
*/ | |
(() => { | |
let text = '', lastText = '', msg = '', timer = null, count = 0 | |
let faces = [ | |
'#(呵呵)', '#(哈哈)', '#(吐舌)', '#(啊)', '#(酷)', | |
'#(怒)', '#(开心)', '#(汗)', '#(泪)', '#(黑线)', | |
'#(鄙视)', '#(不高兴)', '#(真棒)', '#(钱)', '#(疑问)', | |
'#(阴险)', '#(吐)', '#(咦)', '#(委屈)', '#(花心)', '#(呼)', | |
'#(笑眼)', '#(冷)', '#(太开心)', '#(滑稽)', '#(勉强)', '#(狂汗)', | |
'#(乖)', '#(睡觉)', '#(惊哭)', '#(升起)', '#(惊讶)', '#(喷)', | |
'#(爱心)', '#(心碎)', '#(玫瑰)', '#(礼物)', '#(星星月亮)', '#(太阳)', | |
'#(音乐)', '#(灯泡)', '#(蛋糕)', '#(彩虹)', '#(钱币)', '#(咖啡)', | |
'#(haha)', '#(胜利)', '#(大拇指)', '#(弱)', '#(ok)' | |
] | |
const sendMsg = msg => { | |
document.querySelector('input[maxlength="2048"]').value = msg | |
document.querySelector('input[maxlength="2048"]').dispatchEvent( | |
new KeyboardEvent('keydown', { | |
keyCode: 13, | |
bubbles: true, | |
cancelable: true, | |
view: window | |
}) | |
) | |
} | |
window.startLoop = () => { | |
if (timer) return stopLoop() | |
console.log('===>>> 开始!') | |
timer = setInterval(async () => { | |
if (!text || lastText === text) { | |
const lastDom = Array.from( | |
document.querySelectorAll('.chat-message') | |
).filter( | |
c => !c.classList.contains('self') | |
).pop() | |
if (lastDom.classList.contains('text')) { | |
$img = lastDom.querySelector('.text .expression-baidu') | |
text = lastDom.querySelector('.text').innerText | |
if (!text && $img) { | |
text = $img.alt | |
} | |
} | |
if (lastDom.classList.contains('image')) { | |
text = '[图片]' | |
} | |
console.log(lastText, '<====>', text, '~~~~~', count) | |
} else { | |
lastText = text | |
if (text === '[图片]') { | |
msg = '我浏览器是 IE6,看不到图,写字吧。' | |
} else if (faces.includes(text)) { | |
msg = text | |
} else if (text) { | |
msg = await fetch( | |
'https://daima.co/r.php?k=' + text | |
).then(r => r.json()).then(res => res.text) | |
} | |
console.log(text, '答复===>' , msg) | |
sendMsg(msg) | |
} | |
count++ | |
}, 1000) | |
} | |
window.stopLoop = () => { | |
clearInterval(timer) | |
console.log('===>>> 停止!') | |
} | |
console.log('回复鸡准备就绪,开始: startLoop(),停止: stopLoop()') | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment