js实现html代码中无用css过滤去除工具代码

代码语言:html

所属分类:其他

代码描述:js实现html代码中无用css过滤去除工具代码

代码标签: js html 代码 无用 css 过滤 去除 工具 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8" />
  <title>HTML 一键瘦身:仅保留页面用到的 CSS</title>
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <style>
    :root {
      --bg: #0f172a;
      --panel: #111827;
      --muted: #94a3b8;
      --text: #e5e7eb;
      --accent: #22c55e;
      --border: #334155;
      --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
              "Courier New", monospace;
    }
    html, body {
      height: 100%;
      margin: 0;
      background: #0b1220;
      color: var(--text);
      font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
    }
    .wrap {
      max-width: 1200px;
      margin: 24px auto 40px;
      padding: 0 16px;
    }
    h1 { margin: 6px 0 8px; font-size: 22px; letter-spacing: .3px; }
    .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
    .card {
      background: rgba(17,24,39,.66);
      border: 1px solid var(--border);
      border-radius: 12px;
      box-shadow: 0 10px 30px rgba(0,0,0,.25);
      overflow: hidden;
      margin-top: 12px;
    }
    .card header {
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,0));
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .card header h3 { margin: 0; font-size: 14px; color: #cbd5e1; }
    .card .body { padding: 0; }
    textarea {
      width: 100%;
      min-height: 320px;
      box-sizing: border-box;
      background: #0b1020;
      color: #f3f4f6;
      border: none;
      outline: none;
      resize: vertical;
      padding: 12px 14px;
      font-size: 13px;
      line-height: 1.6;
      font-family: var(--mono);
    }
    textarea[readonly] { opacity: .95; }
    .toolbar {
      display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
      margin: 12px 0 10px;
    }
    button {
      background: #0b1220;
      color: var(--text);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px 14px;
      font-size: 14px;
      cursor: pointer;
      transition: transform .04s ease, border-color .15s ease, background .2s ease, opacity .2s ease;
      user-select: none;
    }
    button:hover { border-color: #3d4451; }
    button:active { transform: translateY(1px); }
    button.primary {
      background: linear-gradient(180deg, #16a34a, #16a34a 40%, #0f9a43);
      border-color: #16a34a;
      color: #fff;
      font-weight: 600;
      letter-spacing: .3px;
    }
    button:disabled { opacity: .5; cursor: not-allowed; }
    .stats { color: #cbd5e1; font-size: 13px; letter-spacing: .2px; margin-left: 8px; }
    .badge {
      display: inline-block;
      padding: 2px 8px; border-radius: 999px; font-size: 12px; margin-left: 6px;
      color: #03220f; background: #86efac; border: 1px solid #22c55e;
    }
    .grid {
      display: grid; gap: 12px; grid-template-columns: 1fr; margin-top: 12px;
    }
    @media (min-width: 1000px) {
      .grid { grid-template-columns: 1.1fr .9fr; }
    }
    iframe {
      width: 100%; height: 360px; border: 1px solid var(--border); border-radius: 10px; background: #fff;
    }
    .foot { margin-top: 10px; color: var(--muted); font-size: 12px; }
    details {
      margin-top: 8px; background: rgba(2,6,23,.4); border: 1px dashed #334155; border-radius: 10px; padding: 8px 12px;
    }
    details summary { cursor: pointer; }
    .opts { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
    .opts label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
    .opts input[type="checkbox"] { width: 16px; height: 16px; accent-color: #16a34a; }
  </style>
</head>
<body>
  <div class="wrap">
    <h1>HTML 一键瘦身:仅保留页面用到的 CSS</h1>
    <div class="sub">粘贴包含 &lt;style&gt; 的 HTML,然后点击“生成”。工具会静态分析 HTML 中实际用到的选择器,过滤掉未使用的 CSS,并生成可预览/可复制的新 HTML。</div>

    <section class="card">
      <header>
        <h3>HTML 输入(包含 &lt;style&gt; 标签)</h3>
        <span class="badge" id="presetTip" style="display:none;">已加载示例</span>
      </header>
      <div class="body">
        <textarea id="htmlInput" spellcheck="false" placeholde.........完整代码请登录后点击上方下载按钮下载查看

网友评论0