mirror of
https://github.com/Dasemu/X-GeoBlock.git
synced 2026-11-26 23:36:11 +00:00
feat: add location picker and persistent cache
This commit is contained in:
1 parent
fcea6cf7b7
commit
3811ae9cfc
16 files changed
+163
-39
No files matched your search
+6
-3
@@ -1,9 +1,12 @@
|
||||
:root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; }
|
||||
body { margin: 0; background: #0f1419; color: #e7e9ea; }
|
||||
main { max-width: 650px; margin: 48px auto; padding: 0 24px; }
|
||||
h1 { font-size: 32px; margin-bottom: 4px; }.lead,.hint { color: #8b98a5; }.hint { margin: -8px 0 8px; font-size: 14px; }
|
||||
label:not(.check) { display: block; margin: 24px 0 8px; font-weight: 700; }
|
||||
textarea,input[type=number] { box-sizing: border-box; width: 100%; border: 1px solid #536471; border-radius: 8px; background: #000; color: inherit; padding: 12px; font: inherit; }
|
||||
.brand { display:flex; align-items:center; gap:16px; }.brand img { width:64px; height:64px; object-fit:contain; flex:0 0 auto; }h1 { font-size: 32px; margin:0 0 4px; }.lead,.hint { color: #8b98a5; }.lead { margin:0; }.hint { margin: 6px 0 8px; font-size: 14px; }
|
||||
fieldset { border: 0; padding: 0; margin: 28px 0 0; } legend { font-size: 18px; font-weight: 700; padding: 0; }
|
||||
input[type=search] { box-sizing: border-box; flex: 1; min-width: 180px; border: 1px solid #536471; border-radius: 999px; background: #000; color: inherit; padding: 10px 14px; font: inherit; }
|
||||
.check { display: block; margin: 22px 0; }.check input { margin-right: 8px; }.actions { display: flex; gap: 12px; margin-top: 28px; }
|
||||
button { border: 0; border-radius: 999px; background: #1d9bf0; color: #fff; padding: 10px 18px; font-weight: 700; cursor: pointer; }
|
||||
button.secondary { background: transparent; border: 1px solid #536471; }#status { min-height: 24px; color: #00ba7c; }
|
||||
.country-tools { display: flex; gap: 12px; align-items: center; margin: 14px 0 8px; }.link-button { background: transparent; color: #1d9bf0; padding: 8px; white-space: nowrap; }
|
||||
.selection-count { color: #8b98a5; margin: 8px 0; font-size: 14px; }.country-list { display: grid; grid-template-columns: repeat(auto-fill,minmax(190px,1fr)); gap: 6px; max-height: 430px; overflow: auto; border: 1px solid #2f3336; border-radius: 12px; padding: 10px; background: #000; }
|
||||
.country-option { display: flex; align-items: center; gap: 9px; padding: 7px 8px; margin: 0; border-radius: 8px; cursor: pointer; }.country-option:hover { background: #16181c; }.country-option[hidden] { display: none; }.country-flag { font-size: 20px; line-height: 1; }.country-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
@@ -1,15 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>X GeoBlock settings</title><link rel="stylesheet" href="options.css"></head>
|
||||
<body><main>
|
||||
<h1>X GeoBlock</h1><p class="lead">Hide posts based on the country shown in an account's About page.</p>
|
||||
<div class="brand"><img src="../icons/icon.png" alt=""><div><h1>X GeoBlock</h1><p class="lead">Hide posts based on the country shown in an account's About page.</p></div></div>
|
||||
<form id="settings">
|
||||
<label class="check"><input id="enabled" type="checkbox"> Enable filtering</label>
|
||||
<label for="blacklist">Blocked countries</label>
|
||||
<p class="hint">Enter one country per line, exactly as X displays it.</p>
|
||||
<textarea id="blacklist" rows="10" spellcheck="false"></textarea>
|
||||
<label for="ttl">Cache duration (hours)</label><input id="ttl" type="number" min="1" max="8760">
|
||||
<fieldset>
|
||||
<legend>Blocked countries and regions</legend>
|
||||
<p class="hint">X may show a country such as “United Kingdom” or a broader region such as “West Asia”. Nothing is blocked by default.</p>
|
||||
<div class="country-tools"><input id="country-search" type="search" placeholder="Search countries and regions…" autocomplete="off"><button type="button" class="link-button" id="clear-selection">Clear selection</button></div>
|
||||
<p id="selection-count" class="selection-count"></p>
|
||||
<div id="country-list" class="country-list"></div>
|
||||
</fieldset>
|
||||
<label class="check"><input id="placeholder" type="checkbox"> Show a clickable placeholder for hidden posts</label>
|
||||
<div class="actions"><button type="submit">Save settings</button><button type="button" class="secondary" id="clear">Clear user cache</button></div>
|
||||
<p id="status" role="status"></p>
|
||||
</form>
|
||||
</main><script src="../lib/config.js"></script><script src="options.js"></script></body></html>
|
||||
</main><script src="../lib/config.js"></script><script src="../lib/countries.js"></script><script src="options.js"></script></body></html>
|
||||
+52
-6
@@ -2,25 +2,71 @@
|
||||
const extensionApi = globalThis.browser || chrome;
|
||||
const form = document.querySelector("#settings");
|
||||
const enabled = document.querySelector("#enabled");
|
||||
const blacklist = document.querySelector("#blacklist");
|
||||
const ttl = document.querySelector("#ttl");
|
||||
const placeholder = document.querySelector("#placeholder");
|
||||
const status = document.querySelector("#status");
|
||||
const countryList = document.querySelector("#country-list");
|
||||
const countrySearch = document.querySelector("#country-search");
|
||||
const selectionCount = document.querySelector("#selection-count");
|
||||
|
||||
renderCountries();
|
||||
|
||||
load();
|
||||
async function load() {
|
||||
const value = await extensionApi.storage.sync.get(XGeoConfig.DEFAULT_SETTINGS);
|
||||
enabled.checked = value.enabled;
|
||||
blacklist.value = value.blacklist.join("\n");
|
||||
ttl.value = value.cacheTtlHours;
|
||||
placeholder.checked = value.showPlaceholder;
|
||||
const selected = new Set(value.blacklist.map(XGeoConfig.normalizeCountry));
|
||||
countryList.querySelectorAll("input").forEach((input) => {
|
||||
input.checked = selected.has(XGeoConfig.normalizeCountry(input.value));
|
||||
});
|
||||
updateSelectionCount();
|
||||
}
|
||||
|
||||
function renderCountries() {
|
||||
const fragment = document.createDocumentFragment();
|
||||
for (const country of XGeoCountries.LOCATIONS) {
|
||||
const label = document.createElement("label");
|
||||
label.className = "country-option";
|
||||
label.dataset.search = `${country.name} ${country.code}`.toLowerCase();
|
||||
const input = document.createElement("input");
|
||||
input.type = "checkbox";
|
||||
input.value = country.name;
|
||||
const flag = document.createElement("span");
|
||||
flag.className = "country-flag";
|
||||
flag.textContent = country.flag;
|
||||
flag.setAttribute("aria-hidden", "true");
|
||||
const name = document.createElement("span");
|
||||
name.className = "country-name";
|
||||
name.textContent = country.name;
|
||||
label.append(input, flag, name);
|
||||
fragment.append(label);
|
||||
}
|
||||
countryList.append(fragment);
|
||||
countryList.addEventListener("change", updateSelectionCount);
|
||||
}
|
||||
|
||||
function updateSelectionCount() {
|
||||
const count = countryList.querySelectorAll("input:checked").length;
|
||||
selectionCount.textContent = `${count} ${count === 1 ? "location" : "locations"} selected`;
|
||||
}
|
||||
|
||||
countrySearch.addEventListener("input", () => {
|
||||
const query = countrySearch.value.trim().toLowerCase();
|
||||
countryList.querySelectorAll(".country-option").forEach((option) => {
|
||||
option.hidden = Boolean(query) && !option.dataset.search.includes(query);
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector("#clear-selection").addEventListener("click", () => {
|
||||
countryList.querySelectorAll("input:checked").forEach((input) => input.checked = false);
|
||||
updateSelectionCount();
|
||||
});
|
||||
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
await extensionApi.storage.sync.set({
|
||||
enabled: enabled.checked,
|
||||
blacklist: Array.from(new Set(blacklist.value.split(/\r?\n/).map((value) => value.trim()).filter(Boolean))),
|
||||
cacheTtlHours: Math.max(1, Number(ttl.value) || 168),
|
||||
blacklist: Array.from(countryList.querySelectorAll("input:checked"), (input) => input.value),
|
||||
showPlaceholder: placeholder.checked
|
||||
});
|
||||
status.textContent = "Settings saved.";
|
||||
|
||||
Reference in new issue
Block a user