@@ -5,7 +5,7 @@ async function clearData() {
55 dbs . forEach ( db => { window . indexedDB . deleteDatabase ( db . name ) } )
66}
77
8- var DEV = false ;
8+ var DEV = true ;
99
1010window . onerror = function ( msg , url , linenumber ) {
1111 if ( DEV === true ) {
@@ -72,15 +72,29 @@ function getImg(id) {
7272}
7373
7474if (
75- ( getCookie ( 'li' ) === '' || getCookie ( 'li' ) === undefined ) &&
76- window . localStorage . getItem ( 'offline' ) !== 'true'
75+ window . localStorage . getItem ( 'offline' ) === 'true' &&
76+ window . localStorage . getItem ( 'li' ) === '' ||
77+ window . localStorage . getItem ( 'offline' ) === 'true' &&
78+ window . localStorage . getItem ( "li" ) === null
7779) {
78- window . location = '../../index.html' ;
80+ document . querySelector ( ".btn-lo" ) . style . display = "none" ;
81+ document . querySelector ( ".btn-clear" ) . style . display = "none" ;
82+ document . querySelector ( "#account" ) . style . display = "none" ;
83+ document . querySelector ( ".btn-logon" ) . style . display = "block" ;
84+
85+ var newPara = document . createElement ( 'p' ) ;
86+
87+ newPara . innerHTML = 'Not logged in. Please <a href="./login.html">log in</a>.' ;
88+
89+ document . getElementById ( 'load' ) . style . display = 'none' ;
90+ document . getElementById ( 'newProjectForm' ) . style . display = 'none' ;
91+ document . querySelector ( '.projects-container' ) . appendChild ( newPara ) ;
7992} else if (
8093 window . localStorage . getItem ( 'li' ) !== null &&
8194 window . localStorage . getItem ( 'offline' ) === 'true'
8295) {
8396 document . getElementById ( 'account' ) . style . display = 'none' ;
97+ document . querySelector ( ".btn-logon" ) . style . display = "none" ;
8498 var username = window . localStorage . getItem ( 'li' ) ;
8599
86100 var data = JSON . parse ( window . localStorage . getItem ( username ) ) ;
@@ -194,27 +208,71 @@ document.getElementById('new').onclick = function () {
194208 ) ;
195209 } else if (
196210 document . getElementById ( 'name' ) . value !== '' &&
197- window . localStorage . getItem ( 'offline' ) === 'true' &&
198- pjs . includes ( document . getElementById ( 'name' ) . value ) !== true
211+ window . localStorage . getItem ( 'offline' ) === 'true'
199212 ) {
200- set ( document . getElementById ( 'name' ) . value , {
201- name : document . getElementById ( 'name' ) . value ,
202- sources : [ ] ,
203- } ) ;
204- var accountData = JSON . parse (
205- window . localStorage . getItem ( window . localStorage . getItem ( 'li' ) )
206- ) ;
207- if ( accountData . editor !== '' ) {
208- accountData . editor =
209- accountData . editor + ':' + document . getElementById ( 'name' ) . value ;
210- } else {
211- accountData . editor = document . getElementById ( 'name' ) . value ;
213+ var editorData ;
214+ function trySet ( count ) {
215+ if ( count == 0 ) {
216+ var checkedData ;
217+ get ( document . getElementById ( 'name' ) . value ) . then ( ( val ) => {
218+ checkedData = val ;
219+ if ( checkedData === undefined ) {
220+ set ( document . getElementById ( 'name' ) . value , {
221+ name : document . getElementById ( 'name' ) . value ,
222+ sources : [ ] ,
223+ } ) ;
224+ editorData = document . getElementById ( 'name' ) . value ;
225+ var accountData = JSON . parse (
226+ window . localStorage . getItem ( window . localStorage . getItem ( 'li' ) )
227+ ) ;
228+ if ( accountData . editor !== '' ) {
229+ accountData . editor =
230+ accountData . editor + ':' + editorData ;
231+ } else {
232+ accountData . editor = editorData ;
233+ }
234+ window . localStorage . setItem (
235+ window . localStorage . getItem ( 'li' ) ,
236+ JSON . stringify ( accountData )
237+ ) ;
238+ window . location = './editor.html?id=' + editorData ;
239+ } else {
240+ count += 1 ;
241+ trySet ( count )
242+ }
243+ } )
244+ } else {
245+ var checkedData ;
246+ get ( document . getElementById ( 'name' ) . value + count ) . then ( ( val ) => {
247+ checkedData = val ;
248+ if ( checkedData === undefined ) {
249+ set ( document . getElementById ( 'name' ) . value + count , {
250+ name : document . getElementById ( 'name' ) . value ,
251+ sources : [ ] ,
252+ } ) ;
253+ editorData = document . getElementById ( 'name' ) . value + count ;
254+ var accountData = JSON . parse (
255+ window . localStorage . getItem ( window . localStorage . getItem ( 'li' ) )
256+ ) ;
257+ if ( accountData . editor !== '' ) {
258+ accountData . editor =
259+ accountData . editor + ':' + editorData ;
260+ } else {
261+ accountData . editor = editorData ;
262+ }
263+ window . localStorage . setItem (
264+ window . localStorage . getItem ( 'li' ) ,
265+ JSON . stringify ( accountData )
266+ ) ;
267+ window . location = './editor.html?id=' + editorData ;
268+ } else {
269+ count += 1 ;
270+ trySet ( count )
271+ }
272+ } )
273+ }
212274 }
213- window . localStorage . setItem (
214- window . localStorage . getItem ( 'li' ) ,
215- JSON . stringify ( accountData )
216- ) ;
217- window . location = './editor.html?id=' + document . getElementById ( 'name' ) . value
275+ trySet ( 0 ) ;
218276 } else {
219277 alert ( 'please enter a name!' ) ;
220278 }
@@ -527,3 +585,7 @@ document.querySelector(".btn-clear").onclick = function() {
527585 }
528586
529587}
588+
589+ document . querySelector ( ".btn-logon" ) . onclick = function ( ) {
590+ window . location . replace ( "./login.html" ) ;
591+ }
0 commit comments