Created
May 28, 2025 18:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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