@@ -19,15 +19,14 @@ import {
1919 setV2P_Settings ,
2020} from '../services'
2121import type { Topic } from '../types'
22+ import { formatTimestamp , getStorage , getStorageSync , isSameDay , setStorage } from '../utils'
2223import {
23- escapeHTML ,
24- formatTimestamp ,
25- getStorage ,
26- getStorageSync ,
27- isSameDay ,
28- setStorage ,
29- } from '../utils'
30- import { calculateLocalStorageSize , formatSizeUnits , isTabId } from './popup.helper'
24+ calculateLocalStorageSize ,
25+ formatSizeUnits ,
26+ generateReadingItmes ,
27+ generateTopicItmes ,
28+ isTabId ,
29+ } from './popup.helper'
3130import type { PopupStorageData , RemoteDataStore } from './popup.type'
3231import { defaultValue , TabId } from './popup.var'
3332
@@ -46,6 +45,7 @@ const errorDisplay = `
4645`
4746
4847const topicContentData : Record < TabId , RemoteDataStore > = {
48+ [ TabId . Reading ] : { } ,
4949 [ TabId . Hot ] : {
5050 data : undefined ,
5151 lastFetchTime : undefined ,
@@ -206,21 +206,6 @@ function loadSettings() {
206206}
207207
208208function initTabs ( ) {
209- const generateTopicItmes = ( topics : Topic [ ] ) => {
210- return topics
211- . map ( ( topic ) => {
212- return `
213- <li class="topic-item">
214- <a href="${ topic . url } " target="_blank">
215- <span class="title">${ escapeHTML ( topic . title ) } </span>
216- <span class="content">${ topic . content . replace ( / < [ ^ > ] * > / g, '' ) } </span>
217- </a>
218- </li>
219- `
220- } )
221- . join ( '' )
222- }
223-
224209 const getCurrentActiveTab = ( ) => {
225210 return $ ( '.tabs > li.active' )
226211 }
@@ -236,6 +221,34 @@ function initTabs() {
236221
237222 const $tabContent = $ ( `#${ tabId } ` )
238223
224+ if ( tabId === TabId . Reading ) {
225+ const readingData = storage [ StorageKey . ReadingList ] ?. data
226+ if ( readingData ) {
227+ const $readingList = $ ( `<ul class="list">` ) . append ( generateReadingItmes ( readingData ) )
228+
229+ $tabContent . empty ( ) . append ( $readingList )
230+
231+ $ ( '.topic-item-action-remove' ) . on ( 'click' , ( ev ) => {
232+ ev . preventDefault ( )
233+ ev . stopPropagation ( )
234+
235+ const url = ev . target . dataset . url
236+
237+ if ( url ) {
238+ const newReadingData = readingData . filter ( ( it ) => it . url !== url )
239+
240+ void setStorage ( StorageKey . ReadingList , { data : newReadingData } )
241+
242+ $tabContent
243+ . find ( `.topic-item:has(.topic-item-action-remove[data-url="${ url } "])` )
244+ . remove ( )
245+ }
246+ } )
247+ } else {
248+ $tabContent . empty ( ) . append ( '<div>暂未添加稍后阅读</div>' )
249+ }
250+ }
251+
239252 if ( tabId === TabId . Hot || tabId === TabId . Latest ) {
240253 const loaded = $tabContent . find ( '.list' ) . length > 0
241254
0 commit comments