vimium-c icon indicating copy to clipboard operation
vimium-c copied to clipboard

Is there a command for html-5 videos 5 second forward and backward. And also for increasing playback speed ?

Open heissonly opened this issue 2 years ago • 25 comments

I am using this chrome extension but I would like to integrate these four five commands with vimium because it contradict with other extension that I am using. Video Speed Controller Screen Shot 2022-07-29 at 14 19 09

heissonly avatar Jul 29 '22 12:07 heissonly

You may add the 5 shortcut keys into Keys of Excluded URLs and keys on Vimium C Options, and then Vimium C won't hook these 5 keys.

Or a better way is to use enterInsertMode or passNextKey, so that Vimium C will only ignore some following keys after a special key

By default, i is mapped to enterInsertMode, and as said in https://github.com/philc/vimium/#keyboard-bindings:

i enter insert mode -- all commands will be ignored until you hit Esc to exit

There's also some advanced tricks to enable and disable Vimium C using a same key - see https://github.com/gdh1995/vimium-c/wiki/Enable-or-Disable-all-frames-by-a-shortcut for further documents.

gdh1995 avatar Jul 29 '22 13:07 gdh1995

As for the left half question, currently Vimum C doesn't provide any direct command to change time of <video>. But it supports map xxx openUrl url="javascript:...", so you may run any JS code you want when a shortcut is triggered.

If there's a key mapping like map xxx openBookmark title="v:cmd1", then xxx will trigger Vimium C to run (javascript) URL saved in a browser bookmark.

gdh1995 avatar Jul 29 '22 13:07 gdh1995

if you want to do the forward and backward thingy then just press the → and ← keys on your keyboard (left and right arrow keys)

yoyeet961 avatar Aug 02 '22 18:08 yoyeet961

if you want to do the forward and backward thingy then just press the → and ← keys on your keyboard (left and right arrow keys)

It's not my intention. I want to use keyboard with only my left hand. And it is not that I want to 10 seconds backward as I can already do with arrow keys but 5 seconds which I need to adjust with JavaScript code on Vimium C.

heissonly avatar Aug 06 '22 18:08 heissonly

As for the left half question, currently Vimum C doesn't provide any direct command to change time of <video>. But it supports map xxx openUrl url="javascript:...", so you may run any JS code you want when a shortcut is triggered.

If there's a key mapping like map xxx openBookmark title="v:cmd1", then xxx will trigger Vimium C to run (javascript) URL saved in a browser bookmark.

Can you not write for me javascript code as last time you made for the pause to video below but this time for increasing speed up % 0.25 und decreasing to %0.25 speed down .

map hv openUrl url="javascript:var\u0020a=document.querySelector('video');a.paused?a.play():a.pause()"

heissonly avatar Aug 07 '22 00:08 heissonly

map <v-speed> openUrl url="javascript:var\u0020a=document.querySelector('video');a.playbackRate+=$c*0.25" mask
run h+ speed
run h- speed#count=-1

Then h+ means to increase speed by 0.25, and 4h- to decrease it by 0.25 * 4 = 1

gdh1995 avatar Aug 08 '22 02:08 gdh1995

What is h+ means ? ( h Key with + ) or ?

run h+ speed run h- speed#count=-1

I don't understand this part of the code. Can you briefly explain please?

heissonly avatar Aug 08 '22 15:08 heissonly

It's h and + (press h , and then Shift+=). And you may change to h= to avoid pressing Shift, or any other keys as you like.

run is just like map with a more complex syntax for "commands with options" (https://github.com/gdh1995/vimium-c/wiki/Auto-run-a-tree-of-commands), and speed is a mapping name declared in map <v-speed> ....

gdh1995 avatar Aug 09 '22 01:08 gdh1995

map <v-speed>

What is this part is doing exactly what does v and speed mean?

And lastly can we not assign directly "+ , -" instead of "h+, h-"

Thanks a lot

heissonly avatar Aug 09 '22 12:08 heissonly

<v-***> is a kind of Vimium-C-only key names, and it won't represent any real key name on a real keyboard. It's designed to solve name resolutions in mappings like mapKey and run. speed is a name and you can change it, if only you change its other occurrences (aka. those in run h+ ...).

You may remove h if you want, and run + speed works. But by default Vimium C doesn't accept a name of -, and it requires unmap to recycle the key of - and use it in a key mapping. The final key mapping will be:

map <v-speed2> openUrl url="javascript:var\u0020a=document.querySelector('video');a.playbackRate+=$c*0.25" mask
# run + speed2
# now use "=" to avoid pressing Shift key
run = speed2
unmap -
run - speed2#count=-1

BTW, if you do want to know "why the mapping rules work", I suggest you may read https://github.com/gdh1995/vimium-c/wiki/Auto-run-a-tree-of-commands to see what's run and how it's parsed as a sequence of Vimium C commands.

Tested on https://twitter.com/ufcfooty/status/1550758078248804352?s=20&t=HAJe1GwH428O0YF0ePZWAw .

gdh1995 avatar Aug 09 '22 13:08 gdh1995

Everything is working as expected about playback speed thanks a lot!

Only issue left is still to go 5 seconds back with specific key for example with q 5 seconds back and with e 5 seconds forward . Can you please share the javascript code of this two command.

I imagine sth like below but of course it is not working.

map q openUrl url="javascript:var\u0020a=document.querySelector('video');a.video5SecondForward"

heissonly avatar Aug 10 '22 14:08 heissonly

map <v-jump> openUrl mask \
  url="javascript:var\u0020a=document.querySelector('video');a.currentTime+=$c*5"
run q -jump
run e jump

gdh1995 avatar Aug 11 '22 06:08 gdh1995

Thanks, it is working as a charm!

heissonly avatar Aug 11 '22 10:08 heissonly

BTW, for any other interested users: run q -jump may only work since Vimium C v1.99.0 (on 22/08/12, it's available on Firefox Add-Ons and Chrome Web Store, but not MS Edge Addons), because there was a bug which would ignore the - sign in v1.98.3 .

gdh1995 avatar Aug 12 '22 01:08 gdh1995

Hi, sometimes(after I closed the chrome) the whole shortcuts we have been set here in this issue, is not working until I change sth about these keys on setting page at vimium custom mapping. (go back, go forward, pause the video, and playback speed)

I change sth in setting and I redo same short key and save it.(about these shortcut) Then they starts work(activate) again. I think it is kind of bug. Because it is only about these video key that we made it here in this issue.

heissonly avatar Aug 13 '22 09:08 heissonly

When you find some keys don't work, then will other key mappings of Vimium C work yet?

gdh1995 avatar Aug 13 '22 10:08 gdh1995

Yes, others are working.

heissonly avatar Aug 13 '22 10:08 heissonly

What about adding a blank line between those key mappings and click Save Options? Will keys work then?

What's your keyboard layout, input language and input method (IME)? If you only use an English QWERTY keyboard layout, will this still happen after a restart?

I tested e and q on a fresh profile of Chrome, and the 2 keys worked when Chrome had restarted and I opened a new tab and visited the test twiter URL.

gdh1995 avatar Aug 13 '22 10:08 gdh1995

Actually, I use German keyboard . It is really interesting now is working even I restart the chrome. If I find exact bug I'll let you know .

heissonly avatar Aug 13 '22 11:08 heissonly

The mappings above use var a=document.querySelector('video'), so if a web page has more than one <video> element, then it may select one which you don't expect. So here's a better mapping:

map <v-speed2> openUrl mask \
  url="javascript:var\u0020a=document.activeElement;\
a=a.matches('video')?a:document.querySelector('video');\
a.playbackRate+=$c*0.25"
map <v-jump> openUrl mask \
  url="javascript:var\u0020a=document.activeElement;\
a=a.matches('video')?a:document.querySelector('video');\
a.currentTime+=$c*5"

run = speed2
unmap -
run - -speed2
run q -jump
run e jump

And then, you may press f to show LinkHints and select a <video> element, so that -/=/q/e will prefer it.

gdh1995 avatar Aug 13 '22 11:08 gdh1995

Did you try yourself this settings on twitter videos ?

And then, you may press f to show LinkHints and select a

It is not selecting with video element even though I made f and select the video with Linkhints. So key-mapping is only working for the first video selected..

heissonly avatar Aug 13 '22 18:08 heissonly

Oh, it's because some <video>s like twitter's are not focusable, when they don't have native control bars.

Then it requires a new mapping rule to make videos "focusable":

# add `[tabindex=0]` to `<video>`s and select it
# `F` can be replaced with whatever keys you like
map F LinkHints.activateHover toggle={"video":"+[tabindex=0]"} \
  $then="LinkHints.click#direct=hovered"

And then pressing F will make <video> without [controls] become <video tabindex=0>, then q and e can select it.

Or if you find there're too many hints on F, you may limit its targets by:

# only show hints for `<video>` elements
map F LinkHints.activateHover toggle={"video":"+[tabindex=0]"} \
  match="video" \
  $then="LinkHints.click#direct=hovered"

gdh1995 avatar Aug 15 '22 02:08 gdh1995

Oh, it's because some <video>s like twitter's are not focusable, when they don't have native control bars.

Then it requires a new mapping rule to make videos "focusable":

# add `[tabindex=0]` to `<video>`s and select it
# `F` can be replaced with whatever keys you like
map F LinkHints.activateHover toggle={"video":"+[tabindex=0]"} \
  $then="LinkHints.click#direct=hovered"

And then pressing F will make <video> without [controls] become <video tabindex=0>, then q and e can select it.

Or if you find there're too many hints on F, you may limit its targets by:

# only show hints for `<video>` elements
map F LinkHints.activateHover toggle={"video":"+[tabindex=0]"} \
  match="video" \
  $then="LinkHints.click#direct=hovered"

None of these are working on twitter. Did you test it yourself ?

heissonly avatar Aug 17 '22 07:08 heissonly

I'm sure both the two mappings work - they do show hints for <video> elements, if only you press F (note it's not f but F ), and then following -, =, q and e will prefer the selected video element.

The test page is still https://twitter.com/ufcfooty/status/1550758078248804352?s=20&t=HAJe1GwH428O0YF0ePZWAw .

  1. If you press f (when CapsLock is off, press a single F), then it won't make Vimium execute LinkHints.activateHover toggle={"video":"+[tabindex=0]"} $then="LinkHints.click#direct=hovered"
    1. map F xxx means to type an UPPER-CASE letter, so when CapsLock is off it means Shift+F
  1. If you click any other element after using F to select a video, then the "active" element will what you click, so following -/=/q/e can not know what video to work on - as a fallback, they'll select a "first" video

gdh1995 avatar Aug 17 '22 13:08 gdh1995

And as said in https://github.com/gdh1995/vimium-c/issues/680#issuecomment-1195537736 , twitter shows extra transparent rectangles over videos, so with map F LinkHints.activateHover toggle={"video":"+[tabindex=0]"} \ $then="LinkHints.click#direct=hovered" you'll need to select a correct hint mark - match="video" is just to avoid this.

gdh1995 avatar Aug 17 '22 13:08 gdh1995

it's my intention. I want to use keyboard with only my left hand. And it is not that I want to 10 seconds backward as like in arrow keys but 5 seconds which I need to adjust with JavaScript code.

On Tue, Aug 2, 2022, 20:16 defacube @.***> wrote:

if you want to do the forward and backward thingy then just press the → and ← keys on your keyboard (left and right arrow keys)

— Reply to this email directly, view it on GitHub https://github.com/gdh1995/vimium-c/issues/687#issuecomment-1203063501, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACR77EC325C6DJO2KI5KZI3VXFQXZANCNFSM55ASMI4A . You are receiving this because you authored the thread.Message ID: @.***>

heissonly avatar Oct 11 '22 07:10 heissonly

None of these are working on twitter

Have you solved it on your browser?

If you want to use only your left hand, you may change key sequences next to the above map or run word, like:

# map <v-jump> ...
run Gc -jump
run Gv jump

gdh1995 avatar Dec 25 '22 18:12 gdh1995