Skip to content

Instantly share code, notes, and snippets.

@and-rom
Last active December 13, 2021 11:28
Show Gist options
  • Select an option

  • Save and-rom/6410c82f14c66711abfda7f0fa1cb5c0 to your computer and use it in GitHub Desktop.

Select an option

Save and-rom/6410c82f14c66711abfda7f0fa1cb5c0 to your computer and use it in GitHub Desktop.
AliExpress Links Change
// ==UserScript==
// @name AliExpress Links Change
// @namespace https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0
// @version 0.5
// @author and-rom
// @description Change links domain from .ru to .com
// @homepage https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0
// @icon https://ae01.alicdn.com/images/eng/wholesale/icon/aliexpress.ico
// @icon64 https://ae01.alicdn.com/images/eng/wholesale/icon/aliexpress.ico
// @updateURL https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0/raw/alilinkschange.meta.js
// @downloadURL https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0/raw/alilinkschange.user.js
// @match https://*.aliexpress.com/*
// @match https://*.aliexpress.ru/*
// @grant none
// ==/UserScript==
// ==UserScript==
// @name AliExpress Links Change
// @namespace https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0
// @version 0.5
// @author and-rom
// @description Change links domain from .ru to .com
// @homepage https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0
// @icon https://ae01.alicdn.com/images/eng/wholesale/icon/aliexpress.ico
// @icon64 https://ae01.alicdn.com/images/eng/wholesale/icon/aliexpress.ico
// @updateURL https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0/raw/alilinkschange.meta.js
// @downloadURL https://gist.github.com/and-rom/6410c82f14c66711abfda7f0fa1cb5c0/raw/alilinkschange.user.js
// @match https://*.aliexpress.com/*
// @match https://*.aliexpress.ru/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function go(links) {
links.forEach(function(link){
if (link.hasAttribute("href")) {
//console.log(link.getAttribute("href"));
link.setAttribute("href", link.getAttribute("href").replace("aliexpress.ru", "aliexpress.com"));
//console.log(link.getAttribute("href"));
}
});
}
function setObserver() {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function( mutation ) {
var newNodes = mutation.addedNodes;
if (newNodes !== null && newNodes.length !== 0 && mutation.target.tagName !== "EM") { // If there are new nodes added
//console.log(mutation);
//console.log(newNodes);
newNodes.forEach(function( newNode ) {
if (newNode.nodeName === "#text" || newNode.nodeName === "#comment") return;
var links = newNode.querySelectorAll('a');
if (links.length !== 0) go(links); //console.log(links);
});
}
});
});
observer.observe(document, {
childList: true,
subtree: true
});
}
document.addEventListener('keydown', function(e) {
if (e.altKey) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 82) { go(document.querySelectorAll('a')); } // Alt + r
}
});
var interval = setInterval(function() {
if(document.readyState === 'complete') {
clearInterval(interval);
setObserver();
go(document.querySelectorAll('a'));
}
}, 100);
})();
@Korb
Copy link

Korb commented Dec 13, 2021

What exactly does this script do?

@and-rom
Copy link
Author

and-rom commented Dec 13, 2021

It replaces link's href from aliexpress.ru to aliexpress.com.
If you don't live in Russia it's not relevant for you.

@Korb
Copy link

Korb commented Dec 13, 2021

I'm from Russia. And - yes, the script changes links to aliexpress.com. But these links still open the aliexpress.ru pages. Does the script make any sense other than sending links from search results to foreign contacts?

@and-rom
Copy link
Author

and-rom commented Dec 13, 2021

Что Вы имеете в виду под "sending links from search results to foreign contacts"? Скрипт ничего никуда не отправляет.
Что до его основной задачи, то, скорее всего, сейчас он уже не может не работать. Я писал его для себя и какое-то время им пользовался. В данный момент я сам его не использую и поэтому не знаю совместим ли он с текущей логикой Aliexpress.

@Korb
Copy link

Korb commented Dec 13, 2021

@and-rom, я имею ввиду, что польза скрипта сейчас, кажется, только в том, что пользователь может отправить .com-ссылку на товар кому-то за пределами этой страны и не бояться, что получатель ссылки, перейдя по ней, увидит непонятные кириллические каракули (сайта aliexpress.ru).

@and-rom
Copy link
Author

and-rom commented Dec 13, 2021

А, если в этом смысле, то да.
А на счет поделиться ссылкой на товар без опасения, что кто-то увидит незнакомые символы... Если учитывать то, насколько рьяно aliexpress старается переадресовать посетителя на домен в его локальной зоне, я думаю, что, даже если кто-то за пределами России перейдет по ссылке в домене .ru, то aliexpress вероятно переадресует его на локальный домен (если у них такой конечно имеется.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment