Last active
September 21, 2021 18:45
-
-
Save Erquint/4b0dada56b0fed4412ed8cb2e97a2473 to your computer and use it in GitHub Desktop.
Prevents redirection to Russian pages of AliExpress and tries to reach global page as a mayday fallback. Install with the following link: https://gist.githubusercontent.com/Erquint/4b0dada56b0fed4412ed8cb2e97a2473/raw/DerusifyAliExpressLinks.user.js
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 DerusifyAliExpressLinks | |
// @description Prevents redirection to Russian pages of AliExpress and tries to reach global page as a mayday fallback. | |
// @version 1.0 | |
// @namespace gness.na@gmail.com | |
// @author https://gist.github.com/Erquint | |
// @homepageURL https://gist.github.com/Erquint/4b0dada56b0fed4412ed8cb2e97a2473 | |
// @updateURL https://gist.githubusercontent.com/Erquint/4b0dada56b0fed4412ed8cb2e97a2473/raw/DerusifyAliExpressLinks.user.js | |
// @downloadURL https://gist.githubusercontent.com/Erquint/4b0dada56b0fed4412ed8cb2e97a2473/raw/DerusifyAliExpressLinks.user.js | |
// @match http*://*aliexpress.*/* | |
// @run-at document-start | |
// @noframes | |
// @inject-into auto | |
// @grant none | |
// ==/UserScript== | |
if (window.location.href.includes('.ru/')) { // Crude mayday fallback just in case. May break in the future. | |
function fallback() { | |
document.querySelector('.language-selector > ul:nth-child(3) > li:nth-child(1) > a:nth-child(1)').click(); | |
document.querySelector('.ui-button').click(); | |
} | |
document.addEventListener('DOMContentLoaded', (e => {setTimeout(fallback, 5000)})); | |
} else { // Upon each click checks if it's a redirection element and defuses it if needed. | |
function main(event) { | |
if (event.target.tagName == 'A') {sub(event.target);} // If Web was ever sane. | |
else if (event.target.parentElement.tagName == 'A') {sub(event.target.parentElement);} // May break in the furure. | |
return false; // Prevents following the original link. | |
} | |
function sub(element) { // Simple replacement. Sufficient so far. | |
window.location.href = element.href.replace('.ru/', '.com/'); | |
} | |
window.onclick = main; // Tab-wide global callback. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm sorry.
It worked for the limited testing I did, but either something changed or AliExpress works differently for different users and thus needs different patches.
It was made on request by a certain individual and they have since also reported it not working reliably for them.
Take it as proof of concept maybe, but I'm not planning to adapt it further, since I don't even use AE on the web myself.