BTS2 - Tooltipy (UserScript+Tippy.js)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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});
    });

})();