Skip to content

Commit

Permalink
chore: more styling, js and html structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Apr 19, 2023
1 parent 8a6f528 commit 4753840
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 29 deletions.
35 changes: 14 additions & 21 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark light" />
<link rel="stylesheet" href="/styles/options.css" />
<!--<script src="" type="module"></script>-->
<script src="/options/options.ts" type="module"></script>
<title>Replace Maps Options</title>
</head>
<body>
<form action="">
<input
type="text"
pattern="^\S+\.[^\s\.]+$"
placeholder="Hostname following the schema: ((sub.)sub.)domain.tld"
name="hostname"
id="hostname"
required />
<input type="submit" value="Disable" />
</form>
<div id="table">
<div>
<p>a</p>
<p>b</p>
</div>
<div>b</div>
<div>c</div>
<div>d</div>
<div>e</div>
</div>
<section class="form">
<form action="">
<input
type="text"
pattern="^\S+\.[^\s\.]+$"
placeholder="Hostname following the schema: (sub.)domain.tld"
name="hostname"
id="hostname"
required />
<input type="submit" value="Disable" />
</form>
</section>
<section class="table"></section>
</body>
</html>
21 changes: 21 additions & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { disabledHosts, invertHostState } from '../bg/utils/storage';

const table = document.querySelector('.table');

function tableEntries() {
const tableItems: HTMLDivElement[] = disabledHosts.map(createEntry);
tableItems.forEach((div) => table?.insertAdjacentElement('beforeend', div));
}

function createEntry(entryText: string, index: number): HTMLDivElement {
const div = document.createElement('div');
div.innerHTML = `<span>${entryText}</span><button onclick="removeEntry(${index})"></button>`;
return div;
}

// TODO: function shouldn't be removed (because 'unused')
function removeEntry(index: number) {
invertHostState(disabledHosts[index]).then(() => document.location.reload());
}

tableEntries();
32 changes: 24 additions & 8 deletions src/styles/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ body {
--text: black;
--bg: white;

--table-even: lightgrey;
--table-odd: lightslategrey;
--table-even: #e3e2eb;
--table-odd: #c3c2cb;
}

@media (prefers-color-scheme: dark) {
:root {
--text: #ccc;
--bg: #1c1b22;

--table-even: grey;
--table-odd: slategrey;
--table-even: #53525b;
--table-odd: #33323b;
}
}

Expand All @@ -32,13 +32,13 @@ body {
gap: 0.5rem;
}

body > * {
body > section {
padding: 0.5rem;
gap: 0.25rem;
display: grid;
}

#table > * {
.table > * {
display: flex;
align-items: center;
justify-content: space-between;
Expand All @@ -47,14 +47,30 @@ body > * {
padding: 0.5rem 1rem;
}

#table > :nth-child(even) {
.table > :nth-child(even) {
background-color: var(--table-even);
}

#table > :nth-child(odd) {
.table > :nth-child(odd) {
background-color: var(--table-odd);
}

.table button {
width: 2rem;
height: 2rem;
}

.table button::before {
content: 'rm';
}

.form {
position: sticky;
top: 0;
background-color: var(--bg);
box-shadow: var(--text) 0 0 0.25rem;
}

form {
display: flex;
box-sizing: border-box;
Expand Down

0 comments on commit 4753840

Please sign in to comment.