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