tetra55

Untitled

Sep 2nd, 2026
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. (function() {
  2. function remove_findbar_matches(label) {
  3. if (!label) return;
  4.  
  5. // Remove the Fluent l10n ID so Firefox's translation engine stops overwriting text
  6. if (label.hasAttribute("data-l10n-id")) {
  7. label.removeAttribute("data-l10n-id");
  8. }
  9.  
  10. // Read the match counts directly from Firefox's internal l10n arguments
  11. let rawArgs = label.getAttribute("data-l10n-args");
  12. if (rawArgs) {
  13. try {
  14. let args = JSON.parse(rawArgs);
  15. if (args && args.current !== undefined && args.total !== undefined) {
  16. let text = `${args.current} of ${args.total}`;
  17. if (args.limit && args.total > args.limit) {
  18. text = `${args.current} of >${args.limit}`;
  19. }
  20. if (label.textContent !== text) {
  21. label.textContent = text;
  22. }
  23. }
  24. } catch (e) {
  25. if (label.textContent.includes(" matches")) {
  26. label.textContent = label.textContent.replace(/\s*matches\s*/gi, "");
  27. }
  28. }
  29. }
  30. }
  31.  
  32. // Observe attribute updates on the count label
  33. let labelObserver = new MutationObserver((mutations) => {
  34. for (let mut of mutations) {
  35. if (mut.type === "attributes") {
  36. remove_findbar_matches(mut.target);
  37. }
  38. }
  39. });
  40.  
  41. function attachToFindbar(findbar) {
  42. let label = findbar.querySelector(".findbar-label.found-matches");
  43. if (label && !label.dataset.matchesObserved) {
  44. label.dataset.matchesObserved = "true";
  45. remove_findbar_matches(label);
  46. labelObserver.observe(label, {
  47. attributes: true,
  48. attributeFilter: ["data-l10n-args", "data-l10n-id"]
  49. });
  50. }
  51. }
  52.  
  53. // Watch for when <findbar> is injected into the DOM
  54. let docObserver = new MutationObserver(() => {
  55. let findbars = document.querySelectorAll("findbar, #FindToolbar");
  56. findbars.forEach(attachToFindbar);
  57. });
  58.  
  59. docObserver.observe(document.documentElement, {
  60. childList: true,
  61. subtree: true
  62. });
  63.  
  64. // Initial check in case findbar is already in DOM
  65. document.querySelectorAll("findbar, #FindToolbar").forEach(attachToFindbar);
  66. })();
Advertisement
Add Comment
Please, Sign In to add comment