3 How to define custom mode
Gold Holk edited this page 2022-08-10 15:54:14 +08:00

It is a good idea to define a custom mode when you have a bunch of operations you may use in similar situation. For example, you may want a single keystroke to seek forward/backward, seek OP, or replay.

Define the bindings in the mode

Define a binding to a mode does not exist will create it automatically.

## video related commands
alias jse js function $all(q, root=document) { return Array.from(root.querySelectorAll(q)) };
alias video_with jse let video; if (document.activeElement.name == 'VIDEO') video = document.activeElement; else video = $all('video').find(v => !v.paused); if (!video) video = $('video');
alias video_goby js -d@ let time = JS_ARGS.filter(Boolean); let sign = '+'; if (time[0].match(/^[-+]/)) { sign = time[0].charAt(0); time[0] = time[0].slice(1) } time = time.filter(Boolean).map(Number); const second = time.reduce((s, n) => s*60+n, 0); tri.controller.acceptExCmd(`video_with video.currentTime ${sign}= ${second}`) @
alias video_goto js -d@ let time = JS_ARGS.filter(Boolean); let sign = '+'; if (time[0].match(/^[-+]/)) { sign = time[0].charAt(0); time[0] = time[0].slice(1) } time = time.filter(Boolean).map(Number); let second = time.reduce((s, n) => s*60+n, 0); if (sign == '-') second = `video.duration - ${second}`; tri.controller.acceptExCmd(`video_with video.currentTime = ${second}`) @

bind --mode=video a video_with video.currentTime = 0
bind --mode=video A video_with video.currentTime = video.duration
bind --mode=video C video_with video.currentTime = Number(get('video_seek_op'))
bind --mode=video b composite js Number(get('video_seek')) | video_with video.currentTime -=
bind --mode=video w composite js Number(get('video_seek')) | video_with video.currentTime +=

# eg: `video_goto 3 21` will seek to 3:21
# `video_goby 3 21` will seek for 3:21
bind --mode=video I fillcmdline video_goby
bind --mode=video i fillcmdline video_goto
bind --mode=video gt fillcmdline video_goto

related settings:

set video_seek 5
set video_seek_op 120
seturl ^https://www.youtube.com/watch\?v=116OjLa1DwY video_seek_op 42

Enter and exit the mode

Define commands to enter and exit the mode:

alias exit_video mode normal
alias video_mode mode video

Binding to enter it:

bind gv video_mode

# Just V should be enough, I never used V in youtube.
bindurl ^https://www.youtube.com/watch\? V video_mode

# or juse enter it default
autocmd DocLoad ^https://www.youtube.com/watch\? video_mode

Binding to exit it:

bind --mode=video V exit_video
bind --mode=video z exit_video
bind --mode=video <Escape> exit_video

Inherits

If you want to use binding from anther mode, you can set the special 🕷🕷INHERITS🕷🕷 key to another mode. When a key is not defined in your mode, tridactyl will look up it in the inherited mode. Your mode bindings will be stored in the ${mode_name}maps.

set videomaps.🕷🕷INHERITS🕷🕷 nmaps

Special mode

If you want to enter/exit from ex/hint/visual/insert/input, you should take a look of their binding for . the mode command will not handle these things for you.