mirror of
https://github.com/Dasemu/X-GeoBlock.git
synced 2026-11-26 23:36:11 +00:00
feat: add cross-browser X GeoBlock extension
This commit is contained in:
commit
0944faab3e
26 files changed
+803
No files matched your search
@@ -0,0 +1,43 @@
|
||||
(function (root) {
|
||||
"use strict";
|
||||
|
||||
const DEFAULT_SETTINGS = Object.freeze({
|
||||
enabled: true,
|
||||
blacklist: ["Belarus", "China", "Iran", "North Korea", "Russia"],
|
||||
cacheTtlHours: 168,
|
||||
showPlaceholder: false
|
||||
});
|
||||
|
||||
const COUNTRY_ALIASES = Object.freeze({
|
||||
"russian federation": "russia",
|
||||
"people's republic of china": "china",
|
||||
"iran, islamic republic of": "iran",
|
||||
"democratic people's republic of korea": "north korea",
|
||||
"dprk": "north korea",
|
||||
"republic of korea": "south korea",
|
||||
"united states of america": "united states",
|
||||
"usa": "united states",
|
||||
"uk": "united kingdom"
|
||||
});
|
||||
|
||||
function normalizeCountry(value) {
|
||||
const normalized = String(value || "")
|
||||
.normalize("NFKD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.trim()
|
||||
.replace(/\s+/g, " ")
|
||||
.toLowerCase();
|
||||
return COUNTRY_ALIASES[normalized] || normalized;
|
||||
}
|
||||
|
||||
function isBlacklisted(country, blacklist) {
|
||||
const candidate = normalizeCountry(country);
|
||||
return Boolean(candidate) && (blacklist || []).some(
|
||||
(entry) => normalizeCountry(entry) === candidate
|
||||
);
|
||||
}
|
||||
|
||||
const api = { DEFAULT_SETTINGS, normalizeCountry, isBlacklisted };
|
||||
root.XGeoConfig = api;
|
||||
if (typeof module !== "undefined") module.exports = api;
|
||||
})(typeof globalThis !== "undefined" ? globalThis : this);
|
||||
Reference in new issue
Block a user