有手就行的页面字符统计工具

2023/12/28 12:37:19

  1. // ==UserScript==
  2. // @name 有手就行的页面字符统计工具
  3. // @namespace Violentmonkey Scripts
  4. // @grant GM_addStyle
  5. // @require https://unpkg.com/jquery@3.6.0/dist/jquery.min.js
  6. // @match *://*/*
  7. // @license AGPL-2.0-or-later
  8. // @version 1.1
  9. // @author 猎隼丶止戈
  10. // @description 2023/12/28 12:37:19
  11. // ==/UserScript==
  12. (function () {
  13. 'use strict';
  14.  
  15. GM_addStyle('div.char-count{position: fixed;bottom: 5px;right: 5px;background: #e2e3e9;width: 100px;} div.char-count ul{margin: 5px;list-style: none;}');
  16.  
  17. function countWords(str) {
  18. const chinese = Array.from(str).filter(ch => /[\u4e00-\u9fa5]/.test(ch)).length;
  19. const english = Array.from(str).filter(ch => /[a-zA-Z]/.test(ch)).length;
  20. const num = Array.from(str).filter(ch => /\d/.test(ch)).length;
  21. return {'cn': chinese, 'en': english, 'num': num};
  22. }
  23.  
  24. $(function() {
  25. let text = $('body').text().replaceAll(/\t|\r|\n|\s/g, '');
  26. let script = $('script').text().replaceAll(/\t|\r|\n|\s/g, '');
  27. let content = text.replaceAll(script, '')
  28. let countObj = countWords(content);
  29. $('script').before(`<div class="char-count"><div>有手就行!</div><ul><li>中文:${countObj.cn}</li><li>英文:${countObj.en}</li><li>数字:${countObj.num}</li><ul></div>`);
  30. });
  31. })();

QingJ © 2025

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