mirror of
https://github.com/comatory/fb2iCal
synced 2025-06-05 22:09:25 +02:00
feature: add UI for user approval of tracking
This commit is contained in:
@ -2,8 +2,10 @@ import { uuidv4, parseStartTimeFromiCalString, useStorage } from './app/utils'
|
||||
import {
|
||||
migrateRecord,
|
||||
getStorage,
|
||||
getConfigStorage,
|
||||
getStorageContents,
|
||||
updateStorage,
|
||||
updateConfigStorage,
|
||||
saveRecord,
|
||||
deleteRecord,
|
||||
} from './app/storage'
|
||||
@ -31,6 +33,40 @@ import generateICS from '../../lib/services/ics-generator'
|
||||
row.remove()
|
||||
}
|
||||
|
||||
const renderTrackingPanel = (storageContents) => {
|
||||
const trackingPanel = document.createElement('div')
|
||||
trackingPanel.id = 'tracking-panel'
|
||||
|
||||
const text = document.createElement('p')
|
||||
text.innerText = `Can we store anonymous logs? This data is only saved to \
|
||||
our internal database and is used to debug the parsing of the web pages.\n\
|
||||
We'll ask you only this time and won't bother you again.`
|
||||
|
||||
const yesButton = document.createElement('button')
|
||||
yesButton.id = 'tracking-panel__yes-button'
|
||||
yesButton.innerText = 'Ok'
|
||||
yesButton.addEventListener('click', () => {
|
||||
updateConfigStorage(storageContents, 'track', true)
|
||||
logger.setRemoteLogging(true)
|
||||
trackingPanel.remove()
|
||||
})
|
||||
|
||||
const noButton = document.createElement('button')
|
||||
noButton.id = 'tracking-panel__no-button'
|
||||
noButton.innerText = 'Nope'
|
||||
noButton.addEventListener('click', () => {
|
||||
updateConfigStorage(storageContents, 'track', false)
|
||||
logger.setRemoteLogging(false)
|
||||
trackingPanel.remove()
|
||||
})
|
||||
|
||||
trackingPanel.appendChild(text)
|
||||
trackingPanel.appendChild(yesButton)
|
||||
trackingPanel.appendChild(noButton)
|
||||
|
||||
document.body.appendChild(trackingPanel)
|
||||
}
|
||||
|
||||
const insertTableRow = ({ id, link, createdAt, startTime, title }) => {
|
||||
showTable()
|
||||
|
||||
@ -122,6 +158,34 @@ import generateICS from '../../lib/services/ics-generator'
|
||||
})
|
||||
}
|
||||
|
||||
const hydrateConfig = () => {
|
||||
if (!useStorage()) {
|
||||
return
|
||||
}
|
||||
|
||||
const prevStorage = getConfigStorage()
|
||||
const storageContents = getStorageContents(prevStorage)
|
||||
|
||||
const useTrackingSet = storageContents.track !== undefined
|
||||
|
||||
if (!useTrackingSet) {
|
||||
renderTrackingPanel(storageContents)
|
||||
}
|
||||
}
|
||||
|
||||
const configureLogger = (logger) => {
|
||||
if (!logger || !useStorage()) {
|
||||
return
|
||||
}
|
||||
|
||||
const prevStorage = getConfigStorage()
|
||||
const storageContents = getStorageContents(prevStorage)
|
||||
|
||||
const shouldTrack = Boolean(storageContents.track)
|
||||
|
||||
logger.setRemoteLogging(shouldTrack)
|
||||
}
|
||||
|
||||
const clearStatuses = () => {
|
||||
document.querySelectorAll('.status-item').forEach((item) => {
|
||||
item.classList.remove('show')
|
||||
@ -235,6 +299,8 @@ import generateICS from '../../lib/services/ics-generator'
|
||||
}
|
||||
|
||||
hydrateList()
|
||||
hydrateConfig()
|
||||
configureLogger(logger)
|
||||
|
||||
const handleHTMLResponse = (html, url) => {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user