Ozon.ru Barcode

Show retrieval barcode on ozon.ru orders list on desktop site

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name        Ozon.ru Barcode
// @namespace   Violentmonkey Scripts
// @match       https://www.ozon.ru/my/orderlist*
// @grant       none
// @version     1.0
// @author      szq2
// @run-at      document-end
// @description Show retrieval barcode on ozon.ru orders list on desktop site
// @license     0BSD
// ==/UserScript==


(function() {
    'use strict';

    // Function to find the code pattern and extract the actual code
    function findAndProcessCodes() {
        const codeRegex = /([\d\s*]+\d+)\s*—\s*код для получения в пунктах выдачи и постаматах Ozon/g;

        // Function to process text nodes
        function processTextNode(textNode) {
            const text = textNode.nodeValue;
            let match = codeRegex.exec(text);

            if (match) {
                // Extract the code from the matched text
                let code = match[1].replace(/\s+/g, '');

                // Create barcode image URL
                const imageUrl = `https://www.ozon.ru/api/my-account-api-gateway.bx/codes/v1/generate?code=${code}&height=208&type=bar&width=580`;

                // Create image element
                const img = document.createElement('img');
                img.src = imageUrl;
                img.style.display = 'block';
                img.style.marginTop = '10px';
                img.style.marginBottom = '10px';
                img.style.maxWidth = '100%';
                img.alt = `Barcode for ${code}`;

                // Insert the image after the text node
                const span = document.createElement('span');
                if(textNode == textNode.parentNode.lastChild)
                  textNode.parentNode.appendChild(span);
                else
                  textNode.parentNode.replaceChild(span, textNode.parentNode.lastChild);
                span.appendChild(img);
            }
        }

        // Walk through all text nodes in the document
        const walker = document.createTreeWalker(
            document.body,
            NodeFilter.SHOW_TEXT,
            null,
            false
        );

        let node;
        while (node = walker.nextNode()) {
            processTextNode(node);
        }
    }

    window.addEventListener('load', findAndProcessCodes);

    // Set up a mutation observer to handle dynamically loaded content
    const observer = new MutationObserver(function(mutations) {
        findAndProcessCodes();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: false
    });
})();