rob4iks3gmail.com / SmartBear1A 2.0 XML Get Info

// ==UserScript==
// @name         SmartBear1A 2.0 XML Get Info
// @namespace    http://tampermonkey.net/
// @version      3.0
// @description  SmartBear1A 2.0 XML Get Info
// @author       Robis
// @match        https://smartbear.1a.lv/roby/external_categories/product?id=*
// @grant        none
// @licence      GPL-3.0
// ==/UserScript==

(function () {
    'use strict';

    function autoCopy() {

        $(function () {
            var extCategory = $("td:contains('Ext. Category Code:')"), //Finds Ext. Category Code and replaces with
                extBrand = $("td:contains('Ext. Brand Code:')"); //Ext. Category, so that it is possible to later find Product Code
            extCategory.html('Ext. Category');

            extBrand.html('Ext. Brand');
        });

        $(function () {
            //Finds Code and copies it into local storage variable
            var codeFind = $("td:contains('Code')"),
                codeFindVal = codeFind.next().html();
            localStorage.setItem("codeFindVal", codeFindVal);

            var stockFind = $("td:contains('Quantity In Stock:')"),
                stockFindVal = stockFind.next().html();
            localStorage.setItem("stockFindVal", stockFindVal);

            var priceFind = $("td:contains('Price w/o VAT:')"),
                priceFindVal = priceFind.next().html();
            localStorage.setItem("priceFindVal", priceFindVal);

			var warrantyFind= $("td:contains('Warranty In Months:')"),
                warrantyFindVal = warrantyFind.next().html();
            localStorage.setItem("warrantyFindVal",  warrantyFindVal);

        });

    }

    function buttonFind() {
        
        var findButtonContainer = document.createElement('div');
        findButtonContainer.id = ('findButtonContainer');

        var createNewProduct = document.createElement('span');
        createNewProduct.id = ('button_CreateNewProduct');
        createNewProduct.className = ('buttonXML');
        createNewProduct.innerHTML = ('<a href="https://smartbear.1a.lv/products/create_new" target="_blank">Create New Product</a>');


        var buttonFindEAN = document.createElement('span'),
            EANFind = $("td:contains('EAN')"),
            EANFindVal = EANFind.next().html().split(' ').join('');

        buttonFindEAN.id = ('button_CompareEAN');
        buttonFindEAN.className = ('buttonXML');
        buttonFindEAN.innerHTML = ('<a href="https://smartbear.1a.lv/products?search[is_submited]=1&search[text]=&search[cat_id]=&search[brd_id]=&search[status]=&search[search_category_attribute_value]=&search[apr_id]=&search[has_linked_ext_product]=&search[has_available_product_in_local_warehouse]=&search[product_availablility]=&search[unavailable_dty_id]=&search[ean_code]=' + EANFindVal + '&search[ext_supp_id]=&search[product_price_modifier_status]=&search[created_sus_id]=&search[actual_pcm_active_from_from_date]=&search[actual_pcm_active_from_to_date]=&search[has_competitor_price]=&search[has_temporary_sell_price]=" target="_blank">Check by EAN</a>');

        var buttonFindCode = document.createElement('span'),
            FindCode = $("td:contains('Code')"),
            FindCodeVal = FindCode.next().html().split(' ').join('');

        buttonFindCode.id = ('button_CompareCode');
        buttonFindCode.className = ('buttonXML');
        buttonFindCode.innerHTML = ('<a href="https://smartbear.1a.lv/products?search[is_submited]=1&search[text]=' + FindCodeVal + '&search[cat_id]=&search[brd_id]=&search[status]=&search[search_category_attribute_value]=&search[apr_id]=&search[has_linked_ext_product]=&search[has_available_product_in_local_warehouse]=&search[product_availablility]=&search[unavailable_dty_id]=&search[ean_code]=&search[ext_supp_id]=&search[product_price_modifier_status]=&search[created_sus_id]=&search[actual_pcm_active_from_from_date]=&search[actual_pcm_active_from_to_date]=&search[has_competitor_price]=&search[has_temporary_sell_price]=" target="_blank">Check by Code</a>');

        var buttonFindName = document.createElement('span'),
            FindName = $("td:contains('Name')"),
            FindNameVal = FindName.next().html();

        buttonFindName.className = ('buttonXML');
        buttonFindName.innerHTML = ('<a href="https://smartbear.1a.lv/products?search[is_submited]=1&search[text]=' + FindNameVal + '&search[cat_id]=&search[brd_id]=&search[status]=&search[search_category_attribute_value]=&search[apr_id]=&search[has_linked_ext_product]=&search[has_available_product_in_local_warehouse]=&search[product_availablility]=&search[unavailable_dty_id]=&search[ean_code]=&search[ext_supp_id]=&search[product_price_modifier_status]=&search[created_sus_id]=&search[actual_pcm_active_from_from_date]=&search[actual_pcm_active_from_to_date]=&search[has_competitor_price]=&search[has_temporary_sell_price]=" target="_blank">Check by Name</a>');
		
		 var buttonFindBrand = document.createElement('span');
		 var brandFind = $("td:contains('Ext. Brand Name')"),
             brandFindVal = brandFind.next().html();
		
            localStorage.setItem("brandFindVal", brandFindVal);
		 buttonFindBrand.className = ('buttonXML');
		 buttonFindBrand.innerHTML = ('<a target="_blank" href="https://www.google.com/search?q=' + brandFindVal +' '+FindCodeVal +  '">Find in Google</a>');

        $(findButtonContainer).insertBefore('#ext_product_main_data');

        findButtonContainer.appendChild(createNewProduct);
        findButtonContainer.appendChild(buttonFindName);
        if (EANFindVal != 0) {
            findButtonContainer.appendChild(buttonFindEAN);
        }
        findButtonContainer.appendChild(buttonFindCode);
		findButtonContainer.appendChild(buttonFindBrand);
    }

    // Activation of Scripts
    autoCopy();
    buttonFind();
})();