PageSourceSearch

https://www.kansai-td.co.jp/common/js/jquery.bytes2km.js

js kansai-td.co.jp collected 2026-10-02 04:11:30 UTC 1,686 bytes, 56 lines download raw bytes

1{
2    globalThis.UtilityTools = globalThis.UtilityTools || {};
3
4    const formatBytesToSize = byteString => {
5        // カンマを除去して数値に変換
6        const bytes = parseFloat(byteString.replace(/,/g, ''));
7
8        if (isNaN(bytes) || bytes === 0) return "0.00 B";
9
10        const k = 1024;
11        const sizes = ['', 'K', 'M', 'G', 'T'];
12
13        // どの単位を適用するか計算 (log1024(bytes))
14        const i = Math.floor(Math.log(bytes) / Math.log(k));
15
16        // 単位変換して小数点第2位で固定
17        const convertedValue = (bytes / Math.pow(k, i)).toFixed(2);
18
19        return `${convertedValue}${sizes[i]}`;
20    };
21
22    UtilityTools.formatBytesToSize = formatBytesToSize;
23
24    (function ($) {
25        $.fn.bytes2km = function (settings) {
26            var _settings = $.extend({
27                m: 1024 * 1024
28            }, settings),
29                _this = $(this);
30
31            _this.each(function () {
32                var _this = $(this),
33                    _text = _this.text().trim();
34
35                if (_text.match(/an error/)) {
36                    _this.html(_this.html().replace(/\[an error[^\]]+\]/, '0.00'));
37                    return true;
38                }
39
40                const match = /(?:\[PDF ([\d,]+)B\]|^([\d, ]+)B$)/.exec(_text);
41
42                if (!match) {
43                    return true;
44                }
45
46                const _size = formatBytesToSize(_text);
47
48                _this.html(_this.html().replace(/ ?[\d,]+B/,`${_size}B`));
49            });
50        }
51    }(jQuery));
52
53    $(function () {
54        $(".filesize_auto").bytes2km();
55    });
56}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.