Commit 16d2a680 authored by koyaanis's avatar koyaanis
Browse files

Init

parent a20d17fb
// ==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;
}
})();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment