Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
koyaanis
f0ck.me keyboard shortcuts
Commits
16d2a680
Commit
16d2a680
authored
Feb 21, 2021
by
koyaanis
Browse files
Init
parent
a20d17fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
f0ck-keyboard-shortcuts.js
0 → 100644
View file @
16d2a680
// ==UserScript==
// @name Keyboard shortcuts for f0ck.me
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://f0ck.me/*
// @grant none
// ==/UserScript==
(
function
()
{
'
use strict
'
;
let
config
=
{
rememberFullscreen
:
true
,
volumeSteps
:
0.03
,
timeSteps
:
5
}
// handle picture fullscreens here
if
(
document
.
getElementById
(
'
f0ck-image
'
))
{
let
image
=
document
.
getElementById
(
'
f0ck-image
'
);
image
.
onclick
=
function
()
{
if
(
image
.
style
.
maxHeight
===
''
)
{
localStorage
.
setItem
(
'
wasFullscreen
'
,
'
false
'
);
}
else
{
localStorage
.
setItem
(
'
wasFullscreen
'
,
'
true
'
);
}
}
window
.
onkeydown
=
function
(
evt
)
{
if
(
evt
.
code
===
'
KeyF
'
)
{
if
(
image
.
style
.
maxHeight
===
''
)
{
image
.
style
.
maxHeight
=
'
unset
'
;
localStorage
.
setItem
(
'
wasFullscreen
'
,
'
true
'
);
}
else
{
image
.
style
.
maxHeight
=
''
;
localStorage
.
setItem
(
'
wasFullscreen
'
,
'
false
'
);
}
}
}
window
.
onload
=
function
()
{
if
(
config
.
rememberFullscreen
)
{
if
(
localStorage
.
getItem
(
'
wasFullscreen
'
)
===
'
true
'
)
{
image
.
style
.
maxHeight
=
'
unset
'
;
}
}
else
{
localStorage
.
removeItem
(
'
wasFullscreen
'
);
}
}
return
;
}
// else video shit here
let
player
=
document
.
getElementById
(
"
my-video_html5_api
"
);
let
fullscreenButton
=
document
.
getElementsByClassName
(
'
vjs-fullscreen-control
'
)[
0
];
let
vjsPlayer
=
document
.
getElementById
(
'
my-video
'
);
let
leftControlDown
=
null
;
const
fullscreenObserver
=
new
MutationObserver
((
mutationsList
,
observer
)
=>
{
// Use traditional 'for loops' for IE 11
for
(
const
mutation
of
mutationsList
)
{
if
(
isFullscreen
())
{
localStorage
.
setItem
(
'
wasFullscreen
'
,
'
true
'
);
}
else
{
localStorage
.
setItem
(
'
wasFullscreen
'
,
'
false
'
);
}
}
});
document
.
addEventListener
(
"
click
"
,
evt
=>
{
if
(
leftControlDown
)
{
if
(
evt
.
isTrusted
===
false
&&
evt
.
toElement
.
getAttribute
(
'
id
'
)
!==
'
random
'
)
{
evt
.
preventDefault
();
}
}
});
window
.
onkeydown
=
function
(
evt
)
{
let
code
=
evt
.
code
;
if
(
code
===
'
ControlLeft
'
)
{
leftControlDown
=
true
;
}
else
if
(
code
===
'
ArrowUp
'
)
{
if
(
player
.
volume
+
config
.
volumeSteps
>
1
)
{
player
.
volume
=
1
;
}
else
{
player
.
volume
+=
config
.
volumeSteps
;
}
if
(
player
.
muted
)
{
player
.
muted
=
false
;
}
}
else
if
(
code
===
'
ArrowDown
'
)
{
if
(
player
.
volume
-
config
.
volumeSteps
<
0
)
{
player
.
volume
=
0
;
}
else
{
player
.
volume
-=
config
.
volumeSteps
;
}
if
(
player
.
muted
)
{
player
.
muted
=
false
;
}
}
else
if
(
code
===
'
ArrowLeft
'
)
{
if
(
player
.
currentTime
-
config
.
timeSteps
<
0
)
{
player
.
currentTime
=
0
;
}
else
{
player
.
currentTime
-=
config
.
timeSteps
;
}
}
else
if
(
code
===
'
ArrowRight
'
)
{
if
(
player
.
currentTime
+
config
.
timeSteps
>
player
.
duration
)
{
player
.
currentTime
=
player
.
duration
;
}
else
{
player
.
currentTime
+=
config
.
timeSteps
;
}
}
else
if
(
code
===
'
KeyM
'
)
{
player
.
muted
?
player
.
muted
=
false
:
player
.
muted
=
true
;
}
else
if
(
code
===
'
KeyF
'
)
{
fullscreenButton
.
click
();
}
else
if
(
code
===
'
Space
'
)
{
if
(
player
.
paused
)
{
player
.
play
();
}
else
{
player
.
pause
();
}
}
}
window
.
onkeyup
=
function
(
evt
)
{
let
code
=
evt
.
code
;
if
(
code
===
'
ControlLeft
'
)
{
leftControlDown
=
false
;
}
}
window
.
onload
=
function
()
{
if
(
config
.
rememberFullscreen
)
{
if
(
localStorage
.
getItem
(
'
wasFullscreen
'
)
===
'
true
'
)
{
fullscreenButton
.
click
();
}
}
else
{
localStorage
.
removeItem
(
'
wasFullscreen
'
);
}
// listen to fullscreen mutations
fullscreenObserver
.
observe
(
vjsPlayer
,
{
attributes
:
true
});
}
function
isFullscreen
()
{
if
(
vjsPlayer
.
className
.
includes
(
'
vjs-fullscreen
'
))
{
return
true
;
}
return
false
;
}
})();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment