// ==UserScript==
// @name Замена на URL 1.2
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Заменяет "начисление за товар <ID>" на URL товара и "Списание за заказ №..." на URL заказа
// @match https://www.ozon.ru/my/points*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ozon.ru
// @grant none
// ==/UserScript==
(function() {
'use strict';
const processed = new WeakSet();
const SELECTOR = 'div.i7y_27';
function replaceIdsWithLinks() {
/* console.log('Селектор найден:', document.querySelectorAll('div.i7y_27').length);
document.querySelectorAll('div.i7y_27').forEach(div => {
console.log('Текст в div:', div.innerText);
});*/
document.querySelectorAll(SELECTOR).forEach(div => {
if (processed.has(div)) return;
const text = div.innerText || '';
let newHTML = div.innerHTML;
let modified = false;
// Проверяем начисление за товар
const productRegex = /Начисление за товар (\d+)\b/i;
const productMatch = text.match(productRegex);
if (productMatch && productMatch[1]) {
const id = productMatch[1];
const url = `https://www.ozon.ru/product/${id}/`;
const linkHTML = `<a href="${url}" target="_blank">${url}</a>`;
newHTML = newHTML.replace(productRegex, linkHTML);
modified = true;
}
// Иначе проверяем списание за заказ
else {
const orderRegex = /Списание за заказ №([\d-]+)\b/i;
const orderMatch = text.match(orderRegex);
if (orderMatch && orderMatch[1]) {
const orderId = orderMatch[1];
const url = `https://www.ozon.ru/my/orderdetails/?order=${orderId}`;
// const linkHTML = `<a href="${url}" target="_blank">${url}</a>`;
// newHTML = newHTML.replace(orderRegex, linkHTML);
newHTML = newHTML.replace(
new RegExp(orderId, 'g'),
`<a href="${url}" target="_blank">${orderId}</a>`
);
modified = true;
}
}
if (modified) {
div.innerHTML = newHTML;
processed.add(div);
}
});
}
// Используем MutationObserver вместо setInterval
const observer = new MutationObserver(replaceIdsWithLinks);
observer.observe(document.body, { childList: true, subtree: true });
window.addEventListener('load', replaceIdsWithLinks);
})();