BTS2 - Tooltipy (UserScript+Tippy.js)

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

スクリプトをインストールするには、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         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});
    });

})();