aboutsummaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-06-26 21:51:25 +0200
committerFeuerfuchs <git@feuerfuchs.dev>2019-06-26 21:51:25 +0200
commit2986f020c87a69224233292969d817de6155e658 (patch)
treee012e5d2b60ece9c38ee8dff8b0a527fe6dfdf17 /js
parentFix URL regex for ending slashes (diff)
downloadgopherproxy-2986f020c87a69224233292969d817de6155e658.tar.gz
gopherproxy-2986f020c87a69224233292969d817de6155e658.tar.bz2
gopherproxy-2986f020c87a69224233292969d817de6155e658.zip
Code cleanup
Diffstat (limited to 'js')
-rw-r--r--js/main.ts20
1 files changed, 16 insertions, 4 deletions
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 {
14const settings = new KeyValueStore({ 14const settings = new KeyValueStore({
15 wordWrap: { 15 wordWrap: {
16 value: ensureSetting('word-wrap', '1') === '1', 16 value: ensureSetting('word-wrap', '1') === '1',
17 callbacks: [
18 value => {
19 localStorage.setItem('word-wrap', value ? '1' : '0');
20 }
21 ],
17 valueRange: [false, true] 22 valueRange: [false, true]
18 }, 23 },
19 imagePreviews: { 24 imagePreviews: {
20 value: ensureSetting('image-previews', '1') === '1', 25 value: ensureSetting('image-previews', '1') === '1',
26 callbacks: [
27 value => {
28 localStorage.setItem('image-previews', value ? '1' : '0');
29 }
30 ],
21 valueRange: [false, true] 31 valueRange: [false, true]
22 }, 32 },
23 clickablePlainLinks: { 33 clickablePlainLinks: {
24 value: ensureSetting('clickable-plain-links', '1') === '1', 34 value: ensureSetting('clickable-plain-links', '1') === '1',
35 callbacks: [
36 value => {
37 localStorage.setItem('clickable-plain-links', value ? '1' : '0');
38 }
39 ],
25 valueRange: [false, true] 40 valueRange: [false, true]
26 }, 41 },
27}); 42});
@@ -81,7 +96,6 @@ const settings = new KeyValueStore({
81 removeImageThumbnails(); 96 removeImageThumbnails();
82 } 97 }
83 98
84 localStorage.setItem('image-previews', value ? '1' : '0');
85 settingImagePreviewValueEl.textContent = value ? '[yes]' : '[no]'; 99 settingImagePreviewValueEl.textContent = value ? '[yes]' : '[no]';
86 } 100 }
87 101
@@ -105,7 +119,6 @@ const settings = new KeyValueStore({
105 contentEl.classList.remove("content--wrap"); 119 contentEl.classList.remove("content--wrap");
106 } 120 }
107 121
108 localStorage.setItem('word-wrap', value ? '1' : '0');
109 settingWordWrapValueEl.textContent = value ? '[yes]' : '[no]'; 122 settingWordWrapValueEl.textContent = value ? '[yes]' : '[no]';
110 } 123 }
111 124
@@ -129,7 +142,6 @@ const settings = new KeyValueStore({
129 removeMarkupForPlainLinks(); 142 removeMarkupForPlainLinks();
130 } 143 }
131 144
132 localStorage.setItem('clickable-plain-links', value ? '1' : '0');
133 clickablePlainLinksValueEl.textContent = value ? '[yes]' : '[no]'; 145 clickablePlainLinksValueEl.textContent = value ? '[yes]' : '[no]';
134 } 146 }
135 147
@@ -254,7 +266,7 @@ function generateMarkupForPlainLinks() {
254 } 266 }
255 267
256 const contentEl = document.getElementsByClassName('content')[0]; 268 const contentEl = document.getElementsByClassName('content')[0];
257 const urlRegex = /\b([a-z]*:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,}\b[-a-zA-Z0-9@:%_\+.~#?&//=]*)/g; 269 const urlRegex = /\b[a-z]*:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,}\b[-a-zA-Z0-9@:%_\+.~#?&//=]*/g;
258 const mailRegex = /\bmailto:[-a-zA-Z0-9@:%._\+~#=]+@(?:[-a-zA-Z0-9@:%._\+~#=]+\.)+[a-z]{2,}\b/g; 270 const mailRegex = /\bmailto:[-a-zA-Z0-9@:%._\+~#=]+@(?:[-a-zA-Z0-9@:%._\+~#=]+\.)+[a-z]{2,}\b/g;
259 271
260 contentEl.innerHTML = contentEl.innerHTML.replace(urlRegex, match => { 272 contentEl.innerHTML = contentEl.innerHTML.replace(urlRegex, match => {