From a4d3f0c9122751b7b75a0785eb9993319cf87d1f Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Thu, 14 Nov 2019 00:25:46 +0100 Subject: [PATCH] Improve browser compatibility Fixes #81. --- package.json | 2 +- src/main/css/main.css | 1 + src/main/index.html | 14 ++++++++++++-- src/main/js/Extensions.ts | 4 ++-- src/main/js/Persistence.ts | 19 +++++++++++-------- src/main/js/Shared.ts | 2 +- src/main/js/Terminal.ts | 4 ++-- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 49c6eee..74dfa99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fwdekker.com", - "version": "0.16.0", + "version": "0.16.1", "description": "The source code of [my personal website](https://fwdekker.com/).", "author": "Felix W. Dekker", "repository": { diff --git a/src/main/css/main.css b/src/main/css/main.css index 8069cde..d101d1e 100644 --- a/src/main/css/main.css +++ b/src/main/css/main.css @@ -89,6 +89,7 @@ body { #terminalCurrentPrefix { display: inline-block; vertical-align: top; + white-space: pre; } #terminalCurrentFocusInput { diff --git a/src/main/index.html b/src/main/index.html index a5f1188..c27dcf7 100644 --- a/src/main/index.html +++ b/src/main/index.html @@ -25,15 +25,25 @@ Please check the instructions how to enable JavaScript in your web browser. +
- - +
+ diff --git a/src/main/js/Extensions.ts b/src/main/js/Extensions.ts index bed55a5..dc4780f 100644 --- a/src/main/js/Extensions.ts +++ b/src/main/js/Extensions.ts @@ -8,7 +8,7 @@ interface String { * Returns this string with all leading and trailing whitespace removed from each line. */ String.prototype.trimLines = function(): string { - return this.split("\n").map(it => it.trimStart()).join("\n"); + return this.split("\n").map(it => it.trimLeft()).join("\n"); }; /** @@ -19,7 +19,7 @@ String.prototype.trimLines = function(): string { * split. */ String.prototype.trimMultiLines = function(): string { - return this.trimLines().split("\\").map(it => it.trimStart()).join(""); + return this.trimLines().split("\\").map(it => it.trimLeft()).join(""); }; diff --git a/src/main/js/Persistence.ts b/src/main/js/Persistence.ts index 4b34a75..56b9427 100644 --- a/src/main/js/Persistence.ts +++ b/src/main/js/Persistence.ts @@ -61,14 +61,17 @@ export class Persistence { * failed. */ static getFileSystem(): FileSystem { - try { - const parsedFiles = Node.deserialize(localStorage.getItem("files") ?? "{}"); - if (parsedFiles instanceof Directory) - return new FileSystem(parsedFiles); - else - console.warn("`files` cookie contains non-directory."); - } catch (error) { - console.warn("Failed to deserialize `files` cookie.", error); + const fileString = localStorage.getItem("files"); + if (fileString !== null) { + try { + const parsedFiles = Node.deserialize(fileString); + if (parsedFiles instanceof Directory) + return new FileSystem(parsedFiles); + else + console.warn("`files` cookie contains non-directory."); + } catch (error) { + console.warn("Failed to deserialize `files` cookie.", error); + } } return new FileSystem(); diff --git a/src/main/js/Shared.ts b/src/main/js/Shared.ts index 5fcf9f1..6379318 100644 --- a/src/main/js/Shared.ts +++ b/src/main/js/Shared.ts @@ -28,7 +28,7 @@ export const emptyFunction = () => {}; * @param fun the function to run as soon as the page is done loading */ export function addOnLoad(fun: () => void): void { - const oldOnLoad = window.onload || emptyFunction; + const oldOnLoad = window.onload ?? emptyFunction; window.onload = () => { // @ts-ignore: Call works without parameters as well diff --git a/src/main/js/Terminal.ts b/src/main/js/Terminal.ts index f38f06a..272838e 100644 --- a/src/main/js/Terminal.ts +++ b/src/main/js/Terminal.ts @@ -98,7 +98,7 @@ export class Terminal { * Returns the input the user has entered in the HTML element. */ private get inputText(): string { - return this.input.innerText.replace(/
/g, ""); + return this.input.innerText.replace(/<\/?br>/g, ""); } /** @@ -254,7 +254,7 @@ export class Terminal { */ private onclick(): void { // Focus on input unless user has text selected. This allows user to copy text - if ((document.getSelection() || "").toString() === "") + if ((document.getSelection() ?? "").toString() === "") this.input.focus(); }