Skip to content

Commit 1f6859e

Browse files
committed
Made Select Services searchable and with iconsk
1 parent 96a11b3 commit 1f6859e

File tree

8 files changed

+152
-62
lines changed

8 files changed

+152
-62
lines changed

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
},
2626
"homepage": "https://libredirect.github.io",
2727
"devDependencies": {
28-
"prettier": "3.3.3",
29-
"pug-cli": "^1.0.0-alpha6",
30-
"web-ext": "^7.2.0",
3128
"@rollup/plugin-commonjs": "^24.0.0",
3229
"@rollup/plugin-node-resolve": "^15.0.0",
3330
"@rollup/plugin-terser": "^0.4.0",
31+
"prettier": "3.3.3",
32+
"pug-cli": "^1.0.0-alpha6",
3433
"rollup": "^3.15.0",
3534
"rollup-plugin-css-only": "^4.3.0",
3635
"rollup-plugin-svelte": "^7.1.2",
37-
"svelte": "^3.55.0"
36+
"svelte": "^3.55.0",
37+
"web-ext": "^7.2.0"
3838
},
3939
"webExt": {
4040
"sourceDir": "./src/",
@@ -44,5 +44,8 @@
4444
"build": {
4545
"overwriteDest": true
4646
}
47+
},
48+
"dependencies": {
49+
"svelte-select": "^5.8.3"
4750
}
4851
}

