PageSourceSearch

https://zhaohongxuan.github.io/js/icons.js?v=1.44.0

js zhaohongxuan.github.io collected 2026-10-03 10:14:36 UTC 1,940 bytes, 60 lines download raw bytes

1/**
2 * icons.js | 非首屏图标异步加载
3 *
4 * 服务端 icon() 对非首屏 SVG 图标输出 <svg class="icon" data-icon="ns:key"> 占位符,
5 * 本脚本按命名空间拉取构建期生成的 js/icons/{ns}.json,成功后原位替换为完整内联 SVG,
6 * 最终 DOM 与全量内联一致,现有 CSS 钩子(搜索三态、菜单渐变、chat 着色等)不受影响。
7 * 首屏关键图标(搜索、菜单、leftbar/rightbar、arrow-left)由模板内联,不经过本脚本。
8 */
9(function () {
10  'use strict';
11
12  const nodes = Array.prototype.slice.call(document.querySelectorAll('svg.icon[data-icon]'));
13  if (nodes.length === 0) {
14    return;
15  }
16
17  const groups = {};
18  nodes.forEach((node) => {
19    const key = node.getAttribute('data-icon');
20    const idx = key.indexOf(':');
21    if (idx < 1) {
22      return;
23    }
24    const ns = key.slice(0, idx);
25    if (!groups[ns]) {
26      groups[ns] = [];
27    }
28    groups[ns].push(node);
29  });
30
31  const script = document.currentScript;
32  const version = (script && script.getAttribute('data-version')) || '';
33  const root = (typeof ctx !== 'undefined' && ctx.root) || '/';
34
35  Object.keys(groups).forEach((ns) => {
36    const url = root + 'js/icons/' + ns + '.json' + (version ? '?v=' + version : '');
37    fetch(url)
38      .then((res) => {
39        if (!res.ok) {
40          throw new Error('HTTP ' + res.status);
41        }
42        return res.json();
43      })
44      .then((data) => {
45        const set = data && data[ns];
46        groups[ns].forEach((node) => {
47          const key = node.getAttribute('data-icon');
48          const svg = set && set[key];
49          if (typeof svg === 'string' && svg.length > 0) {
50            node.outerHTML = svg;
51          } else {
52            console.warn('[stellar] icon not found: ' + key);
53          }
54        });
55      })
56      .catch((err) => {
57        console.warn('[stellar] icons load failed: ' + ns, err);
58      });
59  });
60})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.