Last active
September 15, 2018 06:28
-
-
Save nick-ChenZe/0a8fbc2bec840452284b1a3e535cfce3 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
// 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