nhentai.net - G to Fullscreen ⛶

Press G to rotate fullscreen comics

  1. // ==UserScript==
  2. // @name nhentai.net - G to Fullscreen ⛶
  3. // @namespace Violentmonkey Scripts
  4. // @include https://nhentai.net/*
  5. // @icon https://icons.duckduckgo.com/ip2/nhentai.net.ico
  6. // @supportURL https://greasyfork.org/en/scripts/436918-nhentai-net-g-to-fullscreen/code
  7. // @grant none
  8. // @version 1.1
  9. // @author shelbyKiraM
  10. // @license https://choosealicense.com/licenses/mit/
  11. // @inject-into page
  12. // @description Press G to rotate fullscreen comics
  13. // @description macOS users may need to install Symbola: https://fontlibrary.org/en/font/symbola
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var cookieName = 'gtofull'
  19. var expiration_date = new Date(new Date().setFullYear(new Date().getFullYear() + 5)).toUTCString();
  20. var bclass = (document.cookie.match(/gtofull/)?document.cookie.split('; ').find(row => row.startsWith(cookieName+'=')).split('=')[1]:'n');
  21. // wrap the main #content
  22. document.body.classList.add(bclass);
  23. var el = document.querySelector('div#content');
  24. var wrapper = document.createElement('div');
  25. wrapper.setAttribute("id", "fsw");
  26. el.parentNode.insertBefore(wrapper, el);
  27. wrapper.appendChild(el);
  28.  
  29. // add the Full Screen link
  30. var sel="#content .reader-bar:nth-child(2) .zoom-buttons .box:last-child";
  31. document.querySelector(sel).style = "cursor:pointer";
  32. document.querySelector(sel).addEventListener('click', function(e) {
  33. e.preventDefault();
  34. fullscreeny('fsw');
  35. });
  36. document.querySelector(sel).innerHTML = '<a aria-label="Full screen (g)" title="Full screen (g)">&#x26F6;</a>';
  37.  
  38. // G fullscreen shortcut
  39. window.onkeydown = function(e){
  40. if(e.key=='g') {
  41. // Chose G as F was already bound :( ;
  42. fullscreeny("fsw");
  43. }
  44. if(e.key=='r' && (document.fullscreenElement && document.fullscreenElement !== null)) {
  45. // R to rotate.
  46. if (!e.metaKey) {
  47. if (bclass == 'r') {
  48. bclass = 'l';
  49. } else if (bclass == 'l') {
  50. bclass = 'n';
  51. } else {
  52. bclass = 'r';
  53. }
  54. }
  55. document.body.classList = bclass;
  56. document.cookie = cookieName + '=' + bclass + '; expires=' + expiration_date;
  57. }
  58. }
  59.  
  60. // Add custom styles to rotate (originally made on laptop to read like book)
  61. var styles = `@media (display-mode:fullscreen) and (max-device-width: 100vw) and (max-device-height:100vh) {
  62. #content {
  63. transition: transform 0.5s ease-in;
  64. }
  65. #content img {
  66. object-fit: scale-down;
  67. }
  68. .r #content .image-container, .l #content .image-container {
  69. height: auto !important;
  70. }
  71. .r #content img, .l #content img {
  72. width: 100vh
  73. }
  74. .r #content .fit-both img, .l #content .fit-both img {
  75. height: calc(100vw - 40px);
  76. }
  77. .r #content .fit-horizontal img, .l #content .fit-horizontal img {
  78. height: calc(100vw - 80px);
  79. width: 100vh;
  80. }
  81. .r #content {
  82. width: 100vh;
  83. max-height:100vw;
  84. transform:rotate(90deg) translate(0, calc(-100vw + 100vh)); /* 0 or -35 */
  85. }
  86. .l #content {
  87. width: 100vh;
  88. max-height:100vw;
  89. transform:rotate(270deg) translate(0, -0vw); /* 0 or -35 */
  90. }
  91. .n #content {
  92. width: 100vw;
  93. max-height: 100vh;
  94. transform:rotate(0deg) translate(0, -0); /* 0 or -35 */
  95. }
  96. .n #content img {
  97. width: 100vw;
  98. }
  99. .n #content #image-container.fit-horizontal img {
  100. height: calc(100vh - 80px) !important;
  101. background: #000;
  102. }
  103. .n #content #image-container.fit-both img {
  104. height: calc(100vh - 40px) !important;
  105. }
  106. .zoom-buttons.hidden {
  107. display: block !important;
  108. }
  109. .zoom-buttons.hidden .btn, .zoom-buttons.hidden .zoom-level {
  110. display: none;
  111. }
  112. }`;
  113. // '#image-container, #image-container a {max-height:calc(100vw - 60px);object-fit:scale-down;}';
  114. var css = document.createElement('style');
  115. css.innerHTML = styles;
  116. document.getElementsByTagName("head")[0].appendChild(css);
  117.  
  118. function fullscreeny(fullElem) {
  119. // toggles fullscreen
  120. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null);
  121. var elFull = document.getElementById(fullElem);
  122. if (!isInFullScreen) {
  123. if (elFull.requestFullscreen) { elFull.requestFullscreen(); } else if (elFull.mozRequestFullScreen) { elFull.mozRequestFullScreen(); } else if (elFull.webkitRequestFullScreen) { elFull.webkitRequestFullScreen(); } else if (elFull.msRequestFullscreen) { elFull.msRequestFullscreen(); }
  124. } else {
  125. if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); }
  126. }
  127. }
  128. })();