selection length | 选中计字数

鼠标拖选显示选中字数

< selection length | 选中计字数についてのフィードバック

質問/コメント

§
投稿日: 2015/07/23
編集日: 2015/07/23

GM : "Selection Length" seems useful! (i tweak it for french people)..

I you are interesting , i join it here my "bad" translation.
It is not an perfect translation, but can help to test your script for french people...

Feel free to correct it
:-)

§
投稿日: 2015/07/23
編集日: 2015/07/31

I forget to join my French Translation (because the join function of the Forum seems not working) :

// ==UserScript==
// @name        selection length | 选中计字数 | Comptage des mots Sélectionnés (TWEAK FRENCH)
// @namespace   hzhbest
// @description    鼠标拖选显示选中字数 / Glissez la souris Afficher les mots sélectionnés
// @include     https://*
// @include     http://*
// @version     1.1
// @grant       none
// ==/UserScript==

(function() {

    document.addEventListener('mouseup', function(e) {
        setTimeout(function(){count(e);},150);
    }, false);

    var tooltip =  creaElemIn('div', document.body);
    tooltip.id = "sl_tooltip";  
    var timer, content, overed = false;
    var timeout = 1000;

    // Insert CSS
    var headID = document.getElementsByTagName('head')[0];         
    var cssNode = creaElemIn('style', headID);
    cssNode.type = 'text/css';
    cssNode.innerHTML = '#sl_tooltip {display: none; position: fixed; z-index: 999999; font-size: 12pt; background: white; border: 1px solid #ddecff; box-shadow: 0 1px 3px #333;} #sl_tooltip.show{display: block;} #sl_tooltip table{line-height: 12pt; border-collapse: collapse; border-spacing: 0; font-size: 10pt;}';


function count(e) {
    if (overed) return;
    var ae = document.activeElement;     //console.log(ae.value + "|" + ae.selectionStart + "|" + ae.selectionEnd);
    if (ae.tagName.toLowerCase() == "input" || ae.tagName.toLowerCase() == "textarea") {
        content = ae.value.substring(ae.selectionStart, ae.selectionEnd);
    } else {
        content = getSelection().toString();
    }
    var selCount = content.length;
    if (selCount == 0) return;
        //借用一字数统计脚本代码
            var cvalue=content.replace(/\r\n/g,"\n");
            var sarr=cvalue.split("");
            var len_total=sarr.length;
            var r={
                "wd":0,  //中英文字数    // Nombre de Mots anglais
                "nwd":0,  //英数词数     // Nombre de mot
                "nb":0,  //数字词数      // Nombre de mot numérique
                "c":0,  //字符数         // Nombre de caractères
                "cb":0,  //非空格字符    // Nombre d'espace
                "r":0,  //回车           // Nombre de Retour à la ligne ? (entrer)
                "en":0,  //英文字母数    // Nombre de mots Anglais ?
                "cn":0,  //中文字数      // Nombre de mots chinois
                "bl":0  //非回车空格     // Non- Entrez espaces ??
            };
            var words=cvalue.match(/\w+([’\']\w+)?/g)||[];
            var numbers=cvalue.match(/\b\d+(\.\d+)?\b/g)||[];
            var cnwords=cvalue.match(/[\u4e00-\u9fa5]/g)||[];
            r.nwd=words.length;
            r.nb=numbers.length;
            r.cn=cnwords.length;
            for(var i=0;i<len_total;i++){
                r.c++;
                switch(true){
                    case /[a-zA-Z]/.test(sarr[i]):
                        r.en++;
                        break;
                    case /\S/.test(sarr[i]):
                        r.cb++;
                        break;
                    case /\s/.test(sarr[i]):
                        if(sarr[i]=="\n"||sarr[i]=="\r"){
                            r.r++;
                        }else{
                            r.bl++;
                        }
                }
            }
            r.wd=r.nwd+r.cn;
            var str="Statistiques de caractères<br/>";
            str+="<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
            str+="<tr><td algin='left'>Nombre Total de Caractères:</td><td align='right'> "+(r.c-r.r)+"</td></tr>";
            // str+="<tr><td algin='left'>Caractères vides:</td><td align='right'>"+(r.c-r.bl-r.r)+"</td></tr>";
            str+="<tr><td algin='left'>Caractères Vides:</td><td align='right'> "+r.bl+"</td></tr>";
            str+="<tr><td algin='left'>Caractères Chinois:</td><td align='right'> "+r.en+"</td></tr>";
            str+="<tr><td algin='left'>Autres Caractères:</td><td align='right'> "+(r.c-r.en-r.bl-r.cn-r.r)+"</td></tr>";
            // str+="<tr><td algin='left'>&nbsp;</td><td align='right'>&nbsp;</td></tr>";
            str+="<tr><td algin='left'>Nombre de chiffres:</td><td align='right'> "+r.wd+"</td></tr>";
            str+="<tr><td algin='left'>Nombre de Caractères Chinois:</td><td align='right'> "+r.cn+"</td></tr>";
            str+="<tr><td algin='left'>Nombre de Mots Anglais:</td><td align='right'> "+(r.nwd-r.nb)+"</td></tr>";
            str+="<tr><td algin='left'>Nombre de Chiffres Arabes:</td><td align='right'> "+r.nb+"</td></tr>";
            // str+="<tr><td algin='left'>&nbsp;</td><td align='right'>&nbsp;</td></tr>";
            str+="<tr><td algin='left'>Nombre de Retour à la ligne :</td><td align='right'> "+(r.r+1)+"</td></tr>";
            str+="</table>";
    tooltip.innerHTML = str;
    // tooltip.innerHTML = getSelection().toString();  //for debug
    tooltip.className = "show";
    tooltip.style.top = Math.min(e.clientY + 10, window.innerHeight - tooltip.offsetHeight) + "px";
    tooltip.style.left = Math.min(e.clientX + 20, window.innerWidth - 150) + "px";

    function hide(){
        tooltip.className = '';
        tooltip.removeEventListener('mouseover', over, false);
        tooltip.removeEventListener('mouseout', out, false);
    }
    function over() {
        overed = true;
        clearTimeout(timer);
    }
    function out() {
        overed = false;
        timer = setTimeout(hide, timeout);
    }
    tooltip.addEventListener('mouseover', over, false);
    tooltip.addEventListener('mouseout', out, false);
    timer = setTimeout(hide, timeout * 3);
}


// Create an element
function creaElemIn(tagname, destin) {
    var theElem = destin.appendChild(document.createElement(tagname));
    return theElem;
}


})();
hzhbest作者
§
投稿日: 2015/07/27

Thank you! But I need accurate translation to post a new French fork for this script, since I am not good at French. May you?

§
投稿日: 2015/07/28
編集日: 2015/07/29

I am but ...not :
i don't understand all the technical expression about words etc..

I put a "?" after each.

by example :
Caractères vides / Non- Entrez espaces / Nombre de Chiffres Arabes

Can you translate your script in english ?

hzhbest作者
§
投稿日: 2015/07/29

Well...
Actually I wrote this script to do a word-count approach on web pages similar to MS Word, and since I am a Chinese, I used codes dedicated to count Chinese characters. So this script is not "internationallized" enough.
Maybe I will do an international version (surely in English), later. Then you can translate from that version.

§
投稿日: 2015/07/29

;-)

Suggestion:
Add a key - or an icon we can put in a toolbar (like ThumbnailZoomPlus) - to enable / disable it.

hzhbest作者
§
投稿日: 2015/07/30
;-)

Suggestion:
Add a key - or an icon we can put in a toolbar (like ThumbnailZoomPlus) - to enable / disable it.

To make an icon I will have to convert it to an add-on, which I think is not that necessary, since GM menu is capable. I had made a hotkey mechanism into v1.2, you can try it when uploaded.
btw, the international ver. will come a bit later.

§
投稿日: 2015/07/31

;-)

返信を投稿

返信を投稿するにはログインしてください。