Nintendo Switch ИГРИ | GamesMania.bg (страница 2 от 9)
.
* Only runs on successful checkout; doesn't alter totals, translations,
* products, payment forms, orders, or event/tracking scripts.
*/
(function () {
'use strict';
function init() {
if (!document.body || !document.body.classList.contains('dynamic-page-checkout_final_success')) return;
var root = document.getElementById('checkout-success');
if (!root || root.classList.contains('gm-checkout-ready')) return;
var message = root.querySelector('.c-checkout-final-page__success-message');
var heading = root.querySelector('.c-order-details__heading');
var pageContent = root.querySelector('.o-page-content');
var orderDetails = root.querySelector('#order-details');
if (!message || !heading || !pageContent || !orderDetails) return;
// 1) Decorative success hero: MOVE existing nodes, don't copy or rewrite texts.
var hero = document.createElement('section');
hero.className = 'gm-checkout-hero';
var left = document.createElement('div');
left.className = 'gm-success-left';
var mark = document.createElement('span');
mark.className = 'gm-success-mark';
mark.setAttribute('aria-hidden', 'true');
mark.innerHTML = '';
left.appendChild(mark);
// Preserve EVERY original translated text node and line in the message.
// Styling individual lines is only enabled when Seliton supplied
lines.
var nodes = Array.prototype.slice.call(message.childNodes);
var separators = nodes.filter(function (node) { return node.nodeName === 'BR'; });
if (separators.length >= 2) {
var rows = [], row = document.createElement('span');
nodes.forEach(function (node) {
if (node.nodeName === 'BR') {
rows.push(row);
row = document.createElement('span');
} else {
row.appendChild(node);
}
});
rows.push(row);
message.textContent = '';
rows.forEach(function (item, idx) {
item.className = 'gm-success-row gm-success-row--' + (idx + 1);
message.appendChild(item);
});
}
pageContent.insertBefore(hero, message);
left.appendChild(message);
hero.appendChild(left);
hero.appendChild(heading);
// 2) Only suppress heading duplicates if both original labels match.
[
['.c-order-details__payment-info-title', '.c-order-details__payment-method-title'],
['.c-order-details__shipping-info-title', '.c-order-details__shipping-method-title']
].forEach(function (pair) {
var first = orderDetails.querySelector(pair[0]);
var second = orderDetails.querySelector(pair[1]);
if (first && second && first.textContent.trim() === second.textContent.trim()) {
second.classList.add('gm-duplicate-label');
}
});
// Hide notes header only if Seliton output no notes after the header.
var notesTitle = orderDetails.querySelector('.c-order-details__payment-notes-title');
if (notesTitle) {
var parent = notesTitle.parentElement;
var hasContent = false;
var sibling = notesTitle.nextSibling;
while (sibling) {
if ((sibling.nodeType === 3 && sibling.textContent.trim()) ||
(sibling.nodeType === 1 && sibling.textContent.trim())) {
hasContent = true; break;
}
sibling = sibling.nextSibling;
}
if (!hasContent) notesTitle.classList.add('gm-empty-notes');
}
// 3) Seliton can output an escaped literal "
" in carrier office text.
// Replace only those literal line breaks with real BR nodes, not HTML parsing.
var shippingInfo = orderDetails.querySelector('.c-order-details__shipping-info');
if (shippingInfo) Array.prototype.slice.call(shippingInfo.childNodes).forEach(function (node) {
if (node.nodeType !== 3 || !/
/i.test(node.nodeValue)) return;
var pieces = node.nodeValue.split(/
/i);
var fragment = document.createDocumentFragment();
pieces.forEach(function (piece, i) {
if (i) fragment.appendChild(document.createElement('br'));
fragment.appendChild(document.createTextNode(piece));
});
shippingInfo.replaceChild(fragment, node);
});
// 4) Responsive price labels are COPIED from the existing translated
// product column headers; no hard-coded translations or prices.
var header = orderDetails.querySelector('.c-order-details__products-columns-titles');
var columnSpec = [
['.c-order-details__products-qty', '.c-order-details__products-quantity-title'],
['.c-order-details__products-discounts-wrapper', '.c-order-details__products-discount-title'],
['.c-order-details__products-price-wrapper', '.c-order-details__products-price-title'],
['.c-order-details__products-total-price-wrapper', '.c-order-details__products-total-title']
];
if (header) orderDetails.querySelectorAll('.c-order-details__products-list').forEach(function (product) {
columnSpec.forEach(function (spec) {
var cell = product.querySelector(spec[0]);
var label = header.querySelector(spec[1]);
if (cell && label) cell.setAttribute('data-gm-label', label.textContent.trim() + ':');
});
});
// 5) Move ORIGINAL print button, preserving onclick="print()".
// Added buttons reuse translated labels/URLs already on this exact page.
var print = root.querySelector('.c-checkout-final-page__print-order');
if (print) {
var actions = document.createElement('nav');
actions.className = 'gm-checkout-actions';
actions.setAttribute('aria-label', 'Order actions');
function addExistingLink(source, primary) {
if (!source || !source.getAttribute('href')) return;
var link = document.createElement('a');
link.className = 'gm-checkout-action' + (primary ? ' gm-checkout-action--primary' : '');
link.href = source.href;
link.textContent = source.textContent.trim();
actions.appendChild(link);
}
var bread = document.querySelector('.c-breadcrumb');
if (bread) {
var crumbLinks = bread.querySelectorAll('a.c-breadcrumb__item-link');
addExistingLink(crumbLinks[0], true);
addExistingLink(crumbLinks[1], false);
}
print.parentNode.insertBefore(actions, print);
actions.appendChild(print);
}
root.classList.add('gm-checkout-ready');
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();