-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_aliexpress.user.js
53 lines (46 loc) · 1.53 KB
/
global_aliexpress.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
// ==UserScript==
// @name Global Aliexpress
// @namespace Perlovka/userscripts
// @homepageURL https://github.com/Perlovka/userscripts
// @downloadURL https://github.com/Perlovka/userscripts/raw/master/global_aliexpress/global_aliexpress.user.js
// @updateURL https://github.com/Perlovka/userscripts/raw/master/global_aliexpress/global_aliexpress.user.js
// @version 1.0.1
// @match *://*
// @include *://*
// @run-at document-end
// @grant GM_xmlhttpRequest
// ==/UserScript==
function stripUrl(url) {
return url.split('?')[0];
}
function changeUrl(url) {
return stripUrl(url).replace('ru.aliexpress.com', 'www.aliexpress.com');
}
function unRefer(url, link_id) {
let result = GM_xmlhttpRequest ( {
method: "GET",
url: url,
onload: function (res) {
// console.log('Referral link found: ' + url + ' ->\n\n' + res.finalUrl + ' ->\n\n' + changeUrl(res.finalUrl));
links.snapshotItem(link_id).href = changeUrl(res.finalUrl);
},
onerror: function (res) {console.log(res.statusText);}
} );
}
var links = document.evaluate("//a[contains(@href, 'ru.aliexpress.com') or contains(@href, 'ali.pub')]",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
for (var i=0; i<links.snapshotLength; i++) {
let link = links.snapshotItem(i);
let url = link.href;
if (url.match('ru.aliexpress.com')) {
link.href = changeUrl(url);
link.innerHTML = stripUrl(url);
// console.log('Direct link found: ' + url + ' -> ' + stripUrl(url));
}
else {
unRefer(url, i);
}
}