Greasy Fork is available in English.
自動觀看動畫瘋廣告
当前为
// ==UserScript==
// @name 動畫瘋-自動觀看廣告
// @namespace https://shinoharahare.github.io/
// @version 0.1
// @description 自動觀看動畫瘋廣告
// @author Hare
// @match https://ani.gamer.com.tw/animeVideo.php?sn=*
// @grant none
// ==/UserScript==
(async () => {
'use strict';
if (await checkAD()) {
(await waitElement('#adult')).click()
const video = document.querySelector('video[title=Advertisement]')
video.addEventListener('play', ({ target }) => {
target.muted = true
})
await sleep(30000)
videojs.getPlayer('ani_video').trigger('vast.adSkip')
location.reload()
}
})();
async function checkAD() {
const res = await fetch(`/ajax/token.php?sn=${animefun.videoSn}`)
const json = await res.json()
return json.time == 0
}
async function waitElement(selector) {
return await wait(() => document.querySelector(selector))
}
function wait(tester, timeout, delay = 100) {
return new Promise((resolve, reject) => {
const interval = setInterval(() => {
const result = tester()
if (result) {
clearInterval(interval)
resolve(result)
}
}, delay)
if (timeout) {
setTimeout(() => {
clearInterval(interval)
reject()
}, timeout)
}
})
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}