Last active
May 21, 2025 23:57
-
-
Save apfelchips/d8a6e08c1aeb79df4372096fd11c1fc1 to your computer and use it in GitHub Desktop.
userscript that forces aliexpress.com to be in english
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 aliexpress_en | |
// @version 0.2 | |
// @description always redirect to aliexpress.com and reset the location/language/currency settings. This script pins locale settings cookie. Please clear cookies on all "aliexpress" domains before using this userscript. | |
// @author @[email protected] | |
// @match *://www.aliexpress.com/* | |
// @match *://*.aliexpress.com/* | |
// @match *://www.aliexpress.ru/* | |
// @match *://*.aliexpress.ru/* | |
// @noframes | |
// @license MIT | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=aliexpress.com | |
// @supportURL https://gist.githubusercontent.com/apfelchips/d8a6e08c1aeb79df4372096fd11c1fc1/ | |
// ==/UserScript== | |
// adapted from: https://greasyfork.org/en/scripts/447465-fix-com-to-ru-gatewayadapt-glo2rus-aliexpress-redirect-for-ukraine/code | |
// doc: https://www.tampermonkey.net/documentation.php / https://violentmonkey.github.io/api/metadata-block/ | |
const FORCE_SITE = 'glo' | |
const FORCE_REGION = 'DE' | |
const FORCE_LOCALE = 'en_US' | |
const FORCE_CURRENCY = 'EUR' | |
const Style = { | |
base: [ | |
"color: #fff", | |
"background-color: #444", | |
"padding: 2px 4px", | |
"border-radius: 2px", | |
"font-weight: bold" | |
], | |
green: [ | |
"background-color: green" | |
], | |
red: [ | |
"color: #eee", | |
"background-color: red" | |
], | |
blue: [ | |
"background-color: blue" | |
], | |
yellow: [ | |
"color: #444", | |
"background-color: yellow" | |
], | |
orange: [ | |
"background-color: orange" | |
] | |
} | |
function log(input, extra = []) { | |
let style = Style.base.join(';') + ';'; | |
style += extra.join(';'); | |
let logmsg = input | |
if ( typeof(input) == 'object'){ | |
logmsg = JSON.stringify(input, null, 2).replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, (x) => x.replace(/"/g, '')) // json without quoted properties | |
} | |
console.log(`%c${logmsg}`, style); | |
} | |
function getCookie(cName) { | |
var match = document.cookie.match(new RegExp('(^| )' + cName + '=([^;]+)')) | |
if (match) { | |
log(`found cookie: ${cName}: ${match[2]}`, Style.green) | |
return match[2] | |
} else { | |
log(`empty/unset cookie: ${cName}: ''`, Style.yellow) | |
return '' | |
} | |
} | |
function setCookie(cName, cValue, expDays) { | |
let date = new Date() | |
date.setTime(date.getTime() + (expDays * 24 * 60 * 60 * 1000)) | |
const expires = `expires=${date.toUTCString()}` | |
log(`setting cookie: ${cName}: ${cValue}`, Style.orange) | |
document.cookie = `${cName}=${cValue}; ${expires}; path=/` | |
} | |
const aepCookie = getCookie('aep_usuc_f') | |
const intlCookie = getCookie('intl_locale') | |
const xmanCookie = getCookie('xman_us_f') | |
if (!(aepCookie.includes(`site=${FORCE_SITE}`) | |
&& aepCookie.includes(`region=${FORCE_REGION}`) | |
&& aepCookie.includes(`b_locale=${FORCE_LOCALE}`) | |
&& aepCookie.includes(`c_tp=${FORCE_CURRENCY}`) | |
)) { | |
// site=deu&c_tp=EUR&ups_d=&ups_u_t=®ion=DE&b_locale=de_DE&ae_u_p_s=1 | |
const newaepCookie = `site=${FORCE_SITE}&c_tp=${FORCE_CURRENCY}&ups_d=&ups_u_t=®ion=${FORCE_REGION}&b_locale=${FORCE_LOCALE}&ae_u_p_s=1` | |
setCookie('aep_usuc_f', newaepCookie, 9999) | |
} | |
if ( ! intlCookie.includes(`${FORCE_LOCALE}`)) { | |
setCookie('intl_locale', FORCE_LOCALE, 9999) | |
} | |
if ( ! xmanCookie.includes(`x_locale=${FORCE_LOCALE}`)) { | |
const newxmanCookie = xmanCookie.replace(/x_locale=\w{2}_\w{2}/i, `x_locale=${FORCE_LOCALE}`) | |
setCookie('xman_us_f', newxmanCookie, 9999) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to thank you very much for this script. It saves me time of every time changing the language and currency.
Aliexpress has a new UI now and it hides the shop names in the search results. Could you write a script were the shop names are visible again?