Created
May 9, 2022 23:22
-
-
Save Mabdelwanis/3ea473676ab81806022edf6ac0e39a05 to your computer and use it in GitHub Desktop.
This script displays a menu option in your userscript manager to translate the current page using Google Translate
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
// ==UserScript== | |
// @name Google Translate - 2022 | |
// @namespace https://greasyfork.org/users/906463-coffeegrind123 | |
// @homepageURL https://gist.github.com/coffeegrind123/8ca2c7e700aca3341c71da8d612f6130 | |
// @supportURL https://greasyfork.org/scripts/443947-google-translate-2022 | |
// @match http*://*/* | |
// @exclude http*://*.google.*/* | |
// @grant GM_registerMenuCommand | |
// @noframes | |
// @version 2.4 | |
// @license WTFPL | |
// @icon https://translate.google.com/favicon.ico | |
// @author coffeegrind123 | |
// @description This script displays a menu option in your userscript manager to translate the current page using Google Translate | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
if (window.top != window.self) | |
return; | |
var getlang = navigator.language || navigator.userLanguage; | |
var lang = getlang.split('-')[0]; | |
function translateRedirect() { | |
var arr = window.location.href.split('?'); | |
if (arr.length > 1 && arr[1] !== '') { | |
var translateParams = '&_x_tr_sl=auto&_x_tr_tl=' + lang + '&_x_tr_hl=' + lang; | |
} else { | |
var translateParams = '?_x_tr_sl=auto&_x_tr_tl=' + lang + '&_x_tr_hl=' + lang; | |
} | |
var website = window.location.hostname.replace(/-/g, "--").replace(/\./g, '-'); | |
var redirect = 'https://' + website + '.translate.goog' + window.location.pathname + window.location.search + translateParams + window.location.hash; | |
window.location = redirect; | |
} | |
GM_registerMenuCommand('Translate page', translateRedirect); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment