正在加载用户协议...
`;
+ let d = null;
+ try {
+ const res = await fetch('api/sync.php?action=rules_content', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ credentials: 'same-origin'
+ });
+ const json = await res.json();
+ if (json.success && json.data) d = json.data;
+ } catch (e) {
+ el.innerHTML = `协议加载失败:${e.message}
`;
+ return;
+ }
+ if (!d || d.skipped || !d.has_agreement) {
+ el.innerHTML = `
+
`;
+ return;
+ }
+ // 渲染:用 📜 用户协议
+服务器当前未配置用户协议(rules 目录无协议文件)。
+
+
`;
+ }
+
+ // 轻量 markdown → HTML(仅处理标题/无序列表/加粗/表格分隔线/引用/代码/链接,足够展示协议)
+ function renderMarkdownLite(md) {
+ if (!md) return '';
+ const lines = String(md).split('\n');
+ let html = '';
+ let inList = false;
+ const closeList = () => { if (inList) { html += ''; inList = false; } };
+ for (let raw of lines) {
+ let s = raw;
+ // 表格分隔线丢弃
+ if (s.trim().match(/^\|?[\s:|-]+\|?$/) && s.trim().length > 1 && s.includes('-')) { closeList(); continue; }
+ // 代码围栏 ``` 整行丢弃(json 动作配置已在后端剥离,双保险)
+ if (s.trim().startsWith('```')) { closeList(); continue; }
+ // 标题
+ if (s.match(/^#{1,6}\s/)) {
+ closeList();
+ const lvl = s.match(/^#+/)[0].length;
+ const txt = s.replace(/^#+\s*/, '');
+ const sz = Math.max(15, 22 - lvl);
+ html += `
+
+ 📜 ${esc(d.title || '服务器用户协议')}
+ +
+ ${renderMarkdownLite(d.content)}
+
+ 协议版本指纹:${esc(d.fingerprint || '')} | 共 ${d.line_count || 0} 行
+${esc(txt)}
`;
+ continue;
+ }
+ // 无序列表
+ if (s.match(/^\s*[-*+]\s+/)) {
+ if (!inList) { html += '- '; inList = true; }
+ const item = s.replace(/^\s*[-*+]\s+/, '');
+ html += `
- ${inlineMd(item)} `; + continue; + } + closeList(); + // 引用 + if (s.match(/^\s*>/)) { + html += `
${inlineMd(s.replace(/^\s*>\s?/, ''))}
`;
+ continue;
+ }
+ // 空行
+ if (s.trim() === '') { html += ''; continue; }
+ // 普通段落
+ html += `${inlineMd(s)}
`;
+ }
+ closeList();
+ return html;
+ }
+
+ // 行内 markdown:加粗/斜体/代码/链接
+ function inlineMd(s) {
+ let t = esc(s);
+ t = t.replace(/`([^`]*)`/g, '$1');
+ t = t.replace(/(\*\*|__)(.+?)\1/g, '$2');
+ t = t.replace(/(^|[^*])(\*)([^*]+)\*(?!\*)/g, '$1$3');
+ t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1');
+ return t;
}
// ==================== 债券在线充值(动态加载商品) ====================