Ozon.ru Barcode

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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
    });
})();