selection length | 选中计字数

鼠标拖选显示选中字数

目前為 2015-07-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name        selection length | 选中计字数
// @namespace   hzhbest
// @description    鼠标拖选显示选中字数
// @include     https://*
// @include     http://*
// @version     1.0
// @grant       none
// ==/UserScript==

(function() {

	document.addEventListener("mouseup", function(event) {
		setTimeout(function(){count(event);},150);
	}, false);
	
	var tooltip =  creaElemIn('div', document.body);
	tooltip.id = "sl_tooltip";	
	var timer;
	
	// 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; font-size: 16pt; background: white; border: 1px solid #ddecff; box-shadow: 0 1px 3px #333;} #sl_tooltip.show{display: block;}';


function count(e) {
	var selCount = getSelection().toString().length;
	if (selCount == 0) return;
	tooltip.innerHTML = selCount + "字";
	// tooltip.innerHTML = getSelection().toString();  //for debug
	tooltip.className = 'show';
	clearTimeout(timer);
	timer = setTimeout(function(){tooltip.className = '';},3000);
	tooltip.style.top = e.clientY + 10 + "px";
	tooltip.style.left = e.clientX + 20 + "px";
}


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


})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址