qt_web_browser_scripts.h 5.7 KB

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