-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings.js
53 lines (49 loc) · 2.21 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function fetchImage() {
fetch("https://source.unsplash.com/random/3840x2160/?nature")
.then((resp) => resp)
.then((imagelists) => {
let selectedImage = imagelists.url;
let dom = document.getElementById("header");
dom.style.backgroundColor = "grey";
dom.style.backgroundImage = `url(${selectedImage})`;
});
}
fetchImage();
restoreSettings();
// Save the settings to a Chrome extension storage
function saveSettings() {
chrome.storage.sync.set({
language: document.querySelector("select[name='language']").value,
timeformat: document.querySelector("select[name='timeformat']").value,
quoteSource: document.querySelector("input[name='quoteSource']").value,
imageSource: document.querySelector("input[name='imageSource']").value,
imageResolution: document.querySelector("input[name='imageResolution']").value,
imageCategory: document.querySelector("input[name='imageCategory']").value
}, function () {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function () {
status.textContent = '';
}, 750);
});
}
// Get settings from Chrome extension storage
function restoreSettings() {
chrome.storage.sync.get({
language: 'en',
timeformat: '12',
quoteSource: 'https://simonrijntjes.nl/quote.php',
imageSource: 'https://source.unsplash.com/random/',
imageResolution: '3840x2160',
imageCategory: 'Nature'
}, function (items) {
document.querySelector("select[name='language']").value = items.language;
document.querySelector("select[name='timeformat']").value = items.timeformat;
document.querySelector("input[name='quoteSource']").value = items.quoteSource;
document.querySelector("input[name='imageSource']").value = items.imageSource;
document.querySelector("input[name='imageResolution']").value = items.imageResolution;
document.querySelector("input[name='imageCategory']").value = items.imageCategory;
});
}
document.addEventListener('DOMContentLoaded', restoreSettings);