@@ -119,6 +119,7 @@ function isIframeLoaded() {
119119 iframe . addEventListener ( 'load' , function ( ) {
120120 updateTabDetail ( iframe . contentWindow . document . title , iframe . contentWindow . document . querySelector ( 'link[rel="icon"]' ) ? proxyOtherStuff ( iframe . contentWindow . document . querySelector ( 'link[rel="icon"]' ) . href ) : "favicon.ico" , currentTab ) ;
121121 updateURLBar ( iframe . contentWindow . location . href ) ;
122+ addToHistory ( iframe . contentWindow . location . href , iframe . contentWindow . document . title , iframe . contentWindow . document . querySelector ( 'link[rel="icon"]' ) ? proxyOtherStuff ( iframe . contentWindow . document . querySelector ( 'link[rel="icon"]' ) . href ) : "favicon.ico" ) ;
122123 } ) ;
123124}
124125function exitIframe ( ) {
@@ -130,4 +131,131 @@ function exitIframe() {
130131 iframe . style . zIndex = '' ;
131132 iframe . style . transition = '' ;
132133 document . getElementById ( 'exit-iframe' ) . classList . add ( 'dnone' ) ;
133- }
134+ }
135+
136+ function historySidebar ( ) {
137+ let history = document . getElementById ( 'history' ) ;
138+ history . classList . remove ( 'dnone' ) ;
139+ setPage ( 'history' ) ;
140+ }
141+
142+ function closeHistorySidebar ( ) {
143+ let history = document . getElementById ( 'history' ) ;
144+ history . classList . add ( 'dnone' ) ;
145+ }
146+
147+ function addToHistory ( url , title , favicon ) {
148+ let history = document . getElementById ( 'history' ) ;
149+ let historyContent = document . getElementById ( 'history-content' ) ;
150+ let historyItem = document . createElement ( 'div' ) ;
151+
152+ historyItem . setAttribute ( 'id' , 'history-item' ) ;
153+
154+ let historyLink = document . createElement ( 'a' ) ;
155+ historyLink . setAttribute ( 'id' , 'history-link' ) ;
156+ historyLink . setAttribute ( 'onclick' , `handoffToTABS('${ url } ')` ) ;
157+
158+ let historyTitle = document . createElement ( 'p' ) ;
159+ historyTitle . innerText = title ;
160+
161+ let historyFavicon = document . createElement ( 'img' ) ;
162+ historyFavicon . setAttribute ( 'src' , favicon ) ;
163+
164+ let historyDelete = document . createElement ( 'li' ) ;
165+ historyDelete . setAttribute ( 'id' , 'history-delete' ) ;
166+ historyDelete . setAttribute ( 'onclick' , `deleteHistoryItem(${ historyContent . childElementCount } )` ) ;
167+ historyDelete . classList . add ( 'fa-solid' , 'fa-trash' ) ;
168+
169+ historyLink . appendChild ( historyFavicon ) ;
170+ historyLink . appendChild ( historyTitle ) ;
171+ historyItem . appendChild ( historyLink ) ;
172+ historyContent . appendChild ( historyItem ) ;
173+ historyItem . appendChild ( historyDelete ) ;
174+
175+ if ( localStorage . getItem ( 'history' ) === null ) {
176+ let historyArray = [ ] ;
177+ historyArray . push ( {
178+ url : url ,
179+ title : title ,
180+ favicon : favicon ,
181+ } ) ;
182+ localStorage . setItem ( 'history' , JSON . stringify ( { history : historyArray } ) ) ;
183+ }
184+ else {
185+ let historyJSON = JSON . parse ( localStorage . getItem ( 'history' ) ) ;
186+ let historyArray = historyJSON . history ;
187+ historyArray . push ( {
188+ url : url ,
189+ title : title ,
190+ favicon : favicon ,
191+ id : historyArray . length ,
192+ } ) ;
193+ localStorage . setItem ( 'history' , JSON . stringify ( { history : historyArray } ) ) ;
194+ }
195+ }
196+
197+ function restoreHistory ( ) {
198+ let history = document . getElementById ( 'history' ) ;
199+ let historyContent = document . getElementById ( 'history-content' ) ;
200+ if ( localStorage . getItem ( 'history' ) === null ) {
201+ return ;
202+ }
203+ let historyJSON = JSON . parse ( localStorage . getItem ( 'history' ) ) ;
204+ let historyArray = historyJSON . history ;
205+ historyArray . forEach ( function ( item ) {
206+ let historyItem = document . createElement ( 'div' ) ;
207+
208+ historyItem . setAttribute ( 'id' , 'history-item' ) ;
209+
210+ let historyLink = document . createElement ( 'a' ) ;
211+ historyLink . setAttribute ( 'id' , 'history-link' ) ;
212+ historyLink . setAttribute ( 'onclick' , `handoffToTABS('${ item . url } ')` ) ;
213+
214+ let historyTitle = document . createElement ( 'p' ) ;
215+ historyTitle . innerText = item . title ;
216+
217+ let historyFavicon = document . createElement ( 'img' ) ;
218+ historyFavicon . setAttribute ( 'src' , item . favicon ) ;
219+
220+ let historyDelete = document . createElement ( 'li' ) ;
221+ historyDelete . setAttribute ( 'id' , 'history-delete' ) ;
222+ historyDelete . setAttribute ( 'onclick' , `deleteHistoryItem(${ item . id } )` ) ;
223+ historyDelete . classList . add ( 'fa-solid' , 'fa-trash' ) ;
224+
225+ historyLink . appendChild ( historyFavicon ) ;
226+ historyLink . appendChild ( historyTitle ) ;
227+ historyItem . appendChild ( historyLink ) ;
228+ historyItem . appendChild ( historyDelete ) ;
229+ historyContent . appendChild ( historyItem ) ;
230+ } ) ;
231+ }
232+
233+ function deleteHistoryItem ( id ) {
234+ if ( localStorage . getItem ( 'history' ) === null ) {
235+ return ;
236+ }
237+ let historyJSON = JSON . parse ( localStorage . getItem ( 'history' ) ) ;
238+ let historyArray = historyJSON . history ;
239+ historyArray = historyArray . filter ( ( item ) => item . id != id ) ;
240+ localStorage . setItem ( 'history' , JSON . stringify ( { history : historyArray } ) ) ;
241+ let historyContent = document . getElementById ( 'history-content' ) ;
242+ historyContent . innerHTML = '' ;
243+ restoreHistory ( ) ;
244+ }
245+
246+
247+ function historySidebarKeybinds ( ) {
248+ document . addEventListener ( 'keydown' , function ( e ) {
249+ if ( e . altKey && e . key === 'h' ) {
250+ if ( document . getElementById ( 'history' ) . classList . contains ( 'dnone' ) ) {
251+ historySidebar ( ) ;
252+ }
253+ else {
254+ home ( closeHistorySidebar ( ) ) ;
255+ }
256+ }
257+ } ) ;
258+ console . log ( 'history keybinds loaded' ) ;
259+ restoreHistory ( ) ;
260+ console . log ( 'history restored' ) ;
261+ }
0 commit comments