-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.js
More file actions
141 lines (108 loc) · 4.86 KB
/
Copy pathstrings.js
File metadata and controls
141 lines (108 loc) · 4.86 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const finalPriceWrappers = document.querySelectorAll('[data-price-type="finalPrice"]');
finalPriceWrappers.forEach((wrapper, index, array) =>
{
const currentPriceElement = wrapper.querySelector('.price');
const nextWrapper = array[index + 1];
if (currentPriceElement && nextWrapper)
{
const nextPriceElement = nextWrapper.querySelector('.price');
if (nextPriceElement)
{
const nextPriceText = nextPriceElement.textContent.trim();
const nextPrice = parseFloat(nextPriceText.replace(/[^\d.]/g, ''));
const message = document.createElement('div');
message.style.color = 'blue';
message.style.fontWeight = 'bold';
message.style.fontSize = '15px';
if (nextPrice < 30)
{
message.textContent = 'Next product price is less than €30';
}
else if (nextPrice === 30)
{
message.textContent = "Next product price is €30";
}
else
{
message.textContent = 'Next product price is greater than €30';
}
currentPriceElement.insertAdjacentElement('afterend', message);
}
}
});
//Script For Swapping the default images and hover images
document.querySelectorAll('ol.products.list.items.product-items.row.row-wrapper.row-4').forEach(ol =>
{
document.querySelectorAll('.product-item-image').forEach(container =>
{
const defaultimage = container.querySelector('img.product-image-photo');
const hoverimage = container.querySelector('img.img-hover-show');
if (defaultimage && hoverimage)
{
const tempSrc = defaultimage.src;
defaultimage.src = hoverimage.src;
hoverimage.src = tempSrc;
}
});
});
// Script to print the label in right side of the products
document.querySelectorAll('.product-item-image').forEach(imageContainer =>
{
const existingLabel = imageContainer.querySelector('.label-text span');
if (!existingLabel) {
// Create container div
const labelContainer = document.createElement('div');
labelContainer.className = 'mgn-product-label product-label-container bot-left shape-new-2';
labelContainer.style = 'width:96px; height:0; padding-bottom:96px; --space-y: 4px;';
// Create shape wrapper
const shapeWrapper = document.createElement('div');
shapeWrapper.className = 'shape-wrapper shape-new-2';
// Create SVG icon
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('fill', '#f0c0c2');
svg.setAttribute('style', 'height:32px');
svg.setAttribute('class', 'svg-icon');
svg.setAttribute('viewBox', '0 0 180 60');
svg.setAttribute('xml:space', 'preserve');
const use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
use.setAttribute('x', '0');
use.setAttribute('y', '0');
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#shape-new-2');
svg.appendChild(use);
const labelTextDiv = document.createElement('div');
labelTextDiv.className = 'label-text';
labelTextDiv.style = 'font-size:15px;color:#ffffff;';
const labelSpan = document.createElement('span');
labelSpan.textContent = 'Old';
labelTextDiv.appendChild(labelSpan);
shapeWrapper.appendChild(svg);
shapeWrapper.appendChild(labelTextDiv);
labelContainer.appendChild(shapeWrapper);
imageContainer.appendChild(labelContainer);
}
});
// Script for printing the names of the label in product title
document.querySelectorAll('ol.products.list.items.product-items.row.row-wrapper.row-4 li.item.product').forEach(product =>
{
const nameAnchor = product.querySelector('.product-item-link');
const labelSpan = product.querySelector('.label-text span');
if (labelSpan)
{
let labelText = labelSpan.textContent
if(labelText !== 'Old')
nameAnchor.innerHTML = `${nameAnchor.textContent} <strong> + ${labelText} </strong>`;
}
});
//Script to print the page title below the products
const pageTitle = document.querySelector('.page-title .base')?.textContent;
document.querySelectorAll('[data-price-type="finalPrice"]').forEach(priceSpan =>
{
const titleDiv = document.createElement('div');
titleDiv.textContent = pageTitle;
titleDiv.style.fontSize = '20px';
titleDiv.style.color = '#444';
titleDiv.style.fontStyle = 'bolder';
titleDiv.style.textAlign = 'center';
titleDiv.style.margin = '4px auto';
priceSpan.parentNode.insertBefore(titleDiv, priceSpan.nextSibling);
});