Created
April 7, 2016 13:04
-
-
Save DingWeizhe/39a64367f2ba0514c5f4ce85d58b3520 to your computer and use it in GitHub Desktop.
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
var TIME = 30; | |
var EXIT_MES = ["一樣", "人妖", "幹"]; | |
var SEND_MES = "幹"; | |
var stopWaitMessage; | |
var stopWaitExitMessage; | |
var css = document.createElement("style"); | |
document.body.appendChild(css); | |
css.innerHTML = "\ | |
#timer, #reload{\ | |
background-color: #FFF;\ | |
color: #000;\ | |
text-align: center;\ | |
line-height: 40px;\ | |
width: 40px;\ | |
height: 40px;\ | |
border-radius: 100%;\ | |
position: fixed;\ | |
right: 20px;\ | |
top: 20px;\ | |
z-index: 10;\ | |
cursor: pointer;\ | |
box-shadow: 2px 2px 3px rgba(100,100,50,.3);\ | |
}\ | |
#reload{\ | |
top: 80px;\ | |
}\ | |
"; | |
function safe(fn) { | |
if (typeof fn == "function") return fn; | |
else return function() { | |
return false; | |
}; | |
} | |
function wait(condition, callback) { | |
var timer = setInterval(function() { | |
if (safe(condition)()) { | |
safe(callback)(); | |
clearInterval(timer); | |
} | |
}, 100); | |
return function() { | |
clearInterval(timer); | |
} | |
} | |
function existMessage(message) { | |
return $("#messages").html().indexOf(message) != -1; | |
} | |
function strangerSay(message) { | |
return $(".stranger").map(function() { | |
return $(this).html(); | |
}).toArray().join("").indexOf(message) != -1; | |
} | |
function notify() { | |
var i = 10; | |
var timer = setInterval(function() { | |
new Audio("/ding.mp3").play(); | |
if (i-- == 0) clearInterval(timer);; | |
}, 100); | |
} | |
function rechat(why) { | |
console.error(why); | |
safe(stopWaitExitMessage)(); | |
safe(stopWaitMessage)(); | |
changePerson(); | |
stop = true; | |
setTimeout(function() { | |
$("#popup-yes").click(); | |
setTimeout(run, 1000); | |
}, 500); | |
} | |
function exitMessage() { | |
for (var i in EXIT_MES) { | |
if (strangerSay(EXIT_MES[i])) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function send(message) { | |
$("#messageInput").val(message); | |
sendMessage(); | |
} | |
function run() { | |
clickStartChat(); | |
wait(function() { | |
return existMessage("加密連線完成,開始聊天囉!"); | |
}, function() { | |
stop = false; | |
counter = TIME; | |
send(SEND_MES); | |
stopWaitMessage = wait(function() { | |
return existMessage("陌生人:") && !exitMessage(); | |
}, function() { | |
//stop = true; | |
notify(); | |
}); | |
}); | |
} | |
function rewait() { | |
safe(stopWaitExitMessage)(); | |
stopWaitExitMessage = wait(function() { | |
return existMessage("離開") || exitMessage(); | |
}, function() { | |
rechat("出現離開文字"); | |
}); | |
} | |
var stop = false; | |
var counter = TIME; | |
setInterval(function() { | |
if (stop == true) return; | |
if (counter == 0) { | |
rechat("時間超過30秒"); | |
} else { | |
counter--; | |
$("#timer").html(counter); | |
} | |
}, 1000); | |
$("<div id='timer'>").appendTo($("body")).click(function() { | |
stop = !stop; | |
}); | |
$("<div id='reload'>R</div>").appendTo($("body")).click(function() { | |
rechat(); | |
}); | |
rewait(); | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment