YouTube - Always Theater Mode

Set the default viewing mode to Theater Mode.

当前为 2016-07-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube - Always Theater Mode
  3. // @namespace r-a-y/youtube/theater
  4. // @description Set the default viewing mode to Theater Mode.
  5. // @include http://www.youtube.com/watch*
  6. // @include https://www.youtube.com/watch*
  7. // @version 1.3.3
  8. // @grant none
  9. // @run-at document-start
  10. // @license GPL v3
  11. // ==/UserScript==
  12.  
  13. // Ensure unsafeWindow object is available both in firefox and chrome
  14. //
  15. // Props Anon via YouTube Cinema Mode userscript
  16. // https://greasyfork.org/en/scripts/10417-youtube-cinema-mode
  17. function installUnsafewindowPolyfill()
  18. {
  19. if (typeof unsafeWindow === 'undefined')
  20. {
  21. if (typeof XPCNativeWrapper === 'function' && typeof XPCNativeWrapper.unwrap === 'function')
  22. unsafeWindow = XPCNativeWrapper.unwrap(window);
  23. else if (window.wrappedJSObject)
  24. unsafeWindow = window.wrappedJSObject;
  25. }
  26. }
  27.  
  28. // Disable SPF (Structured Page Fragments), which prevents properly attaching to page load events when navigation occurs
  29. // Will also disable the red loading bar.
  30. //
  31. // Props Anon via YouTube Cinema Mode userscript
  32. // https://greasyfork.org/en/scripts/10417-youtube-cinema-mode
  33. function disableSPF()
  34. {
  35. if (unsafeWindow._spf_state && unsafeWindow._spf_state.config)
  36. {
  37. unsafeWindow._spf_state.config['navigate-limit'] = 0;
  38. unsafeWindow._spf_state.config['navigate-part-received-callback'] = function (targetUrl) { location.href = targetUrl; }
  39. }
  40.  
  41. setTimeout(disableSPF, 50);
  42. }
  43.  
  44. // flash + html5 requires manually resizing the stage
  45. function resizeStage() {
  46. var playlist;
  47.  
  48. document.getElementById('page').className = "watch watch-stage-mode watch-wide";
  49. document.getElementById('player').className = "content-alignment watch-medium";
  50. document.getElementById('watch7-container').className = "watch-wide";
  51.  
  52. // handle playlists
  53. playlist = document.getElementById('watch-appbar-playlist');
  54. if (playlist) {
  55. playlist.setAttribute('style', 'top:120px');
  56. }
  57. }
  58.  
  59. /** TIME FOR SOME ACTION! **/
  60.  
  61. // get rid of SPF
  62. installUnsafewindowPolyfill();
  63. disableSPF();
  64.  
  65. // resize after document is loaded
  66. window.addEventListener ("load", function() {
  67. resizeStage();
  68. });