Fullscreen Shortcut

Add a shortcut to enable fullscreen mode of several streaming-media websites

  1. // ==UserScript==
  2. // @name Fullscreen Shortcut
  3. // @namespace https://greasyfork.org/users/673298
  4. // @version 1.2.5
  5. // @author Fingalzzz
  6. // @description Add a shortcut to enable fullscreen mode of several streaming-media websites
  7. // @homepage https://greasyfork.org/en/scripts/408194-fullscreen-shortcut
  8. // @supportURL https://greasyfork.org/en/scripts/408194-fullscreen-shortcut
  9. // @match https://www.bilibili.com/video/*
  10. // @match https://www.bilibili.com/bangumi/play/*
  11. // @match https://www.iqiyi.com/*
  12. // @match https://v.qq.com/x/*
  13. // @match https://www.youtube.com/*
  14. // @match https://v.youku.com/*
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20. const shortcut = 'Backslash'; // You can change this to your preferred key
  21.  
  22. const siteSelectors = [
  23. { pattern: /bilibili\.com\/(bangumi|video)/, selector: ".bpx-player-ctrl-btn.bpx-player-ctrl-full" },
  24. { pattern: /iqiyi\.com/, selector: ".iqp-btn.iqp-btn-fullscreen" },
  25. { pattern: /v\.qq\.com/, selector: ".txp_btn.txp_btn_fullscreen" },
  26. { pattern: /youtube\.com/, selector: ".ytp-fullscreen-button.ytp-button" }
  27. // Youku handled separately
  28. ];
  29.  
  30. document.addEventListener('keydown', (e) => {
  31. if (e.code === shortcut) {
  32. let selector = null;
  33. const link = window.location.href;
  34.  
  35. for (const site of siteSelectors) {
  36. if (site.pattern.test(link)) {
  37. selector = site.selector;
  38. break;
  39. }
  40. }
  41. if (link.includes('v.youku.com')) {
  42. selector = document.fullscreen ? ".iconfont.icon-exit-fullscreen" : ".iconfont.icon-fullscreen";
  43. }
  44.  
  45. if (selector) {
  46. const btn = document.querySelector(selector);
  47. if (btn) {
  48. btn.click();
  49. } else {
  50. // Optional: Add feedback for debugging
  51. // alert("Fullscreen button not found on this page.");
  52. }
  53. }
  54. }
  55. });
  56. })();
  57.