Trasnlate Bakcup 6/5/25
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Custom Google Translate</title>
<style>
#google-translate-menu {
border: 1px solid #ccc !important;
background-color: #333 !important;
color: #fff !important;
padding: 8px 16px !important;
font-size: 14px !important;
font-family: Arial, sans-serif !important;
border-radius: 4px !important;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
display: inline-block;
margin: 10px auto;
cursor: pointer !important;
text-align: center;
max-width: 200px;
transition: color 0.3s ease, background-color 0.3s ease;
}
#google-translate-menu:hover {
background-color: #444 !important;
color: #fff !important;
}
.goog-logo-link,
.goog-te-gadget span {
display: none !important;
}
.goog-te-banner-frame.skiptranslate {
display: none !important;
}
body {
top: 0 !important;
}
</style>
</head>
<body>
<div id="google-translate-menu" role="menuitem" tabindex="0" aria-label="Translate this site"></div>
<script>
function replaceGoogleTranslateMenuItem() {
const menuItems = document.querySelectorAll('.sl-modern-menu [role="menuitem"]');
for (const item of menuItems) {
if (item.textContent.trim() === 'Google Translate') {
const parentLi = item.closest('li');
if (parentLi) {
parentLi.innerHTML = '<div id="google-translate-menu" role="menuitem" tabindex="0" aria-label="Translate this site"></div>';
break;
}
}
}
}
function waitForTranslateText(retries = 10) {
const labelSpan = document.querySelector('.goog-te-gadget-simple .VIpgJd-ZVi9od-xl07Ob-lTBxed');
if (labelSpan) {
// Set text color
labelSpan.style.color = '#fff';
// ✅ Set arrow color
const arrow = labelSpan.querySelector('span[aria-hidden="true"]');
if (arrow) {
arrow.style.color = '#fff';
}
} else if (retries > 0) {
setTimeout(() => waitForTranslateText(retries - 1), 300);
}
}
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google-translate-menu');
waitForTranslateText(); // Retry styling until it's there
}
window.addEventListener('DOMContentLoaded', () => {
replaceGoogleTranslateMenuItem();
loadGoogleTranslate();
});
function loadGoogleTranslate() {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
document.head.appendChild(script);
}
</script>
</body>
</html>
