Skip to content

Commit 03059d6

Browse files
authored
🔀 Merge pull request #327 from richardfrost/firefox_mobile_fix
Fix For Older Firefox for Android Versions
2 parents e285de3 + 4c03e95 commit 03059d6

File tree

7 files changed

+71
-8
lines changed

7 files changed

+71
-8
lines changed

bin/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
eventPage: './src/script/eventPage.ts',
44
optionPage: './src/script/optionPage.ts',
55
popup: './src/script/popup.ts',
6+
showErrors: '/src/script/showErrors.ts',
67
webFilter: './src/script/webFilter.ts',
78
},
89
mode: 'production',

src/script/lib/helper.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,31 @@ export function numberToBoolean(value: number): boolean {
124124
}
125125

126126
export function numberWithCommas(number: number | string): string {
127-
return number.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ',');
127+
if (typeof Intl == 'object' && typeof Intl.NumberFormat == 'function') {
128+
if (typeof number === 'string') {
129+
number = parseInt(number).toString();
130+
}
131+
132+
return number.toLocaleString();
133+
} else {
134+
number = number.toString();
135+
136+
// Get numbers before `.` (if present)
137+
const decimalIndex = number.indexOf('.');
138+
let output = decimalIndex === -1 ? number : number.slice(0, decimalIndex);
139+
140+
// Insert commas every 3 digits from the right
141+
for (let i = output.length - 3; i > 0; i -= 3) {
142+
output = output.slice(0, i) + ',' + output.slice(i);
143+
}
144+
145+
// Append fractional part
146+
if (decimalIndex !== -1) {
147+
output += number.slice(decimalIndex);
148+
}
149+
150+
return output;
151+
}
128152
}
129153

130154
export function readFile(file) {

src/script/showErrors.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Show errors (including syntax) on the page
2+
// Requires: <body>...<div id="uncaughtErrors"></div></body>
3+
window.onerror = function(message, source, lineno, colno, error) {
4+
const errorContainer = document.querySelector('BODY > #uncaughtErrors') as HTMLDivElement;
5+
if (errorContainer) {
6+
if (!errorContainer.childElementCount) {
7+
const errorHeader = document.createElement('P');
8+
errorHeader.textContent = 'Errors:';
9+
errorContainer.appendChild(errorHeader);
10+
}
11+
const errorMessage = document.createElement('P');
12+
errorMessage.textContent = message.toString();
13+
errorContainer.appendChild(errorMessage);
14+
} else {
15+
window.alert(message);
16+
}
17+
};

src/static/optionPage.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,12 @@ a#bookmarkletLink:active, a#bookmarkletLink:hover, a#bookmarkletLink:link, a#boo
193193
left: 0;
194194
bottom: 18px
195195
}
196+
197+
/* Uncaught Errors */
198+
#uncaughtErrors P {
199+
color: red;
200+
}
201+
202+
#uncaughtErrors P:first-child {
203+
font-weight: bolder;
204+
}

src/static/optionPage.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,9 @@ <h4 class="sectionHeader">Site Config</h4>
812812
</div>
813813
</div>
814814

815+
<div id="uncaughtErrors"></div>
816+
<script src="showErrors.js"></script>
817+
815818
<script src="optionPage.js"></script>
816819
</body>
817820
</html>

src/static/popup.css

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ a:hover, a:active {
2929
font-size: 10px;
3030
}
3131

32-
p {
33-
margin-right: 35px;
34-
margin-top: 40px;
35-
float: right;
36-
}
37-
3832
h4 {
3933
margin-bottom: 5px;
4034
}
@@ -210,4 +204,15 @@ input:checked + .slider:before {
210204
-moz-user-select: none;
211205
-ms-user-select: none;
212206
user-select: none;
213-
}
207+
}
208+
209+
/* Uncaught Errors */
210+
#uncaughtErrors P {
211+
color: red;
212+
font-size: 12px;
213+
line-height: 1;
214+
}
215+
216+
#uncaughtErrors P:first-child {
217+
font-weight: bolder;
218+
}

src/static/popup.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
- <a href="https://github.com/richardfrost/AdvancedProfanityFilter/releases" target="_blank">Changelog</a>
5454
- <a href="https://github.com/richardfrost/AdvancedProfanityFilter/issues" target="_blank">Support</a>
5555
</div>
56+
57+
<div id="uncaughtErrors"></div>
58+
<script src="showErrors.js"></script>
59+
5660
<script src="popup.js"></script>
5761
</body>
5862
</html>

0 commit comments

Comments
 (0)