@@ -7,7 +7,7 @@ class KlippedApp {
77 this . closeButton = null ;
88 this . storageKey = 'klipped' ;
99 this . hasUsedAppKey = 'klipped-has-used' ;
10-
10+
1111 this . init ( ) ;
1212 }
1313
@@ -38,6 +38,9 @@ class KlippedApp {
3838 // Setup event listeners
3939 this . setupEventListeners ( ) ;
4040
41+ // Register service worker if available
42+ this . setupServiceWorker ( ) ;
43+
4144 // Update title initially
4245 this . updateTitle ( ) ;
4346 }
@@ -71,7 +74,7 @@ class KlippedApp {
7174 if ( e . key === 'Escape' && this . modal . classList . contains ( 'show' ) ) {
7275 this . hideModal ( ) ;
7376 }
74-
77+
7578 // Keyboard shortcuts
7679 if ( e . metaKey || e . ctrlKey ) {
7780 switch ( e . key ) {
@@ -112,18 +115,32 @@ class KlippedApp {
112115 } ) ;
113116 }
114117
118+ setupServiceWorker ( ) {
119+ if ( 'serviceWorker' in navigator ) {
120+ window . addEventListener ( 'load' , ( ) => {
121+ navigator . serviceWorker . register ( '/sw.js' )
122+ . then ( ( registration ) => {
123+ console . log ( 'SW registered: ' , registration ) ;
124+ } )
125+ . catch ( ( registrationError ) => {
126+ console . log ( 'SW registration failed: ' , registrationError ) ;
127+ } ) ;
128+ } ) ;
129+ }
130+ }
131+
115132 loadContent ( ) {
116133 const savedContent = localStorage . getItem ( this . storageKey ) ;
117134 const hasUsedApp = localStorage . getItem ( this . hasUsedAppKey ) ;
118-
135+
119136 if ( savedContent ) {
120137 this . editor . value = savedContent ;
121138 } else if ( ! hasUsedApp ) {
122139 // First time user - set welcome text as actual content
123140 const welcomeText = `Klipped is a simple, privacy-oriented scratchpad.
124141
125142It's like the back of your hand. Write ideas down. Paste snippets of text. Delete when you're done. ` ;
126-
143+
127144 this . editor . value = welcomeText ;
128145 this . saveContent ( welcomeText ) ;
129146 // Mark that the user has now used the app
@@ -139,7 +156,7 @@ It's like the back of your hand. Write ideas down. Paste snippets of text. Delet
139156 localStorage . setItem ( this . hasUsedAppKey , 'true' ) ;
140157 } catch ( error ) {
141158 console . error ( 'Failed to save content:' , error ) ;
142-
159+
143160 // Handle quota exceeded error
144161 if ( error . name === 'QuotaExceededError' ) {
145162 console . warn ( 'LocalStorage quota exceeded. Content may not be saved.' ) ;
@@ -151,11 +168,11 @@ It's like the back of your hand. Write ideas down. Paste snippets of text. Delet
151168 updateTitle ( content = null ) {
152169 const text = content || this . editor . value || '' ;
153170 let title = text . trim ( ) . substring ( 0 , 60 ) ;
154-
171+
155172 if ( title . startsWith ( '"' ) ) {
156173 title = title . substring ( 1 ) ;
157174 }
158-
175+
159176 if ( ! title ) {
160177 document . title = 'Klipped' ;
161178 } else {
@@ -166,7 +183,7 @@ It's like the back of your hand. Write ideas down. Paste snippets of text. Delet
166183 showModal ( ) {
167184 this . modal . classList . add ( 'show' ) ;
168185 document . body . style . overflow = 'hidden' ;
169-
186+
170187 // Focus the close button for accessibility
171188 setTimeout ( ( ) => {
172189 this . closeButton . focus ( ) ;
@@ -181,7 +198,7 @@ It's like the back of your hand. Write ideas down. Paste snippets of text. Delet
181198 hideModal ( ) {
182199 this . modal . classList . remove ( 'show' ) ;
183200 document . body . style . overflow = '' ;
184-
201+
185202 // Focus the info button
186203 this . infoButton . focus ( ) ;
187204
0 commit comments