qt_web_browser_scripts.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. constexpr char NX_FONT_CSS[] = R"(
  6. (function() {
  7. css = document.createElement('style');
  8. css.type = 'text/css';
  9. css.id = 'nx_font';
  10. css.innerText = `
  11. /* FontStandard */
  12. @font-face {
  13. font-family: 'FontStandard';
  14. src: url('%1') format('truetype');
  15. }
  16. /* FontChineseSimplified */
  17. @font-face {
  18. font-family: 'FontChineseSimplified';
  19. src: url('%2') format('truetype');
  20. }
  21. /* FontExtendedChineseSimplified */
  22. @font-face {
  23. font-family: 'FontExtendedChineseSimplified';
  24. src: url('%3') format('truetype');
  25. }
  26. /* FontChineseTraditional */
  27. @font-face {
  28. font-family: 'FontChineseTraditional';
  29. src: url('%4') format('truetype');
  30. }
  31. /* FontKorean */
  32. @font-face {
  33. font-family: 'FontKorean';
  34. src: url('%5') format('truetype');
  35. }
  36. /* FontNintendoExtended */
  37. @font-face {
  38. font-family: 'NintendoExt003';
  39. src: url('%6') format('truetype');
  40. }
  41. /* FontNintendoExtended2 */
  42. @font-face {
  43. font-family: 'NintendoExt003';
  44. src: url('%7') format('truetype');
  45. }
  46. `;
  47. document.head.appendChild(css);
  48. })();
  49. )";
  50. constexpr char LOAD_NX_FONT[] = R"(
  51. (function() {
  52. var elements = document.querySelectorAll("*");
  53. for (var i = 0; i < elements.length; i++) {
  54. var style = window.getComputedStyle(elements[i], null);
  55. if (style.fontFamily.includes("Arial") || style.fontFamily.includes("Calibri") ||
  56. style.fontFamily.includes("Century") || style.fontFamily.includes("Times New Roman")) {
  57. elements[i].style.fontFamily = "FontStandard, FontChineseSimplified, FontExtendedChineseSimplified, FontChineseTraditional, FontKorean, NintendoExt003";
  58. } else {
  59. elements[i].style.fontFamily = style.fontFamily + ", FontStandard, FontChineseSimplified, FontExtendedChineseSimplified, FontChineseTraditional, FontKorean, NintendoExt003";
  60. }
  61. }
  62. })();
  63. )";
  64. constexpr char FOCUS_LINK_ELEMENT_SCRIPT[] = R"(
  65. if (document.getElementsByTagName("a").length > 0) {
  66. document.getElementsByTagName("a")[0].focus();
  67. }
  68. )";
  69. constexpr char GAMEPAD_SCRIPT[] = R"(
  70. window.addEventListener("gamepadconnected", function(e) {
  71. console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
  72. e.gamepad.index, e.gamepad.id, e.gamepad.buttons.length, e.gamepad.axes.length);
  73. });
  74. window.addEventListener("gamepaddisconnected", function(e) {
  75. console.log("Gamepad disconnected from index %d: %s", e.gamepad.index, e.gamepad.id);
  76. });
  77. )";
  78. constexpr char WINDOW_NX_SCRIPT[] = R"(
  79. var end_applet = false;
  80. var yuzu_key_callbacks = [];
  81. (function() {
  82. class WindowNX {
  83. constructor() {
  84. yuzu_key_callbacks[1] = function() { window.history.back(); };
  85. yuzu_key_callbacks[2] = function() { window.nx.endApplet(); };
  86. }
  87. addEventListener(type, listener, options) {
  88. console.log("nx.addEventListener called, type=%s", type);
  89. window.addEventListener(type, listener, options);
  90. }
  91. endApplet() {
  92. console.log("nx.endApplet called");
  93. end_applet = true;
  94. }
  95. playSystemSe(system_se) {
  96. console.log("nx.playSystemSe is not implemented, system_se=%s", system_se);
  97. }
  98. sendMessage(message) {
  99. console.log("nx.sendMessage is not implemented, message=%s", message);
  100. }
  101. setCursorScrollSpeed(scroll_speed) {
  102. console.log("nx.setCursorScrollSpeed is not implemented, scroll_speed=%d", scroll_speed);
  103. }
  104. }
  105. class WindowNXFooter {
  106. setAssign(key, label, func, option) {
  107. console.log("nx.footer.setAssign called, key=%s", key);
  108. switch (key) {
  109. case "A":
  110. yuzu_key_callbacks[0] = func;
  111. break;
  112. case "B":
  113. yuzu_key_callbacks[1] = func;
  114. break;
  115. case "X":
  116. yuzu_key_callbacks[2] = func;
  117. break;
  118. case "Y":
  119. yuzu_key_callbacks[3] = func;
  120. break;
  121. case "L":
  122. yuzu_key_callbacks[6] = func;
  123. break;
  124. case "R":
  125. yuzu_key_callbacks[7] = func;
  126. break;
  127. }
  128. }
  129. setFixed(kind) {
  130. console.log("nx.footer.setFixed is not implemented, kind=%s", kind);
  131. }
  132. unsetAssign(key) {
  133. console.log("nx.footer.unsetAssign called, key=%s", key);
  134. switch (key) {
  135. case "A":
  136. yuzu_key_callbacks[0] = function() {};
  137. break;
  138. case "B":
  139. yuzu_key_callbacks[1] = function() {};
  140. break;
  141. case "X":
  142. yuzu_key_callbacks[2] = function() {};
  143. break;
  144. case "Y":
  145. yuzu_key_callbacks[3] = function() {};
  146. break;
  147. case "L":
  148. yuzu_key_callbacks[6] = function() {};
  149. break;
  150. case "R":
  151. yuzu_key_callbacks[7] = function() {};
  152. break;
  153. }
  154. }
  155. }
  156. class WindowNXPlayReport {
  157. incrementCounter(counter_id) {
  158. console.log("nx.playReport.incrementCounter is not implemented, counter_id=%d", counter_id);
  159. }
  160. setCounterSetIdentifier(counter_id) {
  161. console.log("nx.playReport.setCounterSetIdentifier is not implemented, counter_id=%d", counter_id);
  162. }
  163. }
  164. window.nx = new WindowNX();
  165. window.nx.footer = new WindowNXFooter();
  166. window.nx.playReport = new WindowNXPlayReport();
  167. })();
  168. )";