2016-05-13 01:00:21 -04:00
|
|
|
(function () {
|
2016-05-13 01:29:08 -04:00
|
|
|
var targets = document.querySelectorAll('p, li, h1, h2, h3, h4, h5, h6, header, a, button, small');
|
2016-05-13 01:00:21 -04:00
|
|
|
_.each(targets, function (node) {
|
|
|
|
if (isTranslationResult(node)) {
|
|
|
|
var prevNode = node.previousElementSibling;
|
2016-05-13 01:29:08 -04:00
|
|
|
if (prevNode && isOriginalEnglish(prevNode.innerText) && !prevNode.classList.contains('nav-list-item')) {
|
|
|
|
prevNode.classList.add('lang-english');
|
2016-05-13 01:00:21 -04:00
|
|
|
}
|
|
|
|
node.title = prevNode.innerText;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function isOriginalEnglish(text) {
|
2016-05-13 01:29:08 -04:00
|
|
|
return /^[\1-\255—]*$/.test(text);
|
2016-05-13 01:00:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function isClonedNode(node1, node2) {
|
|
|
|
return node1.parentNode === node2.parentNode && node1.tagName === node2.tagName && node1.className === node2.className;
|
|
|
|
}
|
|
|
|
|
|
|
|
function indexOf(node) {
|
|
|
|
var i = 0;
|
|
|
|
var aNode = node.parentNode.firstChild;
|
|
|
|
while (aNode !== node) {
|
|
|
|
++i;
|
|
|
|
if (aNode.tagName !== node.tagName) {
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
aNode = aNode.nextElementSibling;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isTranslationResult(node) {
|
|
|
|
var prevNode = node.previousElementSibling;
|
|
|
|
return indexOf(node) % 2 === 1 && prevNode && isClonedNode(node, prevNode) && isOriginalEnglish(prevNode.innerText);
|
|
|
|
}
|
|
|
|
})();
|