Animelon shortcuts

Adds several shortcuts to Animelon

  1. // ==UserScript==
  2. // @name Animelon shortcuts
  3. // @namespace https://github.com/sahlaysta/
  4. // @version 0.2
  5. // @description Adds several shortcuts to Animelon
  6. // @author sahlaysta
  7. // @match https://*.animelon.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=animelon.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. //adds a shortcut operation
  17. function addShortcutFunction(keyCodes, shortcutFn) {
  18. document.addEventListener('keydown', event => {
  19. if (!event.altKey && !event.ctrlKey && !event.isComposing
  20. && !/^(?:input|textarea|select|button)$/i.test(event.target.tagName)
  21. && keyCodes.includes(event.keyCode)) {
  22. shortcutFn();
  23. event.preventDefault();
  24. }
  25. });
  26. }
  27.  
  28. //returns the angularjs ng controller for the video player
  29. function getVideoController() {
  30. return window.angular.element(document.getElementById('video-player-container')).scope();
  31. }
  32.  
  33. // Spacebar and K to pause/unpause
  34. addShortcutFunction([32, 75], () => {
  35. const ngCtrl = getVideoController();
  36. ngCtrl.playerValues.triggers.play(!(ngCtrl.playerValues.playing));
  37. });
  38.  
  39. // M to mute/unmute
  40. addShortcutFunction([77], () => {
  41. const ngCtrl = getVideoController();
  42. ngCtrl.playerValues.triggers.volume(ngCtrl.playerValues.storage.volume === 0 ? 1 : 0);
  43. });
  44.  
  45. // P to show/unshow the Discord panel
  46. addShortcutFunction([80], () => {
  47. document.getElementsByClassName('discordButton')[0].click();
  48. });
  49.  
  50. // J to jump to previous dialogue
  51. addShortcutFunction([74], () => {
  52. const ngCtrl = getVideoController();
  53. ngCtrl.playerValues.triggers.backward();
  54. });
  55.  
  56. // L to jump to next dialogue
  57. addShortcutFunction([76], () => {
  58. const ngCtrl = getVideoController();
  59. ngCtrl.playerValues.triggers.forward();
  60. });
  61.  
  62. })();