Skip to content

Commit 7de544b

Browse files
authored
Add Background Option (#49)
* Add Background Option * Add Gallery Keybind
1 parent fb73508 commit 7de544b

File tree

5 files changed

+97
-21
lines changed

5 files changed

+97
-21
lines changed

manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"default": "Alt+Shift+A"
1818
},
1919
"description": "Upload Files"
20+
},
21+
"openGallery": {
22+
"suggested_key": {
23+
"default": "Alt+Shift+G"
24+
},
25+
"description": "Upload Files"
2026
}
2127
},
2228
"permissions": [

src/css/options.css

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/* CSS for options.html */
22

3-
body {
4-
margin: 0;
5-
background: #000;
6-
}
7-
83
video {
94
position: fixed;
105
top: 50%;
@@ -15,16 +10,16 @@ video {
1510
height: auto;
1611
z-index: -100;
1712
transform: translateX(-50%) translateY(-50%);
18-
background: url("../media/loop.jpg") no-repeat;
13+
background: url('../media/loop.jpg') no-repeat;
1914
background-size: cover;
2015
filter: blur(150px);
2116
}
2217

2318
.card {
2419
min-width: 400px;
20+
background: rgba(0 0 0 / 70%);
2521
}
2622

27-
.card,
2823
table tr {
2924
background: rgba(0 0 0 / 30%);
3025
}

src/html/options.html

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</head>
1313
<body class="h-100">
1414

15-
<video poster="../media/loop.jpg" id="bgvid" playsinline autoplay muted loop>
15+
<video poster="../media/loop.jpg" id="bgvid" class="d-none" playsinline autoplay muted loop>
1616
<source src="../media/loop.mp4" type="video/mp4">
1717
</video> <!-- video -->
1818

1919
<div class="container-fluid p-2 h-100">
2020
<div class="d-flex align-items-center h-100">
21-
<div class="col-xxl-8 col-lg-10 col-12 m-auto">
21+
<div class="col-xl-8 col-lg-10 col-12 m-auto">
2222
<div class="card p-2 mb-2">
2323
<div class="card-body">
2424
<div class="d-flex justify-content-center align-items-center">
@@ -69,17 +69,17 @@ <h1>Django Files Options</h1>
6969
</div>
7070

7171
<div class="row g-2">
72-
<div class="col-sm-4 col-12 mb-2">
72+
<div class="col-md-4 col-12 mb-2">
7373
<label for="recentFiles" class="form-label"><i class="fa-solid fa-list-ol me-2"></i> Recent Files</label>
7474
<input id="recentFiles" aria-describedby="recentFilesHelp" type="number" class="form-control" autocomplete="off">
7575
<div class="form-text" id="recentFilesHelp">Popup Recent Files. <span class="d-inline-block">0 to Disable.</span></div>
7676
</div>
77-
<div class="col-sm-4 col-12 mb-2">
77+
<div class="col-md-4 col-12 mb-2">
7878
<label for="popupWidth" class="form-label"><i class="fa-solid fa-arrows-left-right-to-line me-2"></i> Popup Width</label>
7979
<input id="popupWidth" aria-describedby="popupWidthHelp" type="number" class="form-control" autocomplete="off" step="10">
8080
<div class="form-text" id="popupWidthHelp">Popup Width in Pixels. <span class="d-inline-block">320-600.</span></div>
8181
</div>
82-
<div class="col-sm-4 col-12 mb-2">
82+
<div class="col-md-4 col-12 mb-2">
8383
<label for="popupTimeout" class="form-label"><i class="fa-regular fa-clock me-2"></i> Preview Timeout</label>
8484
<input id="popupTimeout" aria-describedby="popupTimeoutHelp" type="number" class="form-control" autocomplete="off">
8585
<div class="form-text" id="popupTimeoutHelp">Popup Preview Timeout in Seconds.</div>
@@ -181,6 +181,35 @@ <h1>Django Files Options</h1>
181181
</label>
182182
</div>
183183
</div>
184+
185+
<h5>
186+
Options Page Background
187+
<span class="small" data-bs-toggle="tooltip" data-bs-title="Disabled, Random Picture or Video Loop.">
188+
<i class="fa-solid fa-circle-info ms-1"></i>
189+
</span>
190+
</h5>
191+
<div id="backgroundOptions" class="ms-3">
192+
<div class="form-check form-check-inline">
193+
<input class="form-check-input" type="radio" name="radioBackground" id="bgNone" value="none">
194+
<label class="form-check-label" for="bgNone">
195+
<i class="fa-regular fa-square"></i> None
196+
</label>
197+
</div>
198+
199+
<div class="form-check form-check-inline">
200+
<input class="form-check-input" type="radio" name="radioBackground" id="bgPicture" value="picture">
201+
<label class="form-check-label" for="bgPicture">
202+
<i class="fa-regular fa-image"></i> Picture
203+
</label>
204+
</div>
205+
<div class="form-check form-check-inline">
206+
<input class="form-check-input" type="radio" name="radioBackground" id="bgVideo" value="video">
207+
<label class="form-check-label" for="bgVideo">
208+
<i class="fa-solid fa-video"></i> Video
209+
</label>
210+
</div>
211+
</div>
212+
184213
</form>
185214

186215
<hr>

src/js/options.js

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async function initOptions() {
3232

3333
const { options } = await chrome.storage.sync.get(['options'])
3434
console.debug('options:', options)
35+
setBackground(options)
3536
updateOptions(options)
3637
if (!options?.siteUrl) {
3738
const siteUrl = document.getElementById('siteUrl')
@@ -48,13 +49,37 @@ async function initOptions() {
4849
*/
4950
function onChanged(changes, namespace) {
5051
// console.debug('onChanged:', changes, namespace)
51-
for (const [key, { newValue }] of Object.entries(changes)) {
52+
for (const [key, { oldValue, newValue }] of Object.entries(changes)) {
5253
if (namespace === 'sync' && key === 'options') {
5354
updateOptions(newValue)
55+
if (oldValue.radioBackground !== newValue.radioBackground) {
56+
setBackground(newValue)
57+
}
5458
}
5559
}
5660
}
5761

62+
function setBackground(options) {
63+
if (options.radioBackground === 'bgPicture') {
64+
console.debug('setBackground:', options)
65+
document.body.style.background =
66+
"url('https://picsum.photos/1920/1080') no-repeat center fixed"
67+
document.body.style.webkitBackgroundSize = 'cover'
68+
document.body.style.mozBackgroundSize = 'cover'
69+
document.body.style.oBackgroundSize = 'cover'
70+
document.body.style.backgroundSize = 'cover'
71+
72+
document.querySelector('video').classList.add('d-none')
73+
} else if (options.radioBackground === 'bgVideo') {
74+
document.querySelector('video').classList.remove('d-none')
75+
76+
document.body.style.cssText = ''
77+
} else {
78+
document.body.style.cssText = ''
79+
document.querySelector('video').classList.add('d-none')
80+
}
81+
}
82+
5883
/**
5984
* Save Options Callback
6085
* @function saveOptions
@@ -63,11 +88,13 @@ function onChanged(changes, namespace) {
6388
async function saveOptions(event) {
6489
// console.debug('saveOptions:', event)
6590
const { options } = await chrome.storage.sync.get(['options'])
91+
let key = event.target.id
92+
let value
6693
if (event.target.type === 'checkbox') {
67-
options[event.target.id] = event.target.checked
94+
value = event.target.checked
6895
} else if (event.target.id === 'siteUrl') {
6996
event.target.value = event.target.value.replace(/\/+$/, '')
70-
options[event.target.id] = event.target.value
97+
value = event.target.value
7198
} else if (event.target.type === 'number') {
7299
const number = parseInt(event.target.value, 10)
73100
let min = 0
@@ -80,18 +107,31 @@ async function saveOptions(event) {
80107
}
81108
if (!isNaN(number) && number >= min && number <= max) {
82109
event.target.value = number.toString()
83-
options[event.target.id] = number
110+
value = number
84111
} else {
85112
event.target.value = options[event.target.id]
86113
// TODO: Add Error Handling
87114
// showToast(`Value ${number} Out of Range for ${event.target.id}`,'warning')
88115
}
116+
} else if (event.target.type === 'radio') {
117+
key = event.target.name
118+
const radios = document.getElementsByName(key)
119+
for (const input of radios) {
120+
if (input.checked) {
121+
value = input.id
122+
break
123+
}
124+
}
89125
} else {
90-
options[event.target.id] = event.target.value
126+
value = event.target.value
127+
}
128+
if (value !== undefined) {
129+
options[key] = value
130+
console.info(`Set: ${key}:`, value)
131+
await chrome.storage.sync.set({ options })
132+
} else {
133+
console.warn('No Value for key:', key)
91134
}
92-
console.info(`Set: "${event.target.id}" to target:`, event.target)
93-
console.debug('options:', options)
94-
await chrome.storage.sync.set({ options })
95135
}
96136

97137
/**
@@ -117,7 +157,7 @@ function updateOptions(options) {
117157
}
118158
if (el.tagName !== 'INPUT') {
119159
el.textContent = value.toString()
120-
} else if (el.type === 'checkbox') {
160+
} else if (['checkbox', 'radio'].includes(el.type)) {
121161
el.checked = value
122162
} else {
123163
el.value = value

src/js/service-worker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async function onInstalled(details) {
4949
deleteConfirm: true,
5050
contextMenu: true,
5151
showUpdate: false,
52+
radioBackground: 'bgPicture',
5253
})
5354
)
5455
console.log('options:', options)
@@ -89,6 +90,11 @@ async function onCommand(command) {
8990
const url = `${options.siteUrl}/uppy/`
9091
await chrome.tabs.create({ active: true, url })
9192
}
93+
} else if (command === 'openGallery') {
94+
if (options.siteUrl) {
95+
const url = `${options.siteUrl}/gallery/`
96+
await chrome.tabs.create({ active: true, url })
97+
}
9298
} else {
9399
console.warn('Unknown Command:', command)
94100
}

0 commit comments

Comments
 (0)