Skip to content

Instantly share code, notes, and snippets.

@natzir
Created May 28, 2025 18:48
Show Gist options
  • Save natzir/f13e37febb8ba7e5f1e9caed620c26d4 to your computer and use it in GitHub Desktop.
Save natzir/f13e37febb8ba7e5f1e9caed620c26d4 to your computer and use it in GitHub Desktop.
Block Google AI Overviews from hijacking your website traffic via Google Translate. Automatically redirects visitors from Google Translate SGE back to your original domain.
<script type="text/javascript">
console.log("πŸ” Anti Google Translate SGE");
(function() {
const urlParams = new URLSearchParams(window.location.search);
const hasSGEParam = urlParams.has("_x_tr_pto") && urlParams.get("_x_tr_pto") === "sge";
console.log("πŸ” Checking _x_tr_pto parameter:", {
hasParam: urlParams.has("_x_tr_pto"),
paramValue: urlParams.get("_x_tr_pto"),
isSGE: hasSGEParam
});
if (hasSGEParam) {
console.log("βœ… SGE parameter detected, redirecting...");
let originalDomain = window.location.hostname;
if (originalDomain.includes('translate.goog')) {
originalDomain = originalDomain.replace('.translate.goog', '')
.replace(/-/g, '.');
}
const targetURL = window.location.protocol + '//' + originalDomain + window.location.pathname;
console.log("πŸ”„ Redirecting to:", targetURL);
window.location.href = targetURL;
} else {
console.log("❌ No SGE parameter found, allowing normal access");
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment