您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
2023/12/28 12:37:19
// ==UserScript== // @name 有手就行的页面字符统计工具 // @namespace Violentmonkey Scripts // @grant GM_addStyle // @require https://unpkg.com/[email protected]/dist/jquery.min.js // @match *://*/* // @license AGPL-2.0-or-later // @version 1.1 // @author 猎隼丶止戈 // @description 2023/12/28 12:37:19 // ==/UserScript== (function () { 'use strict'; GM_addStyle('div.char-count{position: fixed;bottom: 5px;right: 5px;background: #e2e3e9;width: 100px;} div.char-count ul{margin: 5px;list-style: none;}'); function countWords(str) { const chinese = Array.from(str).filter(ch => /[\u4e00-\u9fa5]/.test(ch)).length; const english = Array.from(str).filter(ch => /[a-zA-Z]/.test(ch)).length; const num = Array.from(str).filter(ch => /\d/.test(ch)).length; return {'cn': chinese, 'en': english, 'num': num}; } $(function() { let text = $('body').text().replaceAll(/\t|\r|\n|\s/g, ''); let script = $('script').text().replaceAll(/\t|\r|\n|\s/g, ''); let content = text.replaceAll(script, '') let countObj = countWords(content); $('script').before(`<div class="char-count"><div>有手就行!</div><ul><li>中文:${countObj.cn}</li><li>英文:${countObj.en}</li><li>数字:${countObj.num}</li><ul></div>`); }); })();