From 2986f020c87a69224233292969d817de6155e658 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Wed, 26 Jun 2019 21:51:25 +0200 Subject: Code cleanup --- js/main.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/main.ts b/js/main.ts index b099496..32c5a5b 100644 --- a/js/main.ts +++ b/js/main.ts @@ -14,14 +14,29 @@ function ensureSetting(key: string, defaultValue: string): string { const settings = new KeyValueStore({ wordWrap: { value: ensureSetting('word-wrap', '1') === '1', + callbacks: [ + value => { + localStorage.setItem('word-wrap', value ? '1' : '0'); + } + ], valueRange: [false, true] }, imagePreviews: { value: ensureSetting('image-previews', '1') === '1', + callbacks: [ + value => { + localStorage.setItem('image-previews', value ? '1' : '0'); + } + ], valueRange: [false, true] }, clickablePlainLinks: { value: ensureSetting('clickable-plain-links', '1') === '1', + callbacks: [ + value => { + localStorage.setItem('clickable-plain-links', value ? '1' : '0'); + } + ], valueRange: [false, true] }, }); @@ -81,7 +96,6 @@ const settings = new KeyValueStore({ removeImageThumbnails(); } - localStorage.setItem('image-previews', value ? '1' : '0'); settingImagePreviewValueEl.textContent = value ? '[yes]' : '[no]'; } @@ -105,7 +119,6 @@ const settings = new KeyValueStore({ contentEl.classList.remove("content--wrap"); } - localStorage.setItem('word-wrap', value ? '1' : '0'); settingWordWrapValueEl.textContent = value ? '[yes]' : '[no]'; } @@ -129,7 +142,6 @@ const settings = new KeyValueStore({ removeMarkupForPlainLinks(); } - localStorage.setItem('clickable-plain-links', value ? '1' : '0'); clickablePlainLinksValueEl.textContent = value ? '[yes]' : '[no]'; } @@ -254,7 +266,7 @@ function generateMarkupForPlainLinks() { } const contentEl = document.getElementsByClassName('content')[0]; - const urlRegex = /\b([a-z]*:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,}\b[-a-zA-Z0-9@:%_\+.~#?&//=]*)/g; + const urlRegex = /\b[a-z]*:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,}\b[-a-zA-Z0-9@:%_\+.~#?&//=]*/g; const mailRegex = /\bmailto:[-a-zA-Z0-9@:%._\+~#=]+@(?:[-a-zA-Z0-9@:%._\+~#=]+\.)+[a-z]{2,}\b/g; contentEl.innerHTML = contentEl.innerHTML.replace(urlRegex, match => { -- cgit v1.2.3-70-g09d2