This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathimage-settings.js
60 lines (45 loc) · 2.13 KB
/
image-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
54
55
56
57
58
59
60
/* globals app document */
const yo = require('yo-yo')
// exported api
// =
module.exports = function renderImageSettings () {
return yo`
<div id="image-settings" class="image-settings-wrap">
<h2>Image settings</h2>
<p>Embedding images creates a more seamless timeline, but enables <a href="https://github.com/beakerbrowser/fritter/issues/10">pixel-tracking</a>. Choose the setting that works best for you:</p>
<form class="image-settings" onsubmit=${onUpdateImageSettings}>
<div class="input-wrap">
<input ${isCurrentSetting('all') ? 'checked' : ''} type="radio" id="choice-all" name="embedImages" value="all">
<label for="choice-all">Embed all images</label>
</div>
<div class="input-wrap">
<input ${isCurrentSetting('dat') ? 'checked' : ''} type="radio" id="choice-dat" name="embedImages" value="dat">
<label for="choice-dat">Embed images from <code>dat://</code> sources</label>
</div>
<div class="input-wrap">
<input ${isCurrentSetting('dat-followed') ? 'checked' : ''} type="radio" id="choice-dat-followed" name="embedImages" value="dat-followed">
<label for="choice-dat-followed">Embed images from <code>dat://</code> sources I follow</label>
</div>
<div class="input-wrap">
<input ${isCurrentSetting('none') ? 'checked' : ''} type="radio" id="choice-none" name="embedImages" value="none">
<label for="choice-none">Don't embed images</label>
</div>
<div class="actions">
<button type="submit" class="btn primary">Save</button>
</div>
</form>
</div>
`
async function onUpdateImageSettings (e) {
e.preventDefault()
// Save new value of settings
const imageSetting = document.querySelector('input[name=embedImages]:checked').value
app.settings.imageEmbed = imageSetting
await app.updateSettings(app.settings)
app.gotoFeed()
}
function isCurrentSetting (val) {
// const settings = JSON.parse(window.localStorage.settings || '{}')
return val === app.settings.imageEmbed || (!app.settings.imageEmbed && val === 'none')
}
}