Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- function remove_findbar_matches(label) {
- if (!label) return;
- // Remove the Fluent l10n ID so Firefox's translation engine stops overwriting text
- if (label.hasAttribute("data-l10n-id")) {
- label.removeAttribute("data-l10n-id");
- }
- // Read the match counts directly from Firefox's internal l10n arguments
- let rawArgs = label.getAttribute("data-l10n-args");
- if (rawArgs) {
- try {
- let args = JSON.parse(rawArgs);
- if (args && args.current !== undefined && args.total !== undefined) {
- let text = `${args.current} of ${args.total}`;
- if (args.limit && args.total > args.limit) {
- text = `${args.current} of >${args.limit}`;
- }
- if (label.textContent !== text) {
- label.textContent = text;
- }
- }
- } catch (e) {
- if (label.textContent.includes(" matches")) {
- label.textContent = label.textContent.replace(/\s*matches\s*/gi, "");
- }
- }
- }
- }
- // Observe attribute updates on the count label
- let labelObserver = new MutationObserver((mutations) => {
- for (let mut of mutations) {
- if (mut.type === "attributes") {
- remove_findbar_matches(mut.target);
- }
- }
- });
- function attachToFindbar(findbar) {
- let label = findbar.querySelector(".findbar-label.found-matches");
- if (label && !label.dataset.matchesObserved) {
- label.dataset.matchesObserved = "true";
- remove_findbar_matches(label);
- labelObserver.observe(label, {
- attributes: true,
- attributeFilter: ["data-l10n-args", "data-l10n-id"]
- });
- }
- }
- // Watch for when <findbar> is injected into the DOM
- let docObserver = new MutationObserver(() => {
- let findbars = document.querySelectorAll("findbar, #FindToolbar");
- findbars.forEach(attachToFindbar);
- });
- docObserver.observe(document.documentElement, {
- childList: true,
- subtree: true
- });
- // Initial check in case findbar is already in DOM
- document.querySelectorAll("findbar, #FindToolbar").forEach(attachToFindbar);
- })();
Advertisement
Add Comment
Please, Sign In to add comment