// ==UserScript==
// @name agefans Enhance
// @namespace https://github.com/IronKinoko/agefans-enhance
// @version 0.1.17
// @description more powerful agefans
// @author IronKinoko
// @match https://www.agefans.net/*
// @match https://www.agefans.net/play/*
// @match https://www.agefans.net/detail/*
// @require https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js
// @grant none
// @license MIT
// @downloadURL none
// ==/UserScript==
;(function () {
'use strict'
window.log = console.log
delete window.console
document.cookie = 'username=admin; path=/; max-age=99999999;'
const his = new (class {
cacheKey = 'v-his'
his = JSON.parse(localStorage.getItem(this.cacheKey) || '[]')
getAll() {
return this.his
}
get(id) {
return this.his.find((o) => o.id === id)
}
setTime(id, time = 0) {
this.get(id).time = time
this.save()
}
log(item) {
this.his.unshift(item)
this.save()
}
refresh(id, data) {
const index = this.his.findIndex((o) => o.id === id)
const item = this.his.splice(index, 1)[0]
this.his.unshift(data || item)
this.save()
}
save() {
localStorage.setItem(this.cacheKey, JSON.stringify(this.his.slice(0, 50)))
}
has(id) {
return Boolean(this.his.find((o) => o.id === id))
}
})()
function gotoNextPart() {
const dom = document.querySelector("li a[style*='color: rgb(238, 0, 0);']")
.parentElement.nextElementSibling
if (dom) {
dom.children[0].click()
}
}
function renderHistroyStyle() {
// add a tag visited style
let styleDom = document.createElement('style')
styleDom.innerHTML = `.movurl li a:visited { color: red; }`
document.head.appendChild(styleDom)
}
function replacePlayer() {
const dom = document.getElementById('age_playfram')
dom.setAttribute('allow', 'autoplay')
const prefix = 'https://ironkinoko.github.io/agefans-enhance/?url='
const fn = () => {
let url = new URL(dom.src)
if (url.hostname.includes('agefans')) {
let videoURL = url.searchParams.get('url')
if (videoURL) {
dom.src = prefix + encodeURIComponent(videoURL)
}
}
}
const mutationOb = new MutationObserver(fn)
mutationOb.observe(dom, { attributes: true })
fn()
}
function toggleFullScreen(bool) {
let dom = document.querySelector('.fullscn')
dom.click()
}
function notifyChildToggleFullScreen(isFull) {
const dom = document.getElementById('age_playfram')
dom.contentWindow.postMessage({ code: 666, isFull }, '*')
}
function inject() {
let dom = document.querySelector('.fullscn')
dom.onclick = () => {
if (document.body.style.overflow === 'hidden') {
document.body.style.overflow = ''
notifyChildToggleFullScreen(false)
} else {
document.body.style.overflow = 'hidden'
notifyChildToggleFullScreen(true)
}
}
let ageframediv = document.getElementById('ageframediv')
let { width, height } = ageframediv.getBoundingClientRect()
ageframediv.style.height = (width / 16) * 9 + 'px'
}
function prerenderNextPartHTML() {
const dom = document.querySelector("li a[style*='color: rgb(238, 0, 0);']")
.parentElement.nextElementSibling
if (dom) {
const link = document.createElement('link')
link.rel = 'prerender'
link.href = dom.children[0].href
document.head.appendChild(link)
}
}
function parseTime(time = 0) {
return `${Math.floor(time / 60)
.toString()
.padStart(2, '0')}:${(time % 60).toString().padStart(2, '0')}`
}
function renderHistoryList() {
$('#history')
.html('')
.append(() => {
/** @type {any[]} */
const histories = his.getAll()
let html = ''
histories.forEach((o) => {
html += `