mirror of
https://github.com/Dasemu/X-GeoBlock.git
synced 2026-11-27 15:56:31 +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,10 +6,10 @@ X GeoBlock is a Manifest V3 browser extension for Chromium and Firefox. While yo
|
|||||||
|
|
||||||
- Processes posts already on the page and posts loaded by infinite scrolling.
|
- Processes posts already on the page and posts loaded by infinite scrolling.
|
||||||
- Performs authenticated About-page requests in the extension service worker.
|
- Performs authenticated About-page requests in the extension service worker.
|
||||||
- Caches account results locally for a configurable period (seven days by default).
|
- Caches account results locally without expiration until you clear the cache.
|
||||||
- Coalesces duplicate lookups and spaces network requests to reduce load on X.
|
- Coalesces duplicate lookups and spaces network requests to reduce load on X.
|
||||||
- Skips followed accounts.
|
- Skips followed accounts.
|
||||||
- Provides a configurable country blacklist, an enable switch, and optional hidden-post placeholders.
|
- Provides a searchable country and region checklist with flags, an enable switch, and optional hidden-post placeholders.
|
||||||
- Stores all settings and lookup results in browser extension storage. No data is sent to third parties.
|
- Stores all settings and lookup results in browser extension storage. No data is sent to third parties.
|
||||||
|
|
||||||
## Install from source in Chromium
|
## Install from source in Chromium
|
||||||
@@ -18,7 +18,7 @@ X GeoBlock is a Manifest V3 browser extension for Chromium and Firefox. While yo
|
|||||||
2. Enable **Developer mode**.
|
2. Enable **Developer mode**.
|
||||||
3. Select **Load unpacked** and choose this repository directory.
|
3. Select **Load unpacked** and choose this repository directory.
|
||||||
4. Sign in to `https://x.com` and browse normally.
|
4. Sign in to `https://x.com` and browse normally.
|
||||||
5. Open the extension settings to review the default blacklist.
|
5. Open the extension settings and select the countries you want to block. No country is selected by default.
|
||||||
|
|
||||||
No build step or dependency installation is required.
|
No build step or dependency installation is required.
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ After editing a file, reload the extension and refresh the X tab. See [Architect
|
|||||||
|
|
||||||
X does not publish a stable API for the country shown on the About page. The extension parses X's HTML and embedded page data, so a markup change can temporarily prevent detection. An unknown country leaves the post visible. Requests use your existing X session and are subject to X's rate limits.
|
X does not publish a stable API for the country shown on the About page. The extension parses X's HTML and embedded page data, so a markup change can temporarily prevent detection. An unknown country leaves the post visible. Requests use your existing X session and are subject to X's rate limits.
|
||||||
|
|
||||||
The default blacklist is an editable starting point: Belarus, China, Iran, North Korea, and Russia. Inclusion is a local user preference and does not assert anything about individual account holders.
|
The location picker contains the ISO 3166-1 countries, plus Kosovo, using English CLDR display names. It also includes the broader English region labels exposed by X, such as `West Asia`, alongside country labels such as `United Kingdom`. Inclusion is a local user preference and does not assert anything about individual account holders.
|
||||||
|
|
||||||
## Permissions
|
## Permissions
|
||||||
|
|
||||||
|
|||||||
+1
-10
@@ -45,14 +45,12 @@ async function lookupUserInternal(username, key) {
|
|||||||
const stored = await extensionApi.storage.local.get(CACHE_KEY);
|
const stored = await extensionApi.storage.local.get(CACHE_KEY);
|
||||||
const cache = stored[CACHE_KEY] || {};
|
const cache = stored[CACHE_KEY] || {};
|
||||||
const cached = cache[key];
|
const cached = cache[key];
|
||||||
const ttl = Math.max(1, Number(settings.cacheTtlHours) || 168) * 60 * 60 * 1000;
|
if (cached) {
|
||||||
if (cached && Date.now() - cached.checkedAt < ttl) {
|
|
||||||
return decision(cached, settings, true);
|
return decision(cached, settings, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await enqueue(() => fetchAbout(username));
|
const result = await enqueue(() => fetchAbout(username));
|
||||||
cache[key] = { ...result, checkedAt: Date.now() };
|
cache[key] = { ...result, checkedAt: Date.now() };
|
||||||
pruneCache(cache);
|
|
||||||
await extensionApi.storage.local.set({ [CACHE_KEY]: cache });
|
await extensionApi.storage.local.set({ [CACHE_KEY]: cache });
|
||||||
return decision(cache[key], settings, false);
|
return decision(cache[key], settings, false);
|
||||||
}
|
}
|
||||||
@@ -105,10 +103,3 @@ async function ensureOffscreenDocument() {
|
|||||||
justification: "Parse the account About page without opening a visible tab."
|
justification: "Parse the account About page without opening a visible tab."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function pruneCache(cache) {
|
|
||||||
const entries = Object.entries(cache);
|
|
||||||
if (entries.length <= 2000) return;
|
|
||||||
entries.sort((a, b) => (b[1].checkedAt || 0) - (a[1].checkedAt || 0));
|
|
||||||
for (const [key] of entries.slice(1500)) delete cache[key];
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
5. The worker caches the result and compares the country with the configured blacklist.
|
5. The worker caches the result and compares the country with the configured blacklist.
|
||||||
6. The content script hides the post only when the country matches and the account is not followed.
|
6. The content script hides the post only when the country matches and the account is not followed.
|
||||||
|
|
||||||
Failed or ambiguous lookups fail open: the post remains visible. The cache is limited to 2,000 entries and pruned to the 1,500 most recently checked entries when the limit is exceeded.
|
Failed or ambiguous lookups fail open: the post remains visible. Successful lookups remain cached without expiration. The user can clear the entire cache from the settings page if X changes an account's country or following relationship.
|
||||||
|
|
||||||
## Browser components
|
## Browser components
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
X GeoBlock does not collect analytics, transmit browsing data to third parties, or operate a remote server.
|
X GeoBlock does not collect analytics, transmit browsing data to third parties, or operate a remote server.
|
||||||
|
|
||||||
The extension reads public account About pages from `x.com` using the X session already present in your browser. It stores usernames, detected countries, following status, and lookup timestamps in local extension storage. Settings use synchronized extension storage when browser sync is enabled. You can clear the lookup cache at any time from the settings page or remove all extension data by uninstalling the extension.
|
The extension reads public account About pages from `x.com` using the X session already present in your browser. It stores usernames, detected countries, following status, and lookup timestamps in local extension storage without automatic expiration. Settings use synchronized extension storage when browser sync is enabled. You can clear the lookup cache at any time from the settings page or remove all extension data by uninstalling the extension.
|
||||||
|
|
||||||
The extension reads post author links in X timelines only to decide whether to display those posts. It does not read or store post text.
|
The extension reads post author links in X timelines only to decide whether to display those posts. It does not read or store post text.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 861 KiB |
+15
-3
@@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
const DEFAULT_SETTINGS = Object.freeze({
|
const DEFAULT_SETTINGS = Object.freeze({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
blacklist: ["Belarus", "China", "Iran", "North Korea", "Russia"],
|
blacklist: [],
|
||||||
cacheTtlHours: 168,
|
|
||||||
showPlaceholder: false
|
showPlaceholder: false
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -16,8 +15,21 @@
|
|||||||
"dprk": "north korea",
|
"dprk": "north korea",
|
||||||
"republic of korea": "south korea",
|
"republic of korea": "south korea",
|
||||||
"united states of america": "united states",
|
"united states of america": "united states",
|
||||||
|
"u.s.": "united states",
|
||||||
"usa": "united states",
|
"usa": "united states",
|
||||||
"uk": "united kingdom"
|
"uk": "united kingdom",
|
||||||
|
"viet nam": "vietnam",
|
||||||
|
"bolivia, plurinational state of": "bolivia",
|
||||||
|
"venezuela, bolivarian republic of": "venezuela",
|
||||||
|
"tanzania, united republic of": "tanzania",
|
||||||
|
"syrian arab republic": "syria",
|
||||||
|
"lao people's democratic republic": "laos",
|
||||||
|
"moldova, republic of": "moldova",
|
||||||
|
"brunei darussalam": "brunei",
|
||||||
|
"czechia": "czech republic",
|
||||||
|
"turkiye": "turkey",
|
||||||
|
"cote d’ivoire": "ivory coast",
|
||||||
|
"cote d'ivoire": "ivory coast"
|
||||||
});
|
});
|
||||||
|
|
||||||
function normalizeCountry(value) {
|
function normalizeCountry(value) {
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
(function (root) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// ISO 3166-1 alpha-2, plus XK for Kosovo (commonly exposed by CLDR services).
|
||||||
|
const REGION_CODES = (`
|
||||||
|
AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ
|
||||||
|
BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ
|
||||||
|
CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ
|
||||||
|
DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR
|
||||||
|
GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY
|
||||||
|
HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP
|
||||||
|
KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY
|
||||||
|
MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ
|
||||||
|
NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY
|
||||||
|
QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ
|
||||||
|
TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ
|
||||||
|
VA VC VE VG VI VN VU WF WS XK YE YT ZA ZM ZW
|
||||||
|
`).trim().split(/\s+/);
|
||||||
|
|
||||||
|
const displayNames = new Intl.DisplayNames(["en"], { type: "region" });
|
||||||
|
|
||||||
|
// X sometimes exposes a broad region instead of an ISO country. Keep these
|
||||||
|
// labels verbatim because they are compared with the About-page value.
|
||||||
|
const X_REGIONS = Object.freeze([
|
||||||
|
["Caribbean", "🌎"], ["Central Africa", "🌍"], ["Central America", "🌎"],
|
||||||
|
["Central Asia", "🌏"], ["East Africa", "🌍"], ["East Asia", "🌏"],
|
||||||
|
["Eastern Europe", "🌍"], ["North Africa", "🌍"], ["North America", "🌎"],
|
||||||
|
["Northern Europe", "🌍"], ["Oceania", "🌏"], ["South America", "🌎"],
|
||||||
|
["South Asia", "🌏"], ["Southeast Asia", "🌏"], ["Southern Africa", "🌍"],
|
||||||
|
["Southern Europe", "🌍"], ["West Africa", "🌍"], ["West Asia", "🌏"],
|
||||||
|
["Western Europe", "🌍"]
|
||||||
|
].map(([name, flag]) => Object.freeze({ code: `X-${name}`, name, flag, type: "region" })));
|
||||||
|
|
||||||
|
function countryName(code) {
|
||||||
|
return displayNames.of(code) || code;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countryFlag(code) {
|
||||||
|
if (!/^[A-Z]{2}$/.test(code)) return "🌐";
|
||||||
|
return String.fromCodePoint(...code.split("").map((letter) => 127397 + letter.charCodeAt(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
const COUNTRIES = Object.freeze(REGION_CODES
|
||||||
|
.map((code) => Object.freeze({ code, name: countryName(code), flag: countryFlag(code), type: "country" }))
|
||||||
|
.sort((a, b) => a.name.localeCompare(b.name, "en")));
|
||||||
|
const LOCATIONS = Object.freeze([...X_REGIONS, ...COUNTRIES]);
|
||||||
|
|
||||||
|
const api = { REGION_CODES, X_REGIONS, COUNTRIES, LOCATIONS, countryName, countryFlag };
|
||||||
|
root.XGeoCountries = api;
|
||||||
|
if (typeof module !== "undefined") module.exports = api;
|
||||||
|
})(typeof globalThis !== "undefined" ? globalThis : this);
|
||||||
+11
-1
@@ -3,6 +3,12 @@
|
|||||||
"name": "X GeoBlock",
|
"name": "X GeoBlock",
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"description": "Hide posts from X accounts based in countries you choose.",
|
"description": "Hide posts from X accounts based in countries you choose.",
|
||||||
|
"icons": {
|
||||||
|
"16": "icons/icon.png",
|
||||||
|
"32": "icons/icon.png",
|
||||||
|
"48": "icons/icon.png",
|
||||||
|
"128": "icons/icon.png"
|
||||||
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage",
|
"storage",
|
||||||
"offscreen"
|
"offscreen"
|
||||||
@@ -30,7 +36,11 @@
|
|||||||
"options_page": "options/options.html",
|
"options_page": "options/options.html",
|
||||||
"action": {
|
"action": {
|
||||||
"default_title": "X GeoBlock",
|
"default_title": "X GeoBlock",
|
||||||
"default_popup": "popup/popup.html"
|
"default_popup": "popup/popup.html",
|
||||||
|
"default_icon": {
|
||||||
|
"16": "icons/icon.png",
|
||||||
|
"32": "icons/icon.png"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"web_accessible_resources": [],
|
"web_accessible_resources": [],
|
||||||
"minimum_chrome_version": "109"
|
"minimum_chrome_version": "109"
|
||||||
|
|||||||
+6
-3
@@ -1,9 +1,12 @@
|
|||||||
:root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; }
|
:root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; }
|
||||||
body { margin: 0; background: #0f1419; color: #e7e9ea; }
|
body { margin: 0; background: #0f1419; color: #e7e9ea; }
|
||||||
main { max-width: 650px; margin: 48px auto; padding: 0 24px; }
|
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; }
|
.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; }
|
||||||
label:not(.check) { display: block; margin: 24px 0 8px; font-weight: 700; }
|
fieldset { border: 0; padding: 0; margin: 28px 0 0; } legend { font-size: 18px; font-weight: 700; padding: 0; }
|
||||||
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; }
|
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; }
|
.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 { 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; }
|
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>
|
<!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>
|
<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>
|
<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">
|
<form id="settings">
|
||||||
<label class="check"><input id="enabled" type="checkbox"> Enable filtering</label>
|
<label class="check"><input id="enabled" type="checkbox"> Enable filtering</label>
|
||||||
<label for="blacklist">Blocked countries</label>
|
<fieldset>
|
||||||
<p class="hint">Enter one country per line, exactly as X displays it.</p>
|
<legend>Blocked countries and regions</legend>
|
||||||
<textarea id="blacklist" rows="10" spellcheck="false"></textarea>
|
<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>
|
||||||
<label for="ttl">Cache duration (hours)</label><input id="ttl" type="number" min="1" max="8760">
|
<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>
|
<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>
|
<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>
|
<p id="status" role="status"></p>
|
||||||
</form>
|
</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 extensionApi = globalThis.browser || chrome;
|
||||||
const form = document.querySelector("#settings");
|
const form = document.querySelector("#settings");
|
||||||
const enabled = document.querySelector("#enabled");
|
const enabled = document.querySelector("#enabled");
|
||||||
const blacklist = document.querySelector("#blacklist");
|
|
||||||
const ttl = document.querySelector("#ttl");
|
|
||||||
const placeholder = document.querySelector("#placeholder");
|
const placeholder = document.querySelector("#placeholder");
|
||||||
const status = document.querySelector("#status");
|
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();
|
load();
|
||||||
async function load() {
|
async function load() {
|
||||||
const value = await extensionApi.storage.sync.get(XGeoConfig.DEFAULT_SETTINGS);
|
const value = await extensionApi.storage.sync.get(XGeoConfig.DEFAULT_SETTINGS);
|
||||||
enabled.checked = value.enabled;
|
enabled.checked = value.enabled;
|
||||||
blacklist.value = value.blacklist.join("\n");
|
|
||||||
ttl.value = value.cacheTtlHours;
|
|
||||||
placeholder.checked = value.showPlaceholder;
|
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) => {
|
form.addEventListener("submit", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
await extensionApi.storage.sync.set({
|
await extensionApi.storage.sync.set({
|
||||||
enabled: enabled.checked,
|
enabled: enabled.checked,
|
||||||
blacklist: Array.from(new Set(blacklist.value.split(/\r?\n/).map((value) => value.trim()).filter(Boolean))),
|
blacklist: Array.from(countryList.querySelectorAll("input:checked"), (input) => input.value),
|
||||||
cacheTtlHours: Math.max(1, Number(ttl.value) || 168),
|
|
||||||
showPlaceholder: placeholder.checked
|
showPlaceholder: placeholder.checked
|
||||||
});
|
});
|
||||||
status.textContent = "Settings saved.";
|
status.textContent = "Settings saved.";
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
"description": "Browser extension that hides X posts based on account country.",
|
"description": "Browser extension that hides X posts based on account country.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --test",
|
"test": "node --test",
|
||||||
"check": "node --check background.js && node --check content.js && node --check lib/config.js && node --check lib/parser.js && node --check offscreen/offscreen.js && node --check options/options.js && node --check popup/popup.js && node --check scripts/build.mjs && node --check scripts/bump-version.mjs && node --test",
|
"check": "node --check background.js && node --check content.js && node --check lib/config.js && node --check lib/countries.js && node --check lib/parser.js && node --check offscreen/offscreen.js && node --check options/options.js && node --check popup/popup.js && node --check scripts/build.mjs && node --check scripts/bump-version.mjs && node --test",
|
||||||
"build": "node scripts/build.mjs"
|
"build": "node scripts/build.mjs"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
:root { color-scheme: light dark; font: 14px/1.4 system-ui,sans-serif; } body { margin: 0; min-width: 280px; background: #0f1419; color: #e7e9ea; } main { padding: 18px; } h1 { font-size: 20px; margin: 0 0 16px; } label { display:block; } p { color:#8b98a5; } button { border:0; border-radius:999px; padding:8px 14px; background:#1d9bf0; color:white; font-weight:700; cursor:pointer; }
|
:root { color-scheme: light dark; font: 14px/1.4 system-ui,sans-serif; } body { margin: 0; min-width: 280px; background: #0f1419; color: #e7e9ea; } main { padding: 18px; } .brand { display:flex; align-items:center; gap:10px; margin-bottom:16px; }.brand img { width:36px; height:36px; object-fit:contain; }h1 { font-size: 20px; margin: 0; } label { display:block; } p { color:#8b98a5; } button { border:0; border-radius:999px; padding:8px 14px; background:#1d9bf0; color:white; font-weight:700; cursor:pointer; }
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>X GeoBlock</title><link rel="stylesheet" href="popup.css"></head>
|
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>X GeoBlock</title><link rel="stylesheet" href="popup.css"></head>
|
||||||
<body><main><h1>X GeoBlock</h1><label><input id="enabled" type="checkbox"> Filtering enabled</label><p id="summary"></p><button id="settings">Open settings</button></main><script src="../lib/config.js"></script><script src="popup.js"></script></body></html>
|
<body><main><div class="brand"><img src="../icons/icon.png" alt=""><h1>X GeoBlock</h1></div><label><input id="enabled" type="checkbox"> Filtering enabled</label><p id="summary"></p><button id="settings">Open settings</button></main><script src="../lib/config.js"></script><script src="popup.js"></script></body></html>
|
||||||
+1
-1
@@ -8,7 +8,7 @@ const dist = join(root, "dist");
|
|||||||
const baseManifest = JSON.parse(readFileSync(join(root, "manifest.json"), "utf8"));
|
const baseManifest = JSON.parse(readFileSync(join(root, "manifest.json"), "utf8"));
|
||||||
const version = baseManifest.version;
|
const version = baseManifest.version;
|
||||||
const sharedFiles = [
|
const sharedFiles = [
|
||||||
"background.js", "content.js", "content.css", "lib", "options", "popup"
|
"background.js", "content.js", "content.css", "icons", "lib", "options", "popup"
|
||||||
];
|
];
|
||||||
|
|
||||||
rmSync(dist, { recursive: true, force: true });
|
rmSync(dist, { recursive: true, force: true });
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const test = require("node:test");
|
|||||||
const assert = require("node:assert/strict");
|
const assert = require("node:assert/strict");
|
||||||
const { findUserRecord } = require("../lib/parser.js");
|
const { findUserRecord } = require("../lib/parser.js");
|
||||||
const { normalizeCountry, isBlacklisted } = require("../lib/config.js");
|
const { normalizeCountry, isBlacklisted } = require("../lib/config.js");
|
||||||
|
const { COUNTRIES, LOCATIONS } = require("../lib/countries.js");
|
||||||
|
|
||||||
test("finds following state in nested X user data", () => {
|
test("finds following state in nested X user data", () => {
|
||||||
const source = { data: { user: { result: { legacy: { screen_name: "Alice", following: true, location: "Berlin" } } } } };
|
const source = { data: { user: { result: { legacy: { screen_name: "Alice", following: true, location: "Berlin" } } } } };
|
||||||
@@ -15,3 +16,10 @@ test("normalizes country aliases", () => {
|
|||||||
assert.equal(isBlacklisted("Russian Federation", ["Russia"]), true);
|
assert.equal(isBlacklisted("Russian Federation", ["Russia"]), true);
|
||||||
assert.equal(isBlacklisted("Germany", ["Russia"]), false);
|
assert.equal(isBlacklisted("Germany", ["Russia"]), false);
|
||||||
});
|
});
|
||||||
|
test("offers the full country checklist with unique values", () => {
|
||||||
|
assert.equal(COUNTRIES.length, 250);
|
||||||
|
assert.equal(new Set(COUNTRIES.map((country) => country.code)).size, 250);
|
||||||
|
assert.ok(COUNTRIES.some((country) => country.name === "Germany" && country.flag === "🇩🇪"));
|
||||||
|
assert.ok(LOCATIONS.some((location) => location.name === "West Asia"));
|
||||||
|
assert.ok(LOCATIONS.some((location) => location.name === "United Kingdom" && location.flag === "🇬🇧"));
|
||||||
|
});
|
||||||
Reference in new issue
Block a user