mirror of
https://github.com/NanashiTheNameless/FixTheGulf.git
synced 2025-07-09 16:10:31 -04:00
make the extension work for users not in the us
This commit is contained in:
parent
aaa243d875
commit
1ff479fad6
1 changed files with 26 additions and 6 deletions
32
gulf.js
32
gulf.js
|
@ -53,7 +53,7 @@
|
|||
and then calls out to the original function.
|
||||
*/
|
||||
_[jsonParsingFunctionName] = function(a, b) {
|
||||
a = a.replaceAll('Gulf of America', 'Gulf of Mexico');
|
||||
a = a.replaceAll(' (Gulf of America)', "").replaceAll('Gulf of America', 'Gulf of Mexico')
|
||||
return originalJsonParsingFunction(a, b)
|
||||
}
|
||||
|
||||
|
@ -138,6 +138,8 @@
|
|||
// Constants for special cases
|
||||
const CHAR_CODE_SPACE = " ".charCodeAt(0)
|
||||
const CHAR_CODE_CAPITAL_A = "A".charCodeAt(0)
|
||||
const CHAR_CODE_PARENTH = '('.charCodeAt(0)
|
||||
const CHAR_CODE_CAPITAL_G = 'G'.charCodeAt(0)
|
||||
const REPLACEMENT_BYTES = [..."Mexico\0"].map(char => char.charCodeAt(0))
|
||||
|
||||
// For every possible starting character in our `labelBytes` blob...
|
||||
|
@ -196,11 +198,29 @@
|
|||
// (we can't just add a fixed value because we don't know how long the
|
||||
// match even is, thanks to variable space matching)
|
||||
const americaStartIndex = labelBytes.indexOf(CHAR_CODE_CAPITAL_A, labelByteStartingIndex)
|
||||
|
||||
// Replace "America" with "Mexico\0"
|
||||
for (let i = 0; i < REPLACEMENT_BYTES.length; i++) {
|
||||
labelBytes[americaStartIndex + i] = REPLACEMENT_BYTES[i];
|
||||
}
|
||||
let parenthStartIndex = -1;
|
||||
// Check if the label is `Gulf of Mexico (Gulf of America)`
|
||||
for (let i = 0; i < labelBytes.length; i++) {
|
||||
if (labelBytes[i] == CHAR_CODE_PARENTH && labelBytes[i + 1] == CHAR_CODE_CAPITAL_G) {
|
||||
parenthStartIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if (parenthStartIndex > -1) {
|
||||
// Replace "(Gulf of" with null bytes
|
||||
for (let i = 0; i < 8; i++) {
|
||||
labelBytes[parenthStartIndex + i] = '\0'.charCodeAt(0)
|
||||
}
|
||||
// Replace "America)" with null bytes
|
||||
for (let i = 0; i < 8; i++) {
|
||||
labelBytes[americaStartIndex + i] = '\0'.charCodeAt(0)
|
||||
}
|
||||
} else {
|
||||
// Replace "America" with "Mexico\0"
|
||||
for (let i = 0; i < REPLACEMENT_BYTES.length; i++) {
|
||||
labelBytes[americaStartIndex + i] = REPLACEMENT_BYTES[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue