Last active
October 10, 2024 16:37
-
-
Save apfelchips/d8a6e08c1aeb79df4372096fd11c1fc1 to your computer and use it in GitHub Desktop.
userscript that forces aliexpress.com to be in english
This file contains 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 @attero@mastodon.social | |
// @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) | |
} |
Hmmm, it seemed to work on my first attempt, but now it seems to be stuck in a redirect loop, once redirected to aliexpress.ru
It works great without changes :) Wow thanks for this scrip save nerves.
If I open a link from Google Images search and it is in hebrew, italiano or any other language, it does not work.. The links are like this: it.aliexpress.com
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script gives me errors because
await
is used outside of anasync
function.To fix this, I wrapped most of the code (starting from line 82) in
Also, these patterns:
are giving errors (at least when used with ViolentMonkey):
They seem to be unnecessary, I just removed them