Need QSA to be forgiving

This commit is contained in:
Lim Chee Aun 2024-11-20 23:50:58 +08:00
parent deaddcec00
commit 6c3c158f79
2 changed files with 152 additions and 136 deletions

View file

@ -125,6 +125,17 @@ function getPostText(status) {
);
}
function forgivingQSA(selectors = [], dom = document) {
// Run QSA for list of selectors
// If a selector return invalid selector error, try the next one
for (const selector of selectors) {
try {
return dom.querySelectorAll(selector);
} catch (e) {}
}
return [];
}
function isTranslateble(content) {
if (!content) return false;
content = content.trim();
@ -132,8 +143,9 @@ function isTranslateble(content) {
const text = getHTMLText(content, {
preProcess: (dom) => {
// Remove .mention, pre, code, a:has(.invisible)
for (const a of dom.querySelectorAll(
'.mention, pre, code, a:has(.invisible)',
for (const a of forgivingQSA(
['.mention, pre, code, a:has(.invisible)', '.mention, pre, code'],
dom,
)) {
a.remove();
}
@ -148,8 +160,12 @@ function getHTMLTextForDetectLang(content) {
// Remove anything that can skew the language detection
// Remove .mention, .hashtag, pre, code, a:has(.invisible)
for (const a of dom.querySelectorAll(
for (const a of forgivingQSA(
[
'.mention, .hashtag, pre, code, a:has(.invisible)',
'.mention, .hashtag, pre, code',
],
dom,
)) {
a.remove();
}

264
src/locales/en.po generated
View file

@ -32,7 +32,7 @@ msgstr ""
#: src/components/account-block.jsx:168
#: src/components/account-info.jsx:641
#: src/components/status.jsx:498
#: src/components/status.jsx:514
msgid "Group"
msgstr ""
@ -107,11 +107,11 @@ msgstr ""
#: src/components/compose.jsx:2488
#: src/components/media-alt-modal.jsx:45
#: src/components/media-modal.jsx:357
#: src/components/status.jsx:1721
#: src/components/status.jsx:1738
#: src/components/status.jsx:1862
#: src/components/status.jsx:2474
#: src/components/status.jsx:2477
#: src/components/status.jsx:1737
#: src/components/status.jsx:1754
#: src/components/status.jsx:1878
#: src/components/status.jsx:2490
#: src/components/status.jsx:2493
#: src/pages/account-statuses.jsx:528
#: src/pages/accounts.jsx:109
#: src/pages/hashtag.jsx:199
@ -180,7 +180,7 @@ msgid "Original"
msgstr ""
#: src/components/account-info.jsx:864
#: src/components/status.jsx:2252
#: src/components/status.jsx:2268
#: src/pages/catchup.jsx:71
#: src/pages/catchup.jsx:1445
#: src/pages/catchup.jsx:2056
@ -276,30 +276,30 @@ msgid "Add/Remove from Lists"
msgstr ""
#: src/components/account-info.jsx:1304
#: src/components/status.jsx:1161
#: src/components/status.jsx:1177
msgid "Link copied"
msgstr ""
#: src/components/account-info.jsx:1307
#: src/components/status.jsx:1164
#: src/components/status.jsx:1180
msgid "Unable to copy link"
msgstr ""
#: src/components/account-info.jsx:1313
#: src/components/shortcuts-settings.jsx:1059
#: src/components/status.jsx:1170
#: src/components/status.jsx:3251
#: src/components/status.jsx:1186
#: src/components/status.jsx:3267
msgid "Copy"
msgstr ""
#: src/components/account-info.jsx:1328
#: src/components/shortcuts-settings.jsx:1077
#: src/components/status.jsx:1186
#: src/components/status.jsx:1202
msgid "Sharing doesn't seem to work."
msgstr ""
#: src/components/account-info.jsx:1334
#: src/components/status.jsx:1192
#: src/components/status.jsx:1208
msgid "Share…"
msgstr ""
@ -416,9 +416,9 @@ msgstr ""
#: src/components/shortcuts-settings.jsx:230
#: src/components/shortcuts-settings.jsx:583
#: src/components/shortcuts-settings.jsx:783
#: src/components/status.jsx:2976
#: src/components/status.jsx:3215
#: src/components/status.jsx:3713
#: src/components/status.jsx:2992
#: src/components/status.jsx:3231
#: src/components/status.jsx:3729
#: src/pages/accounts.jsx:36
#: src/pages/catchup.jsx:1581
#: src/pages/filters.jsx:224
@ -608,7 +608,7 @@ msgid "Attachment #{i} failed"
msgstr ""
#: src/components/compose.jsx:1139
#: src/components/status.jsx:2047
#: src/components/status.jsx:2063
#: src/components/timeline.jsx:984
msgid "Content warning"
msgstr ""
@ -644,7 +644,7 @@ msgstr ""
#: src/components/compose.jsx:1206
#: src/components/status.jsx:97
#: src/components/status.jsx:1925
#: src/components/status.jsx:1941
msgid "Private mention"
msgstr ""
@ -674,10 +674,10 @@ msgstr ""
#: src/components/compose.jsx:1504
#: src/components/keyboard-shortcuts-help.jsx:151
#: src/components/status.jsx:913
#: src/components/status.jsx:1701
#: src/components/status.jsx:1702
#: src/components/status.jsx:2370
#: src/components/status.jsx:929
#: src/components/status.jsx:1717
#: src/components/status.jsx:1718
#: src/components/status.jsx:2386
msgid "Reply"
msgstr ""
@ -892,7 +892,7 @@ msgstr ""
#: src/components/drafts.jsx:127
#: src/components/list-add-edit.jsx:185
#: src/components/status.jsx:1336
#: src/components/status.jsx:1352
#: src/pages/filters.jsx:587
msgid "Delete…"
msgstr ""
@ -1100,10 +1100,10 @@ msgid "<0>l</0> or <1>f</1>"
msgstr ""
#: src/components/keyboard-shortcuts-help.jsx:172
#: src/components/status.jsx:921
#: src/components/status.jsx:2396
#: src/components/status.jsx:2428
#: src/components/status.jsx:2429
#: src/components/status.jsx:937
#: src/components/status.jsx:2412
#: src/components/status.jsx:2444
#: src/components/status.jsx:2445
msgid "Boost"
msgstr ""
@ -1112,9 +1112,9 @@ msgid "<0>Shift</0> + <1>b</1>"
msgstr ""
#: src/components/keyboard-shortcuts-help.jsx:180
#: src/components/status.jsx:1006
#: src/components/status.jsx:2453
#: src/components/status.jsx:2454
#: src/components/status.jsx:1022
#: src/components/status.jsx:2469
#: src/components/status.jsx:2470
msgid "Bookmark"
msgstr ""
@ -1173,15 +1173,15 @@ msgid "Media description"
msgstr ""
#: src/components/media-alt-modal.jsx:57
#: src/components/status.jsx:1050
#: src/components/status.jsx:1077
#: src/components/status.jsx:1066
#: src/components/status.jsx:1093
#: src/components/translation-block.jsx:195
msgid "Translate"
msgstr ""
#: src/components/media-alt-modal.jsx:68
#: src/components/status.jsx:1064
#: src/components/status.jsx:1091
#: src/components/status.jsx:1080
#: src/components/status.jsx:1107
msgid "Speak"
msgstr ""
@ -1218,9 +1218,9 @@ msgid "Filtered: {filterTitleStr}"
msgstr ""
#: src/components/media-post.jsx:133
#: src/components/status.jsx:3543
#: src/components/status.jsx:3639
#: src/components/status.jsx:3717
#: src/components/status.jsx:3559
#: src/components/status.jsx:3655
#: src/components/status.jsx:3733
#: src/components/timeline.jsx:973
#: src/pages/catchup.jsx:75
#: src/pages/catchup.jsx:1876
@ -1508,8 +1508,8 @@ msgid "[Unknown notification type: {type}]"
msgstr ""
#: src/components/notification.jsx:434
#: src/components/status.jsx:1020
#: src/components/status.jsx:1030
#: src/components/status.jsx:1036
#: src/components/status.jsx:1046
msgid "Boosted/Liked by…"
msgstr ""
@ -1531,7 +1531,7 @@ msgid "Learn more <0/>"
msgstr ""
#: src/components/notification.jsx:756
#: src/components/status.jsx:251
#: src/components/status.jsx:267
msgid "Read more →"
msgstr ""
@ -1824,7 +1824,7 @@ msgid "Move down"
msgstr ""
#: src/components/shortcuts-settings.jsx:379
#: src/components/status.jsx:1298
#: src/components/status.jsx:1314
#: src/pages/list.jsx:170
msgid "Edit"
msgstr ""
@ -2022,297 +2022,297 @@ msgstr ""
msgid "Import/export settings from/to instance server (Very experimental)"
msgstr ""
#: src/components/status.jsx:522
#: src/components/status.jsx:538
msgid "<0/> <1>boosted</1>"
msgstr ""
#: src/components/status.jsx:621
#: src/components/status.jsx:637
msgid "Sorry, your current logged-in instance can't interact with this post from another instance."
msgstr ""
#: src/components/status.jsx:774
#: src/components/status.jsx:790
msgid "Unliked @{0}'s post"
msgstr ""
#: src/components/status.jsx:775
#: src/components/status.jsx:791
msgid "Liked @{0}'s post"
msgstr ""
#: src/components/status.jsx:814
#: src/components/status.jsx:830
msgid "Unbookmarked @{0}'s post"
msgstr ""
#: src/components/status.jsx:815
#: src/components/status.jsx:831
msgid "Bookmarked @{0}'s post"
msgstr ""
#: src/components/status.jsx:921
#: src/components/status.jsx:983
#: src/components/status.jsx:2396
#: src/components/status.jsx:2428
#: src/components/status.jsx:937
#: src/components/status.jsx:999
#: src/components/status.jsx:2412
#: src/components/status.jsx:2444
msgid "Unboost"
msgstr ""
#: src/components/status.jsx:937
#: src/components/status.jsx:2411
#: src/components/status.jsx:953
#: src/components/status.jsx:2427
msgid "Quote"
msgstr ""
#: src/components/status.jsx:945
#: src/components/status.jsx:2420
#: src/components/status.jsx:961
#: src/components/status.jsx:2436
msgid "Some media have no descriptions."
msgstr ""
#: src/components/status.jsx:952
#: src/components/status.jsx:968
msgid "Old post (<0>{0}</0>)"
msgstr ""
#: src/components/status.jsx:971
#: src/components/status.jsx:1426
#: src/components/status.jsx:987
#: src/components/status.jsx:1442
msgid "Unboosted @{0}'s post"
msgstr ""
#: src/components/status.jsx:972
#: src/components/status.jsx:1427
#: src/components/status.jsx:988
#: src/components/status.jsx:1443
msgid "Boosted @{0}'s post"
msgstr ""
#: src/components/status.jsx:984
#: src/components/status.jsx:1000
msgid "Boost…"
msgstr ""
#: src/components/status.jsx:996
#: src/components/status.jsx:1711
#: src/components/status.jsx:2441
#: src/components/status.jsx:1012
#: src/components/status.jsx:1727
#: src/components/status.jsx:2457
msgid "Unlike"
msgstr ""
#: src/components/status.jsx:997
#: src/components/status.jsx:1711
#: src/components/status.jsx:1712
#: src/components/status.jsx:2441
#: src/components/status.jsx:2442
#: src/components/status.jsx:1013
#: src/components/status.jsx:1727
#: src/components/status.jsx:1728
#: src/components/status.jsx:2457
#: src/components/status.jsx:2458
msgid "Like"
msgstr ""
#: src/components/status.jsx:1006
#: src/components/status.jsx:2453
#: src/components/status.jsx:1022
#: src/components/status.jsx:2469
msgid "Unbookmark"
msgstr ""
#: src/components/status.jsx:1114
#: src/components/status.jsx:1130
msgid "View post by <0>@{0}</0>"
msgstr ""
#: src/components/status.jsx:1135
#: src/components/status.jsx:1151
msgid "Show Edit History"
msgstr ""
#: src/components/status.jsx:1138
#: src/components/status.jsx:1154
msgid "Edited: {editedDateText}"
msgstr ""
#: src/components/status.jsx:1205
#: src/components/status.jsx:3220
#: src/components/status.jsx:1221
#: src/components/status.jsx:3236
msgid "Embed post"
msgstr ""
#: src/components/status.jsx:1219
#: src/components/status.jsx:1235
msgid "Conversation unmuted"
msgstr ""
#: src/components/status.jsx:1219
#: src/components/status.jsx:1235
msgid "Conversation muted"
msgstr ""
#: src/components/status.jsx:1225
#: src/components/status.jsx:1241
msgid "Unable to unmute conversation"
msgstr ""
#: src/components/status.jsx:1226
#: src/components/status.jsx:1242
msgid "Unable to mute conversation"
msgstr ""
#: src/components/status.jsx:1235
#: src/components/status.jsx:1251
msgid "Unmute conversation"
msgstr ""
#: src/components/status.jsx:1242
#: src/components/status.jsx:1258
msgid "Mute conversation"
msgstr ""
#: src/components/status.jsx:1258
#: src/components/status.jsx:1274
msgid "Post unpinned from profile"
msgstr ""
#: src/components/status.jsx:1259
#: src/components/status.jsx:1275
msgid "Post pinned to profile"
msgstr ""
#: src/components/status.jsx:1264
#: src/components/status.jsx:1280
msgid "Unable to unpin post"
msgstr ""
#: src/components/status.jsx:1264
#: src/components/status.jsx:1280
msgid "Unable to pin post"
msgstr ""
#: src/components/status.jsx:1273
#: src/components/status.jsx:1289
msgid "Unpin from profile"
msgstr ""
#: src/components/status.jsx:1280
#: src/components/status.jsx:1296
msgid "Pin to profile"
msgstr ""
#: src/components/status.jsx:1309
#: src/components/status.jsx:1325
msgid "Delete this post?"
msgstr ""
#: src/components/status.jsx:1325
#: src/components/status.jsx:1341
msgid "Post deleted"
msgstr ""
#: src/components/status.jsx:1328
#: src/components/status.jsx:1344
msgid "Unable to delete post"
msgstr ""
#: src/components/status.jsx:1356
#: src/components/status.jsx:1372
msgid "Report post…"
msgstr ""
#: src/components/status.jsx:1712
#: src/components/status.jsx:1748
#: src/components/status.jsx:2442
#: src/components/status.jsx:1728
#: src/components/status.jsx:1764
#: src/components/status.jsx:2458
msgid "Liked"
msgstr ""
#: src/components/status.jsx:1745
#: src/components/status.jsx:2429
#: src/components/status.jsx:1761
#: src/components/status.jsx:2445
msgid "Boosted"
msgstr ""
#: src/components/status.jsx:1755
#: src/components/status.jsx:2454
#: src/components/status.jsx:1771
#: src/components/status.jsx:2470
msgid "Bookmarked"
msgstr ""
#: src/components/status.jsx:1759
#: src/components/status.jsx:1775
msgid "Pinned"
msgstr ""
#: src/components/status.jsx:1804
#: src/components/status.jsx:2260
#: src/components/status.jsx:1820
#: src/components/status.jsx:2276
msgid "Deleted"
msgstr ""
#: src/components/status.jsx:1845
#: src/components/status.jsx:1861
msgid "{repliesCount, plural, one {# reply} other {# replies}}"
msgstr ""
#: src/components/status.jsx:1934
#: src/components/status.jsx:1950
msgid "Thread{0}"
msgstr ""
#: src/components/status.jsx:2010
#: src/components/status.jsx:2072
#: src/components/status.jsx:2157
#: src/components/status.jsx:2026
#: src/components/status.jsx:2088
#: src/components/status.jsx:2173
msgid "Show less"
msgstr ""
#: src/components/status.jsx:2010
#: src/components/status.jsx:2072
#: src/components/status.jsx:2026
#: src/components/status.jsx:2088
msgid "Show content"
msgstr ""
#: src/components/status.jsx:2157
#: src/components/status.jsx:2173
msgid "Show media"
msgstr ""
#: src/components/status.jsx:2294
#: src/components/status.jsx:2310
msgid "Edited"
msgstr ""
#: src/components/status.jsx:2371
#: src/components/status.jsx:2387
msgid "Comments"
msgstr ""
#. More from [Author]
#: src/components/status.jsx:2680
#: src/components/status.jsx:2696
msgid "More from <0/>"
msgstr "More from <0/>"
#: src/components/status.jsx:2981
#: src/components/status.jsx:2997
msgid "Edit History"
msgstr ""
#: src/components/status.jsx:2985
#: src/components/status.jsx:3001
msgid "Failed to load history"
msgstr ""
#: src/components/status.jsx:2990
#: src/components/status.jsx:3006
msgid "Loading…"
msgstr ""
#: src/components/status.jsx:3225
#: src/components/status.jsx:3241
msgid "HTML Code"
msgstr ""
#: src/components/status.jsx:3242
#: src/components/status.jsx:3258
msgid "HTML code copied"
msgstr ""
#: src/components/status.jsx:3245
#: src/components/status.jsx:3261
msgid "Unable to copy HTML code"
msgstr ""
#: src/components/status.jsx:3257
#: src/components/status.jsx:3273
msgid "Media attachments:"
msgstr ""
#: src/components/status.jsx:3279
#: src/components/status.jsx:3295
msgid "Account Emojis:"
msgstr ""
#: src/components/status.jsx:3310
#: src/components/status.jsx:3355
#: src/components/status.jsx:3326
#: src/components/status.jsx:3371
msgid "static URL"
msgstr ""
#: src/components/status.jsx:3324
#: src/components/status.jsx:3340
msgid "Emojis:"
msgstr ""
#: src/components/status.jsx:3369
#: src/components/status.jsx:3385
msgid "Notes:"
msgstr ""
#: src/components/status.jsx:3373
#: src/components/status.jsx:3389
msgid "This is static, unstyled and scriptless. You may need to apply your own styles and edit as needed."
msgstr ""
#: src/components/status.jsx:3379
#: src/components/status.jsx:3395
msgid "Polls are not interactive, becomes a list with vote counts."
msgstr ""
#: src/components/status.jsx:3384
#: src/components/status.jsx:3400
msgid "Media attachments can be images, videos, audios or any file types."
msgstr ""
#: src/components/status.jsx:3390
#: src/components/status.jsx:3406
msgid "Post could be edited or deleted later."
msgstr ""
#: src/components/status.jsx:3396
#: src/components/status.jsx:3412
msgid "Preview"
msgstr ""
#: src/components/status.jsx:3405
#: src/components/status.jsx:3421
msgid "Note: This preview is lightly styled."
msgstr ""
#. [Name] [Visibility icon] boosted
#: src/components/status.jsx:3647
#: src/components/status.jsx:3663
msgid "<0/> <1/> boosted"
msgstr ""