统计一个页面用到的html,css,js

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计html</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            user-select: none;
        }

        body {
            background: #0b1b2c;
        }

        #app {
            display: flex;
        }

        #textareaCount {
            margin: 5px 100px;
        }

        div {
            color: aliceblue;
        }

        div li {
            list-style: none;
            margin: 5px;
        }
    </style>
</head>

<body>
    <div id="app">
        <textarea id="textareaCount" class="textarea1" name="textareaCSS" rows="8" cols="50"
            placeholder="在这里输入HTML内容"></textarea>
        <dl>
            <dt id="countHTML">HTML标签数量:0。</dt>
            <dt>用到的标签有:</dt>
            <dd id="appHTML"></dd>
        </dl>
        <dl>
            <dt id="countCSS">CSS属性数量: 0。</dt>
            <dt>用到的属性有:</dt>
            <dd id="appCSS"></dd>
            
        </dl>
        <dl>
            <dt id="countJS">JS函数和变量数量: 0。</dt>
            <dt>用到的函数和变量有:</dt>
            <dd id="appJS"></dd>
        </dl>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            document.getElementById('textareaCount').addEventListener('input', function () {
                const textareaCount = this.value;

                // 正则表达式匹配所有 HTML 标签
                const tagRegex = /<(\w+)[^>]*>/g;
                const htmlTags = textareaCount.match(tagRegex) || [];
              console.log(htmlTags);
                document.getElementById('countHTML').innerText = `HTML标签数量: ${htmlTags.length}。`;

                const tags = [];

                let match;
                while ((match = tagRegex.exec(textareaCount)) !== null) {
                    tags.push(match[1]);
                }

                // 将数组去重并排序
                const tagList = Array.from(new Set(tags)).sort();

                const appHTML = document.getElementById('appHTML');
                const ulHTML = document.createElement('ul');
                appHTML.innerHTML = ''; // 清空之前的列表
                appHTML.appendChild(ulHTML);

                tagList.forEach((tag, index) => {
                    const li = document.createElement('li');
                    li.textContent = `${index + 1}. ${tag}`;
                    ulHTML.appendChild(li);
                });

                // 正则表达式匹配所有 CSS 属性
                const propertyRegex = /([a-zA-Z-]+)\s*:/g;
                const cssProperties = textareaCount.match(propertyRegex) || [];
                document.getElementById('countCSS').innerText = `CSS属性数量: ${cssProperties.length}。`;
                const properties = [];

                while ((match = propertyRegex.exec(textareaCount)) !== null) {
                    properties.push(match[1]);
                }

                // 将数组去重并排序
                const propertyList = Array.from(new Set(properties)).sort();

                const appCSS = document.getElementById('appCSS');
                const ulCSS = document.createElement('ul');
                appCSS.innerHTML = ''; // 清空之前的列表
                appCSS.appendChild(ulCSS);

                propertyList.forEach((property, index) => {
                    const li = document.createElement('li');
                    li.textContent = `${index + 1}. ${property}`;
                    ulCSS.appendChild(li);
                });
                console.log(properties);

                // 正则表达式匹配所有 JS 关键字
                const jsWordRegex = /(function\s+\w+|var\s+\w+|let\s+\w+|const\s+\w+)/g;
                const jsFunctions = textareaCount.match(jsWordRegex) || [];
                document.getElementById('countJS').innerText = `JS函数和变量数量: ${jsFunctions.length}。`;

                const jsWords = [];

                while ((match = jsWordRegex.exec(textareaCount)) !== null) {
                    jsWords.push(match[0]);
                }

                // 将数组去重并排序
                const sortedJsWords = Array.from(new Set(jsWords)).sort();
                console.log(sortedJsWords);

                const appJS = document.getElementById('appJS');
                const ulJS = document.createElement('ul');
                appJS.innerHTML = ''; // 清空之前的列表
                appJS.appendChild(ulJS);

                sortedJsWords.forEach((word, index) => {
                    const li = document.createElement('li');
                    li.textContent = `${index + 1}. ${word}`;
                    ulJS.appendChild(li);
                });
            });
        });
    </script>
</body>

</html>

相关推荐

  1. 如何 Redis 中 HyperLogLog 统计页面 UV?

    2024-07-17 19:04:03       57 阅读
  2. C#多页面一个实例

    2024-07-17 19:04:03       29 阅读
  3. python+vue实现一个计算页面

    2024-07-17 19:04:03       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 19:04:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 19:04:03       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 19:04:03       58 阅读
  4. Python语言-面向对象

    2024-07-17 19:04:03       69 阅读

热门阅读

  1. 什么是HTTP协议攻击

    2024-07-17 19:04:03       20 阅读
  2. AnyConv OGG 转换器:轻松转换音频格式

    2024-07-17 19:04:03       23 阅读
  3. Local Cache(二)demo

    2024-07-17 19:04:03       18 阅读
  4. Git简要笔记

    2024-07-17 19:04:03       19 阅读
  5. 爬虫-存储数据

    2024-07-17 19:04:03       22 阅读
  6. Windows的包管理器Chocolatey

    2024-07-17 19:04:03       21 阅读
  7. 渗透测试前景怎么样

    2024-07-17 19:04:03       22 阅读
  8. 区块链技术的应用场景和优势

    2024-07-17 19:04:03       19 阅读
  9. 摘要算法介绍

    2024-07-17 19:04:03       23 阅读
  10. 如何规避苹果开发者账户关联

    2024-07-17 19:04:03       22 阅读
  11. golang笔记-流程控制

    2024-07-17 19:04:03       20 阅读