src/pages/src/App.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
onMount(async () => {
3030
let opts = await utils.getOptions()
3131
if (!opts) {
32-
console.log("init defulats")
3332
await servicesHelper.initDefaults()
3433
opts = await utils.getOptions()
3534
}

src/pages/src/Services/Instances.svelte

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import utils from "../../../assets/javascripts/utils"
1414
1515
export let selectedService
16+
export let selectedFrontend
1617
1718
let _options
1819
let _config
@@ -34,10 +35,10 @@
3435
3536
$: {
3637
allInstances = []
37-
if (_options[serviceOptions.frontend]) allInstances.push(..._options[serviceOptions.frontend])
38-
if (redirects && redirects[serviceOptions.frontend]) {
39-
for (const network in redirects[serviceOptions.frontend]) {
40-
allInstances.push(...redirects[serviceOptions.frontend][network])
38+
if (_options[selectedFrontend]) allInstances.push(..._options[selectedFrontend])
39+
if (redirects && redirects[selectedFrontend]) {
40+
for (const network in redirects[selectedFrontend]) {
41+
allInstances.push(...redirects[selectedFrontend][network])
4142
}
4243
}
4344
}
@@ -48,12 +49,12 @@
4849
}
4950
5051
function isCustomInstance(instance) {
51-
if (redirects[serviceOptions.frontend]) {
52-
for (const network in redirects[serviceOptions.frontend]) {
53-
if (redirects[serviceOptions.frontend][network].includes(instance)) return true
52+
if (redirects[selectedFrontend]) {
53+
for (const network in redirects[selectedFrontend]) {
54+
if (redirects[selectedFrontend][network].includes(instance)) return false
5455
}
5556
}
56-
return false
57+
return true
5758
}
5859
5960
async function pingInstances() {
@@ -92,15 +93,15 @@
9293
let addInstanceValue
9394
function addInstance() {
9495
const instance = utils.protocolHost(new URL(addInstanceValue))
95-
if (!_options[serviceOptions.frontend].includes(instance)) {
96-
_options[serviceOptions.frontend].push(instance)
96+
if (!_options[selectedFrontend].includes(instance)) {
97+
_options[selectedFrontend].push(instance)
9798
addInstanceValue = ""
9899
options.set(_options)
99100
}
100101
}
101102
</script>
102103

103-
{#if serviceConf.frontends[serviceOptions.frontend].instanceList && redirects && blacklist}
104+
{#if serviceConf.frontends[selectedFrontend].instanceList && redirects && blacklist}
104105
<hr />
105106
<div dir="ltr">
106107
<div class="ping">
@@ -120,16 +121,14 @@
120121
type="url"
121122
placeholder="https://instance.com"
122123
aria-label="Add instance input"
123-
on:keydown={e => {
124-
if (e.key === "Enter") addInstance()
125-
}}
124+
on:keydown={e => e.key === "Enter" && addInstance()}
126125
/>
127126
<button on:click={addInstance} class="add" aria-label="Add the instance">
128127
<AddIcon />
129128
</button>
130129
</Row>
131130

132-
{#each _options[serviceOptions.frontend] as instance}
131+
{#each _options[selectedFrontend] as instance}
133132
<Row>
134133
<span>
135134
<a href={instance} target="_blank" rel="noopener noreferrer">{instance}</a>
@@ -144,9 +143,9 @@
144143
class="add"
145144
aria-label="Remove Instance"
146145
on:click={() => {
147-
const index = _options[serviceOptions.frontend].indexOf(instance)
146+
const index = _options[selectedFrontend].indexOf(instance)
148147
if (index > -1) {
149-
_options[serviceOptions.frontend].splice(index, 1)
148+
_options[selectedFrontend].splice(index, 1)
150149
options.set(_options)
151150
}
152151
}}
@@ -156,15 +155,15 @@
156155
</Row>
157156
<hr />
158157
{/each}
159-
<Row></Row>
160158

161159
{#if redirects !== "disabled" && blacklist !== "disabled"}
162-
{#if redirects[serviceOptions.frontend] && redirects[serviceOptions.frontend]["clearnet"]}
160+
{#if redirects[selectedFrontend] && redirects[selectedFrontend]["clearnet"]}
163161
{#each Object.entries(_config.networks) as [networkName, network]}
164-
{#if redirects[serviceOptions.frontend] && redirects[serviceOptions.frontend][networkName]}
162+
{#if redirects[selectedFrontend] && redirects[selectedFrontend][networkName] && redirects[selectedFrontend][networkName].length > 0}
163+
<Row></Row>
165164
<Row><Label>{network.name}</Label></Row>
166165
<hr />
167-
{#each redirects[serviceOptions.frontend][networkName] as instance}
166+
{#each redirects[selectedFrontend][networkName] as instance}
168167
<Row>
169168
<span>
170169
<a href={instance} target="_blank" rel="noopener noreferrer">{instance}</a>
@@ -178,7 +177,7 @@
178177
cloudflare
179178
</a>
180179
{/if}
181-
{#if _options[serviceOptions.frontend].includes(instance)}
180+
{#if _options[selectedFrontend].includes(instance)}
182181
<span style="color:grey">chosen</span>
183182
{/if}
184183
{#if pingCache && pingCache[instance]}
@@ -189,9 +188,9 @@
189188
class="add"
190189
aria-label="Add instance"
191190
on:click={() => {
192-
if (_options[serviceOptions.frontend]) {
193-
if (!_options[serviceOptions.frontend].includes(instance)) {
194-
_options[serviceOptions.frontend].push(instance)
191+
if (_options[selectedFrontend]) {
192+
if (!_options[selectedFrontend].includes(instance)) {
193+
_options[selectedFrontend].push(instance)
195194
options.set(_options)
196195
}
197196
}

src/pages/src/Services/RedirectType.svelte

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,17 @@
4646
}
4747
4848
let embeddableFrontends = []
49-
$: (() => {
50-
if (serviceConf) {
51-
embeddableFrontends = []
52-
for (const [frontendId, frontendConf] of Object.entries(serviceConf.frontends)) {
53-
if (frontendConf.embeddable && frontendConf.instanceList) {
54-
embeddableFrontends.push({
55-
value: frontendId,
56-
name: frontendConf.name,
57-
})
58-
}
49+
$: if (serviceConf) {
50+
embeddableFrontends = []
51+
for (const [frontendId, frontendConf] of Object.entries(serviceConf.frontends)) {
52+
if (frontendConf.embeddable && frontendConf.instanceList) {
53+
embeddableFrontends.push({
54+
value: frontendId,
55+
name: frontendConf.name,
56+
})
5957
}
6058
}
61-
})()
59+
}
6260
</script>
6361

6462
<RowSelect
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script>
2+
import { onDestroy } from "svelte"
3+
export let details
4+
import { config, options } from "../stores"
5+
let _options
6+
let _config
7+
8+
const unsubscribeOptions = options.subscribe(val => (_options = val))
9+
const unsubscribeConfig = config.subscribe(val => (_config = val))
10+
onDestroy(() => {
11+
unsubscribeOptions()
12+
unsubscribeConfig()
13+
})
14+
15+
let theme
16+
$: if (_options) {
17+
if (_options.theme == "dark") {
18+
theme = "dark"
19+
} else if (_options.theme == "light") {
20+
theme = "light"
21+
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
22+
theme = "dark"
23+
} else {
24+
theme = "light"
25+
}
26+
}
27+
</script>
28+
29+
{#if _config.services[details.value].imageType == "svgMono"}
30+
{#if theme == "dark"}
31+
<img src={`/assets/images/${details.value}-icon-light.svg`} alt={details.label} />
32+
{:else}
33+
<img src={`/assets/images/${details.value}-icon.svg`} alt={details.label} />
34+
{/if}
35+
{:else}
36+
<img src={`/assets/images/${details.value}-icon.${_config.services[details.value].imageType}`} alt={details.label} />
37+
{/if}

src/pages/src/Services/Services.svelte

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script>
2-
let browser = window.browser || window.chrome
3-
42
import Checkbox from "../components/RowCheckbox.svelte"
53
import RowSelect from "../components/RowSelect.svelte"
64
import Row from "../components/Row.svelte"
75
import Label from "../components/Label.svelte"
86
import Select from "../components/Select.svelte"
97
import { options, config } from "../stores"
108
import RedirectType from "./RedirectType.svelte"
11-
import { onDestroy, onMount } from "svelte"
9+
import { onDestroy } from "svelte"
1210
import Instances from "./Instances.svelte"
11+
import SvelteSelect from "svelte-select"
12+
import ServiceIcon from "./ServiceIcon.svelte"
1313
1414
let _options
1515
let _config
@@ -22,9 +22,9 @@
2222
})
2323
2424
let selectedService = "youtube"
25-
2625
$: serviceConf = _config.services[selectedService]
2726
$: serviceOptions = _options[selectedService]
27+
$: frontendWebsite = serviceConf.frontends[serviceOptions.frontend].url
2828
</script>
2929

3030
<div>
@@ -33,15 +33,26 @@
3333
Service:
3434
<a href={serviceConf.url} target="_blank" rel="noopener noreferrer">{serviceConf.url}</a>
3535
</Label>
36-
<Select
36+
<SvelteSelect
37+
clearable={false}
38+
class="svelte_select"
3739
value={selectedService}
38-
values={[
39-
...Object.entries(_config.services).map(([serviceId, service]) => {
40-
return { value: serviceId, name: service.name }
40+
on:change={e => (selectedService = e.detail.value)}
41+
items={[
42+
...Object.entries(_config.services).map(([serviceKey, service]) => {
43+
return { value: serviceKey, label: service.name }
4144
}),
4245
]}
43-
onChange={e => (selectedService = e.target.options[e.target.options.selectedIndex].value)}
44-
/>
46+
>
47+
<div class="slot" slot="item" let:item>
48+
<ServiceIcon details={item} />
49+
{item.label}
50+
</div>
51+
<div class="slot" slot="selection" let:selection>
52+
<ServiceIcon details={selection} />
53+
{selection.label}
54+
</div>
55+
</SvelteSelect>
4556
</Row>
4657

4758
<hr />
@@ -73,9 +84,9 @@
7384
<Row>
7485
<Label>
7586
Frontend:
76-
<a href={serviceConf.frontends[serviceOptions.frontend].url} target="_blank" rel="noopener noreferrer"
77-
>{serviceConf.frontends[serviceOptions.frontend].url}</a
78-
>
87+
<a href={frontendWebsite} target="_blank" rel="noopener noreferrer">
88+
{frontendWebsite}
89+
</a>
7990
</Label>
8091
<Select
8192
value={serviceOptions.frontend}
@@ -95,7 +106,7 @@
95106
<RedirectType {selectedService} />
96107

97108
<RowSelect
98-
label="Unsupported iframes handling"
109+
label="Unsupported embeds handling"
99110
value={serviceOptions.unsupportedUrls}
100111
onChange={e => {
101112
serviceOptions.unsupportedUrls = e.target.options[e.target.options.selectedIndex].value
@@ -108,12 +119,55 @@
108119
/>
109120

110121
{#if selectedService == "search"}
111-
<div>
112-
Set LibRedirect as Default Search Engine. For how to do in chromium browsers, click
113-
<a href="https://libredirect.github.io/docs.html#search_engine_chromium">here</a>.
114-
</div>
122+
<Row>
123+
<Label>
124+
Set LibRedirect as Default Search Engine. For how to do in chromium browsers, click
125+
<a
126+
href="https://libredirect.github.io/docs.html#search_engine_chromium"
127+
target="_blank"
128+
rel="noopener noreferrer"
129+
>here
130+
</a>.
131+
</Label>
132+
</Row>
115133
{/if}
116134

117-
<Instances {selectedService} />
135+
<Instances
136+
{selectedService}
137+
selectedFrontend={!serviceConf.frontends[serviceOptions.frontend].desktopApp ||
138+
serviceOptions.redirectType == "main_frame"
139+
? serviceOptions.frontend
140+
: serviceOptions.embedFrontend}
141+
/>
142+
143+
<Row></Row>
118144
</div>
119145
</div>
146+
147+
<style>
148+
:global(.svelte_select) {
149+
font-weight: bold;
150+
--item-padding: 0 10px;
151+
--border: none;
152+
--border-hover: none;
153+
--width: 210px;
154+
--background: var(--bg-secondary);
155+
--list-background: var(--bg-secondary);
156+
--item-active-background: red;
157+
--item-is-active-bg: grey;
158+
--item-hover-bg: grey;
159+
--item-color: var(--text); /*text color*/
160+
}
161+
:global(.svelte_select .slot) {
162+
display: flex;
163+
justify-content: start;
164+
align-items: center;
165+
}
166+
167+
:global(.svelte_select img, .svelte_select svg) {
168+
margin-right: 10px;
169+
height: 26px;
170+
width: 26px;
171+
color: var(--text);
172+
}
173+
</style>

src/pages/src/Sidebar.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</a>
1313
<a href="#services" on:click={() => page.set("services")} style={$page == "services" && "color: var(--active);"}>
1414
<ServicesIcon style="margin-right: 5px" />
15-
<span data-localise="__MSG_general__">Services</span>
15+
<span data-localise="__MSG_services__">Services</span>
1616
</a>
1717
<a href="https://libredirect.github.io" target="_blank" rel="noopener noreferrer">
1818
<AboutIcon style="margin-right: 5px" />

0 commit comments

Comments
 (0)