Skip to content

Instantly share code, notes, and snippets.

@hyrious
Last active August 20, 2023 09:54
Show Gist options
  • Save hyrious/4ee2a8ee562e6e901a708f90bddad0ef to your computer and use it in GitHub Desktop.
Save hyrious/4ee2a8ee562e6e901a708f90bddad0ef to your computer and use it in GitHub Desktop.
press ] to goto next episode
// ==UserScript==
// @name ] = 下一集
// @namespace navigate.agemys
// @match *://*.agemys.*/*
// @match *://*.agedm.*/*
// @match https://vip.sp-flv.com:8443/*
// @grant none
// @version 1.0
// @author hyrious
// @description 按 ] 切到下一集
// ==/UserScript==
(function() {
'use strict'
var a = location.pathname.match(/^\/play\/(\d+)\/(\d+)\/(\d+)$/)
if (a == null) {
document.addEventListener('keydown', function onpress(ev) {
if ('{}[]'.includes(ev.key)) {
parent.postMessage(ev.key, '*')
}
}, { capture: true })
return
}
window.addEventListener('message', function onmessage(ev) {
if ('{}[]'.includes(ev.data)) {
document.dispatchEvent(new KeyboardEvent('keydown', { key: ev.data, bubbles: true }))
}
})
var id = a[1], source = parseInt(a[2]), chapter = parseInt(a[3])
function navigate(type) {
if ('[]'.includes(type)) {
chapter += (type === ']' ? 1 : -1)
}
if ('{}'.includes(type)) {
source += (type === '}' ? 1 : -1)
}
location.pathname = '/play/' + id + '/' + source + '/' + chapter
}
document.addEventListener('keydown', function onpress(ev) {
if ('{}[]'.includes(ev.key)) {
navigate(ev.key)
}
}, { capture: true })
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment