-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aliexpress Localized links remover.user.js
81 lines (81 loc) · 2.21 KB
/
Aliexpress Localized links remover.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ==UserScript==
// @name Aliexpress Localized links remover
// @description Removes localized links for Aliexpress and replaces them to the English site urls
// @homepageURL https://github.com/IRainman/user_scripts
// @namespace https://github.com/IRainman/user_scripts
// @supportURL https://github.com/IRainman/user_scripts/issues
// @author HedgehogInTheCPP
// @version 1.5
// @grant none
// @include http://*
// @include https://*
// ==/UserScript==
(function () {
String.prototype.replaceAt=function(index, replacement, length) {
return this.substr(0, index) + replacement + this.substr(index + length);
}
function replaceLinkPattern(pattern, replacement, link) {
const index = link.href.indexOf(pattern);
if (index !== -1) {
link.href = link.href.replaceAt(index, replacement, pattern.length);
return true;
} else {
return false;
}
}
function checkLinkHost(host, link) {
if (link.host == host) {
return true;
} else if (link.host.length < host.length + 1) {
return false;
} else if (link.host.endsWith("." + host)) {
return true;
} else {
return false;
}
}
const domains = [
'aliexpress.ru',
'ru.aliexpress.com',
'pt.aliexpress.com',
'es.aliexpress.com',
'id.aliexpress.com',
'ar.aliexpress.com',
'ko.aliexpress.com',
'pl.aliexpress.com',
'ja.aliexpress.com',
'th.aliexpress.com',
'tr.aliexpress.com',
'it.aliexpress.com',
'vi.aliexpress.com',
'he.aliexpress.com',
'fr.aliexpress.com',
'de.aliexpress.com',
];
const replacement = 'aliexpress.com';
function rwLink(link) {
for (let i = 0; i < domains.length; ++i) {
if (checkLinkHost(domains[i], link) && replaceLinkPattern(domains[i], replacement, link)) {
break;
}
}
}
function rwLinksInNode(node, patterns) {
let links = node.getElementsByTagName('a');
for (let i = 0; i < links.length; ++i) {
rwLink(links[i]);
}
}
(function () {
document.addEventListener('DOMNodeInserted', function (event) {
if (event && event.target &&(event.target instanceof HTMLElement)) {
let node = event.target;
if (node instanceof HTMLAnchorElement) {
rwLink(node);
}
rwLinksInNode(node);
}
}, false);
})();
rwLinksInNode(document);
})();