今天是2024年9月29日 第39周 星期日

代人,时大变了。

我们生活在大地上,但我们的梦想超越天空。

User:KomacyaN/js/Wordcount.js

来自Akarin
< User:KomacyaN
白龙讨论 | 贡献2022年10月31日 (一) 18:18的版本 (建立内容为“(function($) { function bytecount(text) { text = text.replace(/[\u0000-\u007F]/g, '.'); text = text.replace(/[\u0080-\u07FF\uD800-…”的新页面)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
(function($) {
        function bytecount(text) {
            text = text.replace(/[\u0000-\u007F]/g, '.');
            text = text.replace(/[\u0080-\u07FF\uD800-\uDFFF]/g, '..');
            text = text.replace(/[\u0800-\uD7FF\uE000-\uFFFF]/g, '...');
            return text.length;
        };
        function cjkcount(text) {
            text = text.replace(/\./g, '');
            text = text.replace(/[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DB5\u4E00-\u9FCC\uF900-\uFA6D\uFA70-\uFAD9]|[\uD840-\uD868][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|[\uD86A-\uD86C][\uDC00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]/g, '.');
            text = text.replace(/[^\.]/g, '');
            return text.length;
        };
        function getwcbytext(text) {
            return text.length + ' character(s) (' + cjkcount(text) + ' CJK)<br />' +
                bytecount(text) + ' byte(s) in UTF-8 encoding';
        };
        function getsel() {
            if (!window.getSelection) return '';
            return getSelection().toString();
        };
        function dowc(event) {
            $('.wordcount').remove(); // or remove after text.length == 0 checking?
            var text = getsel();
            if (text.length == 0) return;
            var divj = $('<div>').html(getwcbytext(text))
                .css({
                    'position': 'fixed',
                    'left': '0',
                    'bottom': '0',
                    'margin': '6px',
                    'padding': '8px',
                    "color": "whitesmoke",
                    "background": "rgb(255,165,0)",
                    "border": "transparent",
                    "z-index": "100"
                })
                .addClass('wordcount ui-state-highlight ui-corner-all')
                .appendTo('body');
                // we hook keyup, so this may make it flickering
                // eg when shift, ctrl.etc key up
                //.hide().fadeIn('slow');
            setTimeout(function() {
                divj.fadeOut('slow');
            }, 6666);
        };
        $(document).mouseup(dowc).keyup(dowc);
    })(jQuery);
//改自星海姐的[[User:星海子/js/Wordcount.js]],仅修改颜色。