Skip to content

Instantly share code, notes, and snippets.

@DC3
Last active August 29, 2015 14:05
Show Gist options
  • Save DC3/2f28b2ba5fa2f5b54745 to your computer and use it in GitHub Desktop.
Save DC3/2f28b2ba5fa2f5b54745 to your computer and use it in GitHub Desktop.
# http://www.1758.com/hlmy/yanse2.htm
$ ->
timeEl = $('.time')
boxEl = $('#box')
interval = null
eachTime = 1 # ms
replaceRE = /[^\d]+/g
getColor = (str) ->
+str.replace(replaceRE, '')
sortHandler = (a, b) ->
getColor(a.style.backgroundColor) - getColor(b.style.backgroundColor)
clickHandler = -> boxEl.find('span').sort(sortHandler).last().trigger('click')
intervalHandler = ->
return if isNaN((countdown = parseInt(timeEl.text(), 10)))
return clickHandler() if countdown > 0
clearInterval interval
$('body').on 'click', '.play-btn', ->
interval = setInterval intervalHandler, eachTime
boxEl.hide()
console.log '点击开始游戏按钮'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment