1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Iota's Notepad - Developer Options</ title >
7+ < style >
8+ h1 {
9+ margin : 0 0 20px ;
10+
11+ }
12+ body {
13+ background-color : # 1a1a1a ;
14+ color : white;
15+ font-family : Arial, sans-serif;
16+ padding : 5px ;
17+ }
18+ table {
19+ width : 100% ;
20+ border-collapse : collapse;
21+ margin-top : 20px ;
22+ }
23+ th , td {
24+ border : 1px solid # 333 ;
25+ padding : 8px ;
26+ text-align : left;
27+ }
28+ th {
29+ background-color : # 333 ;
30+ }
31+ tr : nth-child (even) {
32+ background-color : # 2a2a2a ;
33+ }
34+ button {
35+ background-color : # 444 ;
36+ color : white;
37+ border : none;
38+ padding : 6px 12px ;
39+ margin : 2px 0 ;
40+ cursor : pointer;
41+ }
42+ button : hover {
43+ background-color : # 555 ;
44+ }
45+ # modal {
46+ display : none;
47+ position : fixed;
48+ top : 50% ;
49+ left : 50% ;
50+ transform : translate (-50% , -50% );
51+ background-color : # 222 ;
52+ color : white;
53+ padding : 20px ;
54+ border : 1px solid # 555 ;
55+ box-shadow : 0 0 10px black;
56+ z-index : 1000 ;
57+ max-width : 80% ;
58+ max-height : 80% ;
59+ overflow : auto;
60+ }
61+ # modal h2 {
62+ margin : 0 0 10px ;
63+ }
64+ # modal pre {
65+ white-space : pre-wrap; /* Handle line breaks and long text */
66+ word-wrap : break-word; /* Break long words */
67+ }
68+ </ style >
69+ </ head >
70+ < body >
71+ < h1 > Developer Options</ h1 >
72+ < button onclick ="refreshStorage() "> Refresh Local Storage</ button >
73+ < div id ="dev-tools ">
74+ < table id ="storage-table ">
75+ < thead >
76+ < tr >
77+ < th > Key</ th >
78+ < th > Actions</ th >
79+ </ tr >
80+ </ thead >
81+ < tbody >
82+ </ tbody >
83+ </ table >
84+ </ div >
85+
86+ <!-- Modal for displaying key-value -->
87+ < div id ="modal ">
88+ < h2 > Key Details</ h2 >
89+ < p id ="modal-key "> < strong > Key:</ strong > </ p >
90+ < pre id ="modal-value "> </ pre >
91+ < button onclick ="closeModal() "> Close</ button >
92+ </ div >
93+
94+ < script >
95+
96+ // Function to refresh the storage view
97+ function refreshStorage ( ) {
98+ console . log ( "Refreshing local storage..." ) ;
99+
100+ const tableBody = document . querySelector ( "#storage-table tbody" ) ;
101+ tableBody . innerHTML = "" ; // Clear previous rows
102+
103+ for ( let i = 0 ; i < localStorage . length ; i ++ ) {
104+ const key = localStorage . key ( i ) ;
105+ const value = localStorage . getItem ( key ) ;
106+
107+ const row = document . createElement ( "tr" ) ;
108+ row . innerHTML = `
109+ <td>${ key } </td>
110+ <td>
111+ <button onclick="viewKey('${ key } ')">View</button>
112+ <button onclick="deleteKey('${ key } ')">Delete</button>
113+ </td>
114+ ` ;
115+ tableBody . appendChild ( row ) ;
116+ }
117+ }
118+
119+ // Function to view key-value in a modal
120+ function viewKey ( key ) {
121+ console . log ( `Viewing key: ${ key } ` ) ;
122+
123+ const value = localStorage . getItem ( key ) ;
124+ const modal = document . getElementById ( "modal" ) ;
125+ const overlay = document . getElementById ( "overlay" ) ;
126+
127+ document . getElementById ( "modal-key" ) . innerHTML = `<strong>Key:</strong> ${ key } ` ;
128+
129+ // Process the value for JSON or format \n
130+ try {
131+ // Try parsing JSON and pretty-print
132+ console . log ( "Attempting to parse JSON value..." ) ;
133+ document . getElementById ( "modal-value" ) . textContent = JSON . stringify ( JSON . parse ( value ) , null , 2 ) ;
134+ } catch {
135+ // Replace \n with actual line breaks for non-JSON
136+ console . log ( "Value is not JSON, replacing line breaks..." ) ;
137+ document . getElementById ( "modal-value" ) . innerHTML = value . replace ( / \n / g, "<br>" ) ;
138+ }
139+
140+ modal . style . display = "block" ;
141+ overlay . style . display = "block" ;
142+ }
143+
144+ // Function to close the modal
145+ function closeModal ( ) {
146+ console . log ( "Closing modal..." ) ;
147+ document . getElementById ( "modal" ) . style . display = "none" ;
148+ }
149+
150+ // Function to delete a key from local storage
151+ function deleteKey ( key ) {
152+ console . log ( `Deleting key: ${ key } ` ) ;
153+ localStorage . removeItem ( key ) ;
154+ refreshStorage ( ) ;
155+ }
156+
157+ // Handle Escape key to close modal
158+ document . addEventListener ( "keydown" , ( e ) => {
159+ if ( e . key === "Escape" ) {
160+ console . log ( "Escape key pressed, closing modal..." ) ;
161+ closeModal ( ) ;
162+ }
163+ } ) ;
164+
165+ // Initial load
166+ console . log ( "Loading initial local storage..." ) ;
167+ refreshStorage ( ) ;
168+ </ script >
169+ </ body >
170+ </ html >
171+
0 commit comments