125续15l-8: 登录页协议弹窗做markdown渲染, 不再干巴巴
之前弹窗直接 textContent 端原文(裸###/裸-/裸**), 到php高度自由化了还做不出渲染 修复: - login.php 新增 renderMarkdownLite+inlineMd+esc(与player.php同范式), 标题/列表/加粗/斜体/代码/引用/链接 - 弹窗 body 改 innerHTML 渲染, 占位文本(加载中/失败/未配置)仍用 textContent 防注入 - .ag-body white-space pre-wrap→normal, 加 markdown 渲染样式(ag-h/ag-h2/ag-h3/ag-quote/code/li) 渲染验证: player.md 标题分级/列表/加粗/代码/引用块全部正常
This commit is contained in:
@@ -91,9 +91,18 @@ require_once __DIR__ . '/captcha_guard.php';
|
|||||||
.ag-modal .ag-close { cursor: pointer; color: var(--dim); font-size: 20px; line-height: 1; }
|
.ag-modal .ag-close { cursor: pointer; color: var(--dim); font-size: 20px; line-height: 1; }
|
||||||
.ag-body {
|
.ag-body {
|
||||||
padding: 14px 18px; overflow-y: auto; flex: 1;
|
padding: 14px 18px; overflow-y: auto; flex: 1;
|
||||||
font-size: 13px; line-height: 1.75; color: var(--text); white-space: pre-wrap;
|
font-size: 13px; line-height: 1.75; color: var(--text); white-space: normal;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
/* 协议 markdown 渲染样式(标题/列表/加粗/引用/代码/段落) */
|
||||||
|
.ag-body h1, .ag-body .ag-h { font-size: 18px; font-weight: 700; color: var(--accent); margin: 14px 0 8px; }
|
||||||
|
.ag-body .ag-h2 { font-size: 15px; font-weight: 700; color: var(--accent); margin: 12px 0 6px; }
|
||||||
|
.ag-body .ag-h3 { font-size: 14px; font-weight: 600; color: var(--text); margin: 10px 0 5px; }
|
||||||
|
.ag-body ul { margin: 6px 0 8px 4px; padding-left: 18px; }
|
||||||
|
.ag-body li { margin: 3px 0; }
|
||||||
|
.ag-body .ag-quote { border-left: 3px solid var(--yellow); padding: 6px 12px; margin: 8px 0; background: rgba(210,153,34,0.08); border-radius: 4px; }
|
||||||
|
.ag-body code { background: rgba(136,136,136,0.2); padding: 1px 5px; border-radius: 3px; font-size: 0.9em; }
|
||||||
|
.ag-body .ag-p { margin: 4px 0; }
|
||||||
.ag-foot {
|
.ag-foot {
|
||||||
padding: 12px 18px; border-top: 1px solid var(--border);
|
padding: 12px 18px; border-top: 1px solid var(--border);
|
||||||
display: flex; justify-content: space-between; align-items: center; gap: 10px;
|
display: flex; justify-content: space-between; align-items: center; gap: 10px;
|
||||||
@@ -333,7 +342,7 @@ require_once __DIR__ . '/captcha_guard.php';
|
|||||||
const res = await fetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'} });
|
const res = await fetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'} });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.success && data.data && data.data.has_agreement && (data.data.content || '').trim() !== '') {
|
if (data.success && data.data && data.data.has_agreement && (data.data.content || '').trim() !== '') {
|
||||||
body.textContent = data.data.content;
|
body.innerHTML = renderMarkdownLite(data.data.content); // ★ 渲染 markdown(标题/列表/加粗/引用)
|
||||||
document.getElementById('agModalTitle').textContent = data.data.title || AG.title;
|
document.getElementById('agModalTitle').textContent = data.data.title || AG.title;
|
||||||
AG_LOADED = true; // ★ 原文到位
|
AG_LOADED = true; // ★ 原文到位
|
||||||
AG_HAS_CONTENT = true; // ★ 有实际内容
|
AG_HAS_CONTENT = true; // ★ 有实际内容
|
||||||
@@ -402,6 +411,62 @@ require_once __DIR__ . '/captcha_guard.php';
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 点「我已完成阅读」→ 关闭弹窗并自动勾选
|
// 点「我已完成阅读」→ 关闭弹窗并自动勾选
|
||||||
|
// ===== 轻量 markdown → HTML 渲染(登录弹窗用,无外部依赖,与 player.php 同范式)=====
|
||||||
|
function renderMarkdownLite(md) {
|
||||||
|
if (!md) return '';
|
||||||
|
const lines = String(md).split(/\r?\n/);
|
||||||
|
let html = '';
|
||||||
|
let inList = false;
|
||||||
|
const closeList = () => { if (inList) { html += '</ul>'; 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; }
|
||||||
|
// 标题 #/##/###
|
||||||
|
const hm = s.match(/^(#{1,6})\s+(.*)$/);
|
||||||
|
if (hm) {
|
||||||
|
closeList();
|
||||||
|
const lvl = hm[1].length;
|
||||||
|
const cls = lvl <= 2 ? (lvl === 1 ? 'ag-h' : 'ag-h2') : 'ag-h3';
|
||||||
|
html += `<div class="${cls}">${inlineMd(hm[2])}</div>`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 无序列表 -/*/+
|
||||||
|
if (s.match(/^\s*[-*+]\s+/)) {
|
||||||
|
if (!inList) { html += '<ul>'; inList = true; }
|
||||||
|
const item = s.replace(/^\s*[-*+]\s+/, '');
|
||||||
|
html += `<li>${inlineMd(item)}</li>`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
closeList();
|
||||||
|
// 引用 >
|
||||||
|
if (s.match(/^\s*>/)) {
|
||||||
|
html += `<div class="ag-quote">${inlineMd(s.replace(/^\s*>\s?/, ''))}</div>`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 空行
|
||||||
|
if (s.trim() === '') { html += '<div style="height:8px"></div>'; continue; }
|
||||||
|
// 普通段落
|
||||||
|
html += `<div class="ag-p">${inlineMd(s)}</div>`;
|
||||||
|
}
|
||||||
|
closeList();
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 行内 markdown:加粗/斜体/代码/链接
|
||||||
|
function inlineMd(s) {
|
||||||
|
let t = esc(s);
|
||||||
|
t = t.replace(/`([^`]*)`/g, '<code>$1</code>');
|
||||||
|
t = t.replace(/(\*\*|__)(.+?)\1/g, '<b>$2</b>');
|
||||||
|
t = t.replace(/(^|[^*])(\*)([^*]+)\*(?!\*)/g, '$1<i>$3</i>');
|
||||||
|
t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener" style="color:var(--accent);text-decoration:underline">$1</a>');
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
// HTML 转义
|
||||||
|
function esc(s) { return String(s ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
|
||||||
|
|
||||||
// ★ 防绕过二次校验:必须 AG_LOADED && AG_HAS_CONTENT && (AG_READ 或 AG.already),否则拒绝
|
// ★ 防绕过二次校验:必须 AG_LOADED && AG_HAS_CONTENT && (AG_READ 或 AG.already),否则拒绝
|
||||||
function confirmAgreement() {
|
function confirmAgreement() {
|
||||||
if (!AG_LOADED || !AG_HAS_CONTENT) {
|
if (!AG_LOADED || !AG_HAS_CONTENT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user