v26110232 问题页小 Banner + 热度/正在看/看过;专题页工具固定模块 + 相关推荐 3 个 + 评论区;首页「进孕妈广场」「全部 30 份测试」

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-02 13:21:48 +00:00
parent a21c3ace47
commit 0a74cfc83f
115 changed files with 257 additions and 26 deletions

View File

@@ -26,6 +26,98 @@
'.tt-w{font-size:12.5px;color:#4E5969;margin-top:2px;line-height:1.5}.tt-go{flex:0 0 auto;font-size:13px;font-weight:700;color:var(--tt-c,#18A058);padding:6px 12px;border-radius:99px;background:var(--tt-bg,#F7F8FA)}';
function href(u) { return u + (location.search || '') + (location.hash || ''); }
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"]/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]; }); }
/* 11-02 用户:推荐工具做成固定模块,下面再推荐 3 个相关专题,再下面是评论区(预置评论 + 用户可评)。
* 104 个专题页都走 render(),所以统一在这里追加,页面不用改。
* 预置评论是 AI 写的模拟评论(AGENTS.md 12c),数据 cm/<slug>.json;用户自己发的只存本机 mmbox.tp.v1。 */
var css2 = '.tt-wrap{padding:16px 14px 14px;border-radius:22px;background:var(--tt-bg,#F7F8FA);border:0}.tt-wrap .tt-it{border-color:transparent;box-shadow:0 4px 14px -10px rgba(31,35,41,.25)}' +
'.tt-h b{display:flex;align-items:center;gap:6px}.tt-h b::before{content:"";width:4px;height:16px;border-radius:4px;background:var(--tt-c,#18A058)}' +
'.tx-sec{margin:26px 0 8px}.tx-sec>.tt-h{margin-bottom:12px}' +
'.tr-list{display:flex;flex-direction:column;gap:10px}.tr-it{display:flex;align-items:center;gap:12px;padding:10px;border-radius:16px;background:#fff;border:1px solid #EEF0F3;text-decoration:none;-webkit-tap-highlight-color:transparent}' +
'.tr-it:active{transform:scale(.98)}.tr-it img{flex:0 0 64px;width:64px;height:64px;border-radius:12px;object-fit:cover;background:#F2F3F5}' +
'.tr-tx{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}.tr-tx b{font-size:15px;font-weight:700;line-height:1.45;color:#1F2329;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}' +
'.tr-tx span{font-size:12px;color:#86909C;display:flex;gap:8px;align-items:center}.tr-tx em{font-style:normal;font-size:11px;font-weight:600;padding:1px 7px;border-radius:99px;background:var(--tt-bg,#F2F3F5);color:var(--tt-c,#18A058)}.tr-go{color:#C9CDD4;font-size:18px}' +
'.tc-in{display:flex;gap:8px;align-items:flex-end;margin-bottom:6px;padding:8px 8px 8px 14px;border-radius:18px;background:#F7F8FA}' +
'.tc-in textarea{flex:1;min-width:0;border:0;background:transparent;resize:none;font-size:14px;line-height:1.6;font-family:inherit;color:#1F2329;height:24px;max-height:96px;outline:0;padding:4px 0}' +
'.tc-in button{flex:0 0 auto;height:32px;padding:0 14px;border:0;border-radius:99px;background:var(--tt-c,#18A058);color:#fff;font-size:13px;font-weight:700}.tc-in button:disabled{opacity:.35}' +
'.tc-it{display:flex;gap:10px;padding:14px 0;border-bottom:1px solid #F2F3F5}.tc-it:last-child{border-bottom:0}.tc-av{flex:0 0 34px;width:34px;height:34px;border-radius:50%;object-fit:cover;background:#F2F3F5}' +
'.tc-me{display:flex;align-items:center;justify-content:center;font-size:13px;font-weight:800;color:#fff;background:var(--tt-c,#18A058)}' +
'.tc-b{flex:1;min-width:0}.tc-n{display:flex;align-items:center;gap:6px;font-size:13px;color:#86909C;line-height:1.4}.tc-n b{font-weight:600;color:#4E5969}.tc-n i{font-style:normal;font-size:11px;padding:0 6px;border-radius:99px;background:#F2F3F5}' +
'.tc-t{margin-top:4px;font-size:14.5px;line-height:1.7;color:#1F2329;word-break:break-word}' +
'.tc-f{display:flex;justify-content:flex-end;margin-top:2px}.tc-lk{display:inline-flex;align-items:center;gap:3px;border:0;background:none;padding:2px 0;font-size:12px;color:#86909C}.tc-lk svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.8}' +
'.tc-lk.on{color:#F2533A}.tc-lk.on svg{fill:currentColor}' +
'.tc-r{margin-top:6px;padding:8px 10px;border-radius:12px;background:#F7F8FA;font-size:13.5px;line-height:1.65;color:#4E5969}.tc-r p+p{margin-top:4px}.tc-r b{font-weight:600;color:#1F2329}' +
'.tc-more{display:block;width:100%;margin-top:6px;height:40px;border:0;border-radius:99px;background:#F7F8FA;color:#4E5969;font-size:13px;font-weight:600}';
var SLUG = (location.pathname.match(/\/topic\/([^\/]+)\//) || [])[1] || '';
var SK = 'mmbox.tp.v1', UK = (function () { var m = ((location.hash || '') + '&' + (location.search || '')).match(/[#?&]openid=([^&]*)/); return m ? decodeURIComponent(m[1]) : '_guest'; })();
function loadMe() { try { var a = JSON.parse(localStorage.getItem(SK) || '{}') || {}; var m = a[UK] || {}; m.cm = m.cm || {}; m.lk = m.lk || {}; return { a: a, m: m }; } catch (e) { return { a: {}, m: { cm: {}, lk: {} } }; } }
function saveMe(st) { try { st.a[UK] = st.m; localStorage.setItem(SK, JSON.stringify(st.a)); } catch (e) {} }
function avP(a) { return typeof a === 'number' ? '../../guangchang/av/' + ('000' + a).slice(-4) + '.webp' : '../../assets/img/mom/' + a + '.jpg'; }
function wan(n) { return n >= 1e4 ? (Math.round(n / 1e3) / 10) + '万' : String(n); }
var HEART = '<svg viewBox="0 0 24 24"><path d="M12 20s-7-4.4-7-10a4 4 0 017-2.6A4 4 0 0119 10c0 5.6-7 10-7 10z"/></svg>';
function getJSON(u) { return fetch(u, { cache: 'no-cache' }).then(function (r) { if (!r.ok) throw r.status; return r.json(); }); }
function related(box) {
getJSON('../_shared/idx.json?v=26110232').then(function (idx) {
var me = null; idx.forEach(function (x) { if (x[0] === SLUG) me = x; });
var tag = me ? me[2] : '', h = 0; for (var i = 0; i < SLUG.length; i++) h = (h * 31 + SLUG.charCodeAt(i)) >>> 0;
var rest = idx.filter(function (x) { return x[0] !== SLUG; });
var same = rest.filter(function (x) { return x[2] === tag; }).sort(function (a, b) { return b[3] - a[3]; });
/* 同类按热度取前几里轮换,凑不够 3 个用全站热门补 */
var pick = [], top = same.slice(0, 6);
for (var k = 0; k < top.length && pick.length < 3; k++) pick.push(top[(h + k) % top.length]);
rest.sort(function (a, b) { return b[3] - a[3]; }).forEach(function (x) { if (pick.length < 3 && pick.indexOf(x) < 0) pick.push(x); });
box.innerHTML = '<div class="tt-h"><b>相关推荐</b><span>其他妈妈也在看</span></div><div class="tr-list">' + pick.map(function (x) {
return '<a class="tr-it" href="' + esc(href('../' + x[0] + '/')) + '"><img src="../' + esc(x[0]) + '/img/hero.webp" alt="" loading="lazy">' +
'<span class="tr-tx"><b>' + esc(x[1]) + '</b><span>' + (x[2] ? '<em>' + esc(x[2]) + '</em>' : '') + wan(Math.round(1510000 * x[3])) + ' 人看过</span></span><span class="tr-go">›</span></a>';
}).join('') + '</div>';
}).catch(function () { box.remove(); });
}
function comments(box) {
var st = loadMe(), L = [], open = false;
function mine() { return st.m.cm[SLUG] || []; }
function item(c, key) {
var lk = !!st.m.lk[key];
return '<div class="tc-it">' + (c.me ? '<span class="tc-av tc-me">我</span>' : '<img class="tc-av" src="' + esc(avP(c[1])) + '" alt="" loading="lazy">') +
'<div class="tc-b"><div class="tc-n"><b>' + esc(c.me ? '我' : c[0]) + '</b>' + (c.me ? '<i>刚刚</i>' : (c[2] ? '<i>' + esc(c[2]) + '</i>' : '')) + '</div>' +
'<div class="tc-t">' + esc(c.me ? c.t : c[3]) + '</div>' +
(!c.me && c[5] && c[5].length ? '<div class="tc-r">' + c[5].map(function (r) { return '<p><b>' + esc(r[0]) + ':</b>' + esc(r[3]) + '</p>'; }).join('') + '</div>' : '') +
'<div class="tc-f"><button type="button" class="tc-lk' + (lk ? ' on' : '') + '" data-k="' + esc(key) + '">' + HEART + '<span>' + ((c.me ? 0 : c[4]) + (lk ? 1 : 0) || '赞') + '</span></button></div></div></div>';
}
function paint() {
var my = mine().slice().reverse(), n = L.length + my.length, show = open ? L : L.slice(0, 5);
box.innerHTML = '<div class="tt-h"><b>大家怎么说</b><span>' + n + ' 条评论</span></div>' +
'<div class="tc-in"><textarea rows="1" maxlength="200" placeholder="说说你的情况,和其他妈妈聊聊…"></textarea><button type="button" disabled>发布</button></div>' +
'<div class="tc-list">' + my.map(function (c, i) { return item({ me: 1, t: c.t }, 'me' + c.ts); }).join('') +
show.map(function (c, i) { return item(c, SLUG + '#' + i); }).join('') + '</div>' +
(!open && L.length > 5 ? '<button type="button" class="tc-more">展开全部 ' + n + ' 条评论</button>' : '');
var ta = box.querySelector('textarea'), bt = box.querySelector('.tc-in button');
ta.addEventListener('input', function () { bt.disabled = !ta.value.trim(); ta.style.height = '24px'; ta.style.height = Math.min(96, ta.scrollHeight) + 'px'; });
bt.addEventListener('click', function () {
var v = ta.value.trim(); if (!v) return;
(st.m.cm[SLUG] = mine()).push({ t: v.slice(0, 200), ts: Date.now() }); saveMe(st); paint();
});
var mo = box.querySelector('.tc-more'); if (mo) mo.addEventListener('click', function () { open = true; paint(); });
[].forEach.call(box.querySelectorAll('.tc-lk'), function (b) {
b.addEventListener('click', function () { var k = b.dataset.k; if (st.m.lk[k]) delete st.m.lk[k]; else st.m.lk[k] = 1; saveMe(st); paint(); });
});
}
getJSON('../_shared/cm/' + SLUG + '.json?v=26110232').then(function (d) { L = d.c || []; paint(); }).catch(function () { paint(); });
}
function extras(el) {
if (!SLUG || document.getElementById('tx-rel')) return;
if (!document.getElementById('tx-css')) { var s = document.createElement('style'); s.id = 'tx-css'; s.textContent = css2; document.head.appendChild(s); }
var a = document.createElement('section'); a.id = 'tx-rel'; a.className = 'tx-sec';
var b = document.createElement('section'); b.id = 'tx-cm'; b.className = 'tx-sec';
el.parentNode.insertBefore(b, el.nextSibling); el.parentNode.insertBefore(a, b);
var c = getComputedStyle(el);
[a, b].forEach(function (x) { x.style.marginLeft = c.marginLeft; x.style.marginRight = c.marginRight; });
a.style.setProperty('--tt-c', c.getPropertyValue('--tt-c')); a.style.setProperty('--tt-bg', c.getPropertyValue('--tt-bg'));
b.style.setProperty('--tt-c', c.getPropertyValue('--tt-c')); b.style.setProperty('--tt-bg', c.getPropertyValue('--tt-bg'));
related(a); comments(b);
}
function render(el, list, opt) {
if (!el) return;
opt = opt || {};
@@ -42,6 +134,7 @@
if (opt.color) el.style.setProperty('--tt-c', opt.color);
if (opt.bg) el.style.setProperty('--tt-bg', opt.bg);
el.innerHTML = '<div class="tt-h"><b>' + esc(opt.title || '用得上的工具') + '</b><span>' + esc(opt.sub || '都在兜爸心选,免费用') + '</span></div><div class="tt-list">' + html + '</div>';
extras(el);
}
window.TopicTools = { render: render, list: T, href: href };
})();