BTS2 - Tooltipy (UserScript+Tippy.js)

Zobrazuje čiarové kódy v pravom dolnom rohu, ideálne na rýchle naskenovanie bez nutnosti jeho vytlačenia

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         BTS2 - Tooltipy (UserScript+Tippy.js)
// @namespace    BTS2, amazon, tooltip, barcode, kod
// @version      0.2
// @description  Zobrazuje čiarové kódy v pravom dolnom rohu, ideálne na rýchle naskenovanie bez nutnosti jeho vytlačenia
// @author       AA z BTS2
// @require      https://cdn.jsdelivr.net/npm/[email protected]/build/browser/io-barcode.min.js
// @require      https://unpkg.com/[email protected]/dist/tippy.all.min.js
// @match        file:///*/LPN*.htm
// @match        http://*/index.html
// @include      http://fcresearch-eu.aka.amazon.com/*/results?*
// @include      https://fcresearch-eu.aka.amazon.com/*/results?*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var findThese = [ 'LPN', 'csX', 'ts', 'spl00', 'ZZ', 'P-1-' ];  // case-sensitive!

    var style_text =
        '.tippy-tooltip.mytooltip-theme {-webkit-box-shadow: 0px 0px 14px 4px rgba(0,0,0,0.6); -moz-box-shadow: 0px 0px 14px 4px rgba(0,0,0,0.6); box-shadow: 0px 0px 14px 4px rgba(0,0,0,0.6)}\n'+
        '.tippy-tooltip.mytooltip-theme {border: 1px solid orange; background: #FDD6AE; padding: 10px 0 5px 0; border-radius: 16px}';

    function ready(fn){
        if (document.attachEvent ? document.readyState === 'complete' : document.readyState !== 'loading') fn();
        else document.addEventListener('DOMContentLoaded', fn);
    }

    function appendStyle(styles){
        var css = document.createElement('style');
        css.type = 'text/css';
        if (css.styleSheet) css.styleSheet.cssText = styles;
        else css.appendChild(document.createTextNode(styles));
        document.body.appendChild(css);
    }

    function generateCode(text){
        var canvas,
            img = new Image(),
            options = {width: 1, height: 40, quite: 15, displayValue: true, font: 'monospace', fontSize: 16, fontWeight: 'bold', textAlign: 'center'};
        canvas = ioBarcode.CODE128B(text, options);
        img.src = canvas.toDataURL('image/png');
        return "<img src=\'"+img.src+"\'>";
    }

    function makeLiveLinks(id, column){
        var destElm = document.getElementById(id);
        if (destElm){
            //var base_link = 'http://fcresearch-eu.aka.amazon.com/BTS2/results?s=';
            var base_link = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?s=';
            var noLinksArray = [].slice.call(destElm.querySelectorAll('td[data-type=\"'+column+'\"]'));
            noLinksArray.forEach(function(elm){
                var text = elm.textContent;
                elm.innerHTML = '<a href=\"'+base_link+text+'\">'+text+'</a>';
            });
        }
    }

    function findLinks(){
        makeLiveLinks('inventory', 'lpn');
        var linksArray = [].slice.call(document.querySelectorAll('a'));
        var goodLinksArray = linksArray.filter(function(elm){
            var linkText = elm.textContent;
            for (var i = 0, length = findThese.length; i < length; i++){
                if (linkText.match('^'+findThese[i])) return elm;
            }
        });
        console.log(goodLinksArray);
        goodLinksArray.forEach(function(elm){
            elm.title = generateCode(elm.textContent);
        });
    }

    ready(function(){
        appendStyle(style_text);
        findLinks();
        tippy('a[title]', {theme: 'mytooltip', animation: 'fade', performance: true, animateFill: false});
    });

})();