Skip to content

Instantly share code, notes, and snippets.

@nick-ChenZe
Last active September 15, 2018 06:28
Show Gist options
  • Save nick-ChenZe/0a8fbc2bec840452284b1a3e535cfce3 to your computer and use it in GitHub Desktop.
Save nick-ChenZe/0a8fbc2bec840452284b1a3e535cfce3 to your computer and use it in GitHub Desktop.
// http://douyu.shiniv.com/
// 自动打开有宝箱的直播间, 30秒后自动关闭
(function () {
let windowOpenedCount = 0
let timer = setInterval(() => {
let blockEls = document.querySelector('#message').children
let len = blockEls.length
for (; len--;) {
let elm = blockEls[len]
let timerElm = elm.querySelector('blockquote .timeleft');
if (!timerElm) return
let isCountDownAt15 = timerElm.innerText == 15
let isWindowLessThan2 = windowOpenedCount < 2
let shouldOpen = isCountDownAt15 && isWindowLessThan2
if (shouldOpen) {
let href = timerElm.parentElement.getAttribute('href')
let instance = window.open(href)
windowOpenedCount++
window.setTimeout(() => {
instance.close()
windowOpenedCount--
}, 30000)
}
}
}, 1000)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment