-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aliexpress Auto translate disable.user.js
57 lines (57 loc) · 1.82 KB
/
Aliexpress Auto translate disable.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
// ==UserScript==
// @name Aliexpress Auto translate disable
// @description Disable auto translation in title and description for Aliexpress sites.
// @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.2
// @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 rwLink(link) {
if (link.href.indexOf('.aliexpress.com/item/') !== -1 ||
link.href.indexOf('.aliexpress.com/store/product/') !== -1) {
if (link.href.indexOf('isOrigTitle') == -1 &&
link.href.indexOf('isOrig') == -1) {
if (!replaceLinkPattern('?', '?isOrigTitle=true&isOrig=true&', link) &&
!replaceLinkPattern('#', '?isOrigTitle=true&isOrig=true#', link)) {
link.href += '?isOrigTitle=true&isOrig=true';
}
}
}
}
rwLink(location);
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);
})();