Allow configuring the auto dismiss time for the extension

This commit is contained in:
Jackson Harper
2023-11-10 11:33:41 +08:00
parent a227d322fa
commit bf37348fd6
7 changed files with 58 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "process.env.EXTENSION_NAME",
"short_name": "process.env.EXTENSION_NAME",
"version": "2.6.2",
"version": "2.8.0",
"description": "Save PDFs and Articles to your Omnivore library",
"author": "Omnivore Media, Inc",
"default_locale": "en",
@ -95,4 +95,4 @@
"web_accessible_resources": [
"views/toast.html"
]
}
}

View File

@ -247,13 +247,29 @@
// Auto hide if everything went well and the user
// has not initiated any interaction.
hideToastTimeout = setTimeout(function () {
console.log('hiding: ', currentToastEl, doNotHide)
if (!doNotHide) {
currentToastEl.remove()
currentToastEl = undefined
}
}, 2500)
const handleAutoDismiss = (autoDismissTime) => {
const dismissTime =
autoDismissTime && !Number.isNaN(Number(autoDismissTime))
? Number(autoDismissTime)
: 2500
console.log('setting dismiss time: ', dismissTime)
hideToastTimeout = setTimeout(function () {
console.log('hiding toast timeout')
if (!doNotHide) {
currentToastEl.remove()
currentToastEl = undefined
}
}, dismissTime)
}
getStorageItem('autoDismissTime')
.then((autoDismissTime) => {
handleAutoDismiss(autoDismissTime)
})
.catch(() => {
handleAutoDismiss('2500')
})
getStorageItem('disableAutoDismiss').then((disable) => {
console.log('got disableAutoDismiss', disable)
if (disable) {

View File

@ -49,6 +49,21 @@ function autoDismissChanged(event) {
})
}
function saveAutoDismissTime() {
const value = document.getElementById('auto-dismiss-time').value
if (value.length < 1 || Number.isNaN(Number(value))) {
alert('Invalid value')
return
}
setStorage({
autoDismissTime: value,
}).then(() => {
console.log('autoDismissTime updated', value)
})
}
;(() => {
document
.getElementById('save-api-key-btn')
@ -61,7 +76,6 @@ function autoDismissChanged(event) {
.addEventListener('click', clearAPIKey)
getStorageItem('disableAutoDismiss').then((value) => {
console.log('disableAutoDismiss updated', value)
document.getElementById('disable-auto-dismiss').checked = value
? true
: false
@ -70,4 +84,11 @@ function autoDismissChanged(event) {
document
.getElementById('disable-auto-dismiss')
.addEventListener('change', autoDismissChanged)
getStorageItem('autoDismissTime').then((value) => {
document.getElementById('auto-dismiss-time').value = value ?? '2500'
})
document
.getElementById('auto-dismiss-time-btn')
.addEventListener('click', saveAutoDismissTime)
})()

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>API Key Storage</title>
<title>Omnivore Extension Settings</title>
<script src="/scripts/common.js"></script>
</head>
@ -35,8 +35,16 @@
<h1>Settings</h1>
<input type="checkbox" id="disable-auto-dismiss" />
<label for="auto-dismiss">Disable Auto Dismiss</label>
<p>
<input type="checkbox" id="disable-auto-dismiss" />
<label for="auto-dismiss">Disable Auto Dismiss</label>
</p>
<p>
<label for="auto-dismiss-time">Auto Dismiss time (ms)</label>
<input type="text" id="auto-dismiss-time" />
<button id="auto-dismiss-time-btn">Save</button>
</p>
</div>
<script src="/scripts/options.js"></script>