mampizzu5
Опытный
скрипт на кликабельные названия товаровЕсть два товара из разных магазинов с одинаковыми картинками и названием, но в бзо только один.
Как понять какой отменять, а какой оставить?
Код:
// ==UserScript==
// @name Ozon Кликабельные названия товаров в БЗО
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Превращает названия товаров в ссылки на карточку (работает на основе SKU из чекбокса)
// @match https://www.ozon.ru/my/returnCreation/items*
// @icon https://www.ozon.ru/favicon.ico
// @grant none
// @run-at document-idle
// ==/UserScript==
(function f(){
document.querySelectorAll('span.tsCompact500Medium').forEach(span=>{
if(span.closest('a')||span.hasAttribute('data-ozon-linked'))return;
let container=span.closest('[class*="item"],[data-state]');
while(container&&!container.querySelector('input[name*="-sku-"]')&&container!==document.body)container=container.parentElement;
if(!container)return;
let cb=container.querySelector('input[type="checkbox"][name*="-sku-"]');
let m=cb&&cb.name.match(/-sku-(\d+)/);
if(!m)return;
let a=document.createElement('a');
a.href=`https://www.ozon.ru/product/${m[1]}/`;
a.target='_blank';
a.rel='noopener noreferrer';
a.textContent=span.textContent;
a.className=span.className;
a.style.cssText=span.style.cssText;
a.style.color='#005bff';
a.style.textDecoration='underline';
a.style.cursor='pointer';
a.style.setProperty('color','#005bff','important');
a.style.setProperty('text-decoration','underline','important');
span.parentNode.replaceChild(a,span);
a.setAttribute('data-ozon-linked','true');
});
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',f);
new MutationObserver(f).observe(document.body,{childList:true,subtree:true});
})();

