Twitch, Fullscreen mode with chat

Enable fullscreen mode with chat when click fullscreen button or key down f key on theater mode

  1. // ==UserScript==
  2. // @name Twitch, Fullscreen mode with chat
  3. // @name:ja Twitch, チャット付きフルスクリーンモード
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1.3
  6. // @description Enable fullscreen mode with chat when click fullscreen button or key down f key on theater mode
  7. // @description:ja シアターモードでフルスクリーンボタンを押すかFキーを押したとき、チャットありのフルスクリーンモードになります
  8. // @author You
  9. // @match https://www.twitch.tv/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
  11. // @grant none
  12. // @run-at document-end
  13. // @noframes
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. var selectors = {
  20. fullscreenButton : `[data-a-target="player-fullscreen-button"]`,
  21. theaterModeButton: `[data-a-target="player-theatre-mode-button"]`,
  22. theaterModeStyle: ".channel-root__scroll-area--theatre-mode",
  23. }
  24.  
  25. function setTheaterMode(enabled) {
  26. if (isTheaterMode() != enabled) {
  27. document.querySelector(selectors.theaterModeButton).click();
  28. }
  29. }
  30.  
  31. function isTheaterMode () {
  32. return !!document.querySelector(selectors.theaterModeStyle);
  33. }
  34.  
  35. function requestFullscreen() {
  36. setTheaterMode(true);
  37. document.documentElement.requestFullscreen();
  38. }
  39.  
  40. function cancelEvent(event) {
  41. event.preventDefault();
  42. event.stopPropagation();
  43. event.stopImmediatePropagation();
  44. }
  45.  
  46. document.addEventListener("click", ev => {
  47. if (ev.target && ev.target.closest(selectors.fullscreenButton) && !document.fullscreen) {
  48. cancelEvent(ev);
  49. requestFullscreen();
  50. }
  51. });
  52.  
  53. document.addEventListener("keydown", ev => {
  54. if (ev.target.tagName == "INPUT" || ev.target.tagName == "TEXTAREA") return;
  55. if (ev.key == "f" && !document.fullscreen) {
  56. cancelEvent(ev);
  57. requestFullscreen();
  58. }
  59. });
  60. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址