diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml new file mode 100644 index 0000000..9142f17 --- /dev/null +++ b/.github/workflows/typecheck.yml @@ -0,0 +1,21 @@ +name: TypeCheck +on: [pull_request, push] + +jobs: + typecheck: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Run TypeScript check + run: npx tsc diff --git a/.gitignore b/.gitignore index c476faf..8a67d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,7 @@ hs_err_*.log replay_*.log *.hprof *.jfr + +# node + +node_modules/ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..08c60fc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,26 @@ +{ + "name": "minecraft-web-chat", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "typescript": "^5.7.2" + } + }, + "node_modules/typescript": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..279d638 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "typescript": "^5.7.2" + } +} diff --git a/src/client/resources/web/js/message_parsing.mjs b/src/client/resources/web/js/message_parsing.mjs index 9e63f7d..8ccdd69 100644 --- a/src/client/resources/web/js/message_parsing.mjs +++ b/src/client/resources/web/js/message_parsing.mjs @@ -89,13 +89,13 @@ function escapeHtml(unsafe) { return ''; } return unsafe - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, ''') - .replace(/`/g, '`') - .replace(/\\/g, '\'); + .replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>') + .replaceAll('"', '"') + .replaceAll("'", ''') + .replaceAll('`', '`') + .replaceAll('\\', '\'); } // Imitates Minecraft's obfuscated text. @@ -132,6 +132,8 @@ export function initializeObfuscation() { for (let i = 0; i < elementsToProcess; i++) { const element = elements[i]; + if (!element) continue; + const length = element.textContent ? element.textContent.length : 0; let result = ''; diff --git a/src/client/resources/web/js/translations.mjs b/src/client/resources/web/js/translations.mjs index a15afae..0928197 100644 --- a/src/client/resources/web/js/translations.mjs +++ b/src/client/resources/web/js/translations.mjs @@ -2,6 +2,7 @@ 'use strict'; // https://github.com/PrismarineJS/minecraft-data 1.21.1 +/** @type {Record} */ export const translations = { "accessibility.onboarding.accessibility.button": "Accessibility Settings...", "accessibility.onboarding.screen.narrator": "Press enter to enable the narrator", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..754e59e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,44 @@ +{ + "compilerOptions": { + "lib": ["dom", "ES2021"], + + // JavaScript Support + "allowJs": true, + "checkJs": true, + "noEmit": true, + + // Module Settings + "module": "ES2020", + "moduleResolution": "node", + "target": "ES2021", + + // Strictness + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "useUnknownInCatchVariables": true, + "alwaysStrict": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + + // Additional Safety + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "verbatimModuleSyntax": true, + "isolatedModules": true + }, + "include": [ + "src/client/resources/web/js/**/*.js", + "src/client/resources/web/js/**/*.mjs" + ], + "exclude": [ + "node_modules" + ] +}