📤 Built a useful command? Submit it here — we'll review & add it to the library.

Translate Description & Activity

Hint: Translate short description, description, and activity notes (skips emails)

Trigger: \translate

(function() {
  var clicked = 0;
  var skipped = 0;

  // 1. Short Description & Description translate buttons
  var fieldButtons = document.querySelectorAll(
    'button#incident\\.short_description_translate\\.btn,' +
    'button#incident\\.description_translate\\.btn,' +
    'button[id*="translate"]'
  );
  fieldButtons.forEach(function(btn) {
    var visible = btn.offsetParent !== null &&
      getComputedStyle(btn).display !== 'none' &&
      getComputedStyle(btn).visibility !== 'hidden';
    if (visible) { btn.click(); clicked++; }
  });

  // 2. Activity feed: Work Notes & Comments (skip email entries)
  var cards = document.querySelectorAll('div.sn-card-component');
  cards.forEach(function(card) {
    var metaText = card.textContent.toLowerCase();
    if (metaText.indexOf('email sent') !== -1 || metaText.indexOf('email received') !== -1) {
      card.querySelectorAll('a[href*="translation-link-toggle"], a').forEach(function(a) {
        if (a.textContent.trim() === 'Translate') skipped++;
      });
      return;
    }
    var translateLinks = card.querySelectorAll('a[href*="translation-link-toggle"]');
    var toClick = [];
    if (translateLinks.length > 0) {
      translateLinks.forEach(function(a) { toClick.push(a); });
    } else {
      card.querySelectorAll('a').forEach(function(a) {
        if (a.textContent.trim() === 'Translate') toClick.push(a);
      });
    }
    toClick.forEach(function(a) { if (a.offsetParent !== null) { a.click(); clicked++; } });
  });

  var toast = document.createElement('div');
  toast.textContent = clicked + ' translated, ' + skipped + ' email(s) skipped';
  toast.style.cssText = 'position:fixed;bottom:30px;right:30px;background:#2e7d32;color:#fff;padding:12px 20px;border-radius:6px;font-family:sans-serif;font-size:14px;font-weight:bold;z-index:99999;box-shadow:0 4px 12px rgba(0,0,0,0.3);';
  document.body.appendChild(toast);
  setTimeout(function() { if (toast.parentNode) toast.parentNode.removeChild(toast); }, 3500);
})();