网站是kukuw在线打字
这段代码来自GreasyFork上一位老哥的分享,经过了我一些删减
$("#content > div").each(function(index){
contentArray.push($(this));
这段有个$禁用代码段。有没有懂的指导一下
(function() {
'use strict';
// @require http://www.jqueryfuns.com/content/js/jquery-1.8.3.min.js
// @require https://raw.githubusercontent.com/imingyu/jquery.mloading/master/src/jquery.mloading.js
// @require http://view.jqueryfuns.com/%E9%A2%84%E8%A7%88-/2016/6/6/4acd3731999352ee27d3e4fb759f5dcc/src/jquery.toast.js
// @resource ui http://view.jqueryfuns.com/%E9%A2%84%E8%A7%88-/2016/6/6/4acd3731999352ee27d3e4fb759f5dcc/src/jquery.toast.css
// @resource ui https://raw.githubusercontent.com/imingyu/jquery.mloading/master/src/jquery.mloading.css
const wordLazy = 0
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime){
return;
}
}
}
function simulateKeyPress(jq_el,character) {
console.log("当前模拟输入的字符:"+character+" 对应键盘码:"+character.charCodeAt(0));
let kd = new KeyboardEvent("keydown", {
bubbles: true, cancelable: true, keyCode: character.charCodeAt(0), which: character.charCodeAt(0)
});
jq_el[0].dispatchEvent(kd);
const last = jq_el.val();
jq_el.val(last+character);
if(Math.random()<0.1){
kd = new KeyboardEvent("keydown", {
bubbles: true, cancelable: true, keyCode: 8, which: 8
});
jq_el[0].dispatchEvent(kd);
jq_el.val(last);
kd = new KeyboardEvent("keydown", {
bubbles: true, cancelable: true, keyCode: character.charCodeAt(0), which: character.charCodeAt(0)
});
jq_el[0].dispatchEvent(kd);
jq_el.val(last+character);
}
}
function processLineTextIn(index,jq_el,text){
console.log("当前模拟输入行数:"+(index+1)+" 模拟文本内容:"+text);
for(let idx = 0; idx < text.length; idx++){
simulateKeyPress(jq_el,text[idx]);
sleep(wordLazy);
}
}
let contentArray = [];
function loopLazy(){
$("#content > div").each(function(index){
contentArray.push($(this));
});
let jq_line = contentArray.shift();
jq_line.children("input:last").focus();
processLineTextIn(0,jq_line.children("input:last"),jq_line.children(".text").text());
}
function run(){
loopLazy();
}
document.addEventListener("keydown", function(e) {
if(e.keyCode == 78) {
if(e.altKey){
run();
}else if(e.ctrlKey){
}
}
});
})();