feat: add collaborative Cloudflare cache and debug mode

This commit is contained in:
Darío Sevilla committed 2026-10-15 07:59:10 +00:00
1 parent 7e88fee0c2
commit 067cbfd24c
20 files changed
+695 -31

No files matched your search

+2 -1
View File
@@ -3,10 +3,11 @@ body { margin: 0; background: #0f1419; color: #e7e9ea; }
main { max-width: 650px; margin: 48px auto; padding: 0 24px; }
.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; }
input[type=search],input[type=url] { box-sizing: border-box; flex: 1; width:100%; 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; }
.cloud-settings { border-top:1px solid #2f3336; padding-top:24px; }.cloud-settings label:not(.check) { display:block; margin:14px 0 7px; font-weight:700; }
+10 -1
View File
@@ -12,7 +12,16 @@
<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="debug-mode" type="checkbox"> Enable debug logging in the X page console</label>
<fieldset class="cloud-settings">
<legend>Collaborative cloud cache</legend>
<p class="hint">Optional. Confirmed results reduce requests to X. Deploy the included Cloudflare Worker and enter its HTTPS URL.</p>
<label for="cloud-endpoint">Worker URL</label>
<input id="cloud-endpoint" type="url" placeholder="https://x-geoblock-cache.example.workers.dev" autocomplete="url">
<label class="check"><input id="cloud-contribute" type="checkbox"> Contribute locally observed locations</label>
<p class="hint">Contributions send a SHA-256 hash of the public username and its location. Following relationships, posts, and your blacklist are never uploaded.</p>
</fieldset>
<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="../lib/countries.js"></script><script src="options.js"></script></body></html>
</main><script src="../lib/config.js"></script><script src="../lib/countries.js"></script><script src="../lib/cloud-cache.js"></script><script src="options.js"></script></body></html>
+22 -1
View File
@@ -3,10 +3,13 @@ const extensionApi = globalThis.browser || chrome;
const form = document.querySelector("#settings");
const enabled = document.querySelector("#enabled");
const placeholder = document.querySelector("#placeholder");
const debugMode = document.querySelector("#debug-mode");
const status = document.querySelector("#status");
const countryList = document.querySelector("#country-list");
const countrySearch = document.querySelector("#country-search");
const selectionCount = document.querySelector("#selection-count");
const cloudEndpoint = document.querySelector("#cloud-endpoint");
const cloudContribute = document.querySelector("#cloud-contribute");
renderCountries();
@@ -15,6 +18,9 @@ async function load() {
const value = await extensionApi.storage.sync.get(XGeoConfig.DEFAULT_SETTINGS);
enabled.checked = value.enabled;
placeholder.checked = value.showPlaceholder;
debugMode.checked = value.debugMode === true;
cloudEndpoint.value = value.cloudCacheEndpoint || "";
cloudContribute.checked = value.contributeCloudCache === true;
const selected = new Set(value.blacklist.map(XGeoConfig.normalizeCountry));
countryList.querySelectorAll("input").forEach((input) => {
input.checked = selected.has(XGeoConfig.normalizeCountry(input.value));
@@ -64,10 +70,25 @@ document.querySelector("#clear-selection").addEventListener("click", () => {
form.addEventListener("submit", async (event) => {
event.preventDefault();
const endpoint = XGeoCloud.normalizeEndpoint(cloudEndpoint.value);
if (cloudEndpoint.value.trim() && !endpoint) {
status.textContent = "Enter a valid HTTPS Worker URL.";
return;
}
if (endpoint) {
const granted = await extensionApi.permissions.request({ origins: [`${endpoint}/*`] });
if (!granted) {
status.textContent = "Host permission is required to use the cloud cache.";
return;
}
}
await extensionApi.storage.sync.set({
enabled: enabled.checked,
blacklist: Array.from(countryList.querySelectorAll("input:checked"), (input) => input.value),
showPlaceholder: placeholder.checked
showPlaceholder: placeholder.checked,
debugMode: debugMode.checked,
cloudCacheEndpoint: endpoint,
contributeCloudCache: Boolean(endpoint) && cloudContribute.checked
});
status.textContent = "Settings saved.";
setTimeout(() => status.textContent = "", 2000);