-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreat.js
74 lines (64 loc) · 2.65 KB
/
treat.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
(function () {
'use strict';
var next,
walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
function fadeOut(el, callback){
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= .1) < 0) {
el.style.display = 'none';
callback();
}
else {
requestAnimationFrame(fade);
}
})();
}
function fadeIn(el, display){
el.style.opacity = 0;
el.style.display = display || 'block';
(function fade() {
var val = parseFloat(el.style.opacity);
if (!((val += .1) > 1)) {
el.style.opacity = val;
requestAnimationFrame(fade);
}
})();
}
function animatedReplace(el, text) {
var display = el.parentNode.style.display;
fadeOut(el.parentNode, function onFaded() {
el.textContent = text;
fadeIn(el.parentNode, display);
});
}
while (next = walk.nextNode()) {
if (/Get Yourself a Little Something/i.test(next.textContent) !== false) {
animatedReplace(next, 'Treat Yo\'self!');
}
else if (/For a night in/.test(next.textContent) !== false) {
animatedReplace(next, 'For a night of Treatin\' Yo\'self!');
}
else if (/Inspired by your Wish List/.test(next.textContent) !== false) {
animatedReplace(next, 'Suggested ways to Treat Yo\'self!');
}
else if (/More top picks for you/.test(next.textContent) !== false) {
animatedReplace(next, 'Even more ways to Treat Yo\'self!');
}
else if (/Everyday made easier/.test(next.textContent) !== false) {
animatedReplace(next, 'Make your life easier by TREATIN\' YO\'SELF!');
}
else if (/Inspired by your shopping trends/.test(next.textContent) !== false) {
animatedReplace(next, 'Inspired by previous Treat Yo\'self moments');
}
else if (/Recommendations for you in/.test(next.textContent) !== false) {
animatedReplace(next, next.textContent.replace('Recommendations for you in', 'Ways for you to Treat Yo\'self in'));
}
else if (/Recommended for You in/.test(next.textContent) !== false) {
animatedReplace(next, next.textContent.replace('Recommended for You in', 'Ways for you to Treat Yo\'self in'));
}
else if (/Recommendations for You/.test(next.textContent) !== false) {
animatedReplace(next, next.textContent.replace('Recommendations for You', 'Ways to Treat Yo\'self'));
}
}
}());