All In One Translator - Amazon

Auto translates all Amazon market places, Argus dashboard as well as all the foreign language web pages required for external research to English.

目前為 2021-03-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        All In One Translator - Amazon
// @namespace   sumedha
// @description Auto translates all Amazon market places, Argus dashboard as well as all the foreign language web pages required for external research to English. 
// @include     *://*/*
// @license     MIT
// @author      msumedha, dmundhe
// @run-at      document-body
// @exclude     /^.translate.googleapis.com./
// @version     1.0
// @grant       none
// @noframes
// ==/UserScript==


/*
Part 1: Setting up the cookie required by google translate to translate the page

Google checks if there's already a cookie googtrans, if not, it doesn't automatically translate the page.
So, first we are setting up the cookie to english language /auto/en.
*/

var amazonDomain;
for (amazonDomain = window.location.hostname.split("."); 2 < amazonDomain.length;){
    amazonDomain.shift();
}

amazonDomain = ";domain=" + amazonDomain.join(".");

// domain cookie
document.cookie = "googtrans=/auto/en; expires=Thu, 07-Mar-2050 20:22:40 GMT; path=/" + amazonDomain;
document.cookie = "googtrans=/auto/en; expires=Thu, 07-Mar-2050 20:22:40 GMT; path=/";



/*
Part 2: Setting up google translate

Reference - https://www.w3schools.com/howto/howto_google_translate.asp
*/


var googleTranslateDivElement = document.createElement('div');
googleTranslateDivElement.id = 'google_translate_element';
googleTranslateDivElement.style.display='none';
document.body.insertBefore(googleTranslateDivElement, document.body.firstChild);

var translateElement = document.createElement('script');

translateElement.setAttribute('src','https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');
translateElement.type = "text/javascript";
document.body.appendChild(translateElement);

var translateScript = document.createElement('script');
translateScript.type = "text/javascript";
translateScript.text = "function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: ''}, 'google_translate_element');}";

document.body.appendChild(translateScript);