悄悄话留言标题后小头像:最新留言真人头像排前,补位随机且每 5 秒换一个,60 秒拉新留言 (v26110637)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26110636';
|
||||
var VER = '26110637';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
|
||||
@@ -168,3 +168,5 @@ p.wcm-mf{display:block;color:#FFC07A}
|
||||
.wcs-avs:empty{display:none}
|
||||
.wcs-avs img{width:18px;height:18px;border-radius:50%;object-fit:cover;border:1.5px solid #3A2C57;background:#4A3A6A}
|
||||
.wcs-avs img+img{margin-left:-7px}
|
||||
.wcs-avs img{transition:transform .26s ease,opacity .26s ease}.wcs-avs img.out{transform:scale(.4);opacity:0}.wcs-avs img.nw{animation:wavIn .45s cubic-bezier(.3,1.6,.5,1)}
|
||||
@keyframes wavIn{from{transform:scale(.3);opacity:0}}
|
||||
|
||||
46
js/wh-cm.js
46
js/wh-cm.js
@@ -69,7 +69,7 @@
|
||||
function repOf(c, me) { return { p: c.parent, n: me ? '我' : (c.nickname || '孕妈'), me: me, to: c.parentName, t: c.text, ts: c.at, st: me ? c.status : '' }; }
|
||||
function load() {
|
||||
if (loading || SIM) return; loading = true;
|
||||
fetch('guangchang/cm.json?v=26110636').then(function (r) { return r.json(); }).then(function (j) {
|
||||
fetch('guangchang/cm.json?v=26110637').then(function (r) { return r.json(); }).then(function (j) {
|
||||
var PP = j.p;
|
||||
SIM = (j.c[PID] || []).map(function (c, k) {
|
||||
var p = PP[c[0]];
|
||||
@@ -87,6 +87,7 @@
|
||||
if (R.starLikes) STAR_N = R.starLikes;
|
||||
/* 11-07 用户改:别人的只出审核通过的;自己发的审核中也显示(标「审核中」,只有自己看得到),没通过的不出 */
|
||||
var mine = (R.mine || []).filter(function (c) { return c.status !== 'rejected'; });
|
||||
avRealFrom((R.list || []).filter(top).concat(mine.filter(function (c) { return top(c) && c.status === 'approved'; })));
|
||||
REAL = (R.list || []).filter(top).map(realOf).concat(mine.filter(top).map(function (c) { var o = realOf(c); o.n = '我'; o.me = 1; o.st = c.status; return o; }));
|
||||
RREP = (R.list || []).filter(function (c) { return !top(c); }).map(function (c) { return repOf(c, 0); })
|
||||
.concat(mine.filter(function (c) { return !top(c); }).map(function (c) { return repOf(c, 1); }));
|
||||
@@ -179,12 +180,47 @@
|
||||
function total() { return (REAL ? REAL.length : 0) + (SIM ? SIM.length : 0); }
|
||||
function paintGo() {
|
||||
document.getElementById('wcmN').textContent = total() ? total() + ' 条' : '';
|
||||
/* 11-07 用户:「妈妈们的留言」后面加 6~8 个小头像 —— 取最热的 8 位 */
|
||||
var av = document.getElementById('wcmAv');
|
||||
if (av && SIM && SIM.length && !av.firstChild) av.innerHTML = SIM.slice().sort(function (a, b) { return b.likes - a.likes; }).slice(0, 8)
|
||||
.map(function (c) { return '<img src="' + esc(c.av) + '" alt="" onerror="this.remove()">'; }).join('');
|
||||
avPaint();
|
||||
document.getElementById('wcmRuleN').textContent = STAR_N;
|
||||
}
|
||||
/* ---------- 「妈妈们的留言」后面的 8 个小头像(11-07 用户:随时换一些,有人新留言就变) ----------
|
||||
最前面 = 最新留言(已通过)的真人头像,按时间倒序;不够 8 个用模拟留言的头像补(每次打开随机洗一遍);
|
||||
补位的每 5 秒换掉一个;页面开着时每 60 秒悄悄拉一次留言,只更新头像,不动正在看的列表。 */
|
||||
var AVN = 8, AVPOOL = null, AVREAL = [], avPi = 0;
|
||||
function avUniq(arr) { var seen = {}; return arr.filter(function (u) { if (!u || seen[u]) return false; seen[u] = 1; return true; }); }
|
||||
function avPaint() {
|
||||
var box = document.getElementById('wcmAv'); if (!box || !SIM || !SIM.length) return;
|
||||
if (!AVPOOL) {
|
||||
AVPOOL = avUniq(SIM.map(function (c) { return c.av; }));
|
||||
for (var i = AVPOOL.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)), t = AVPOOL[i]; AVPOOL[i] = AVPOOL[j]; AVPOOL[j] = t; }
|
||||
}
|
||||
var real = avUniq(AVREAL).slice(0, AVN), fill = [];
|
||||
while (real.length + fill.length < AVN && avPi < AVPOOL.length * 2) { var u = AVPOOL[avPi++ % AVPOOL.length]; if (real.indexOf(u) < 0 && fill.indexOf(u) < 0) fill.push(u); }
|
||||
var old = [].map.call(box.children, function (x) { return x.getAttribute('src'); });
|
||||
box.innerHTML = real.concat(fill).map(function (u, k) {
|
||||
return '<img src="' + esc(u) + '" alt=""' + (k < real.length ? ' data-r="1"' : '') + (old.indexOf(u) < 0 && old.length ? ' class="nw"' : '') + ' onerror="this.remove()">';
|
||||
}).join('');
|
||||
}
|
||||
function avRealFrom(list) {
|
||||
AVREAL = list.filter(function (c) { return c.status ? c.status === 'approved' : true; })
|
||||
.sort(function (a, b) { return (b.at || 0) - (a.at || 0); }).map(function (c) { return c.avatar; });
|
||||
}
|
||||
setInterval(function () { /* 补位的轮换 */
|
||||
var box = document.getElementById('wcmAv'); if (!box || document.hidden || !AVPOOL || !page.classList.contains('show')) return;
|
||||
var slots = [].filter.call(box.children, function (x) { return !x.dataset.r; }); if (!slots.length) return;
|
||||
var have = [].map.call(box.children, function (x) { return x.getAttribute('src'); }), u, n = 0;
|
||||
do { u = AVPOOL[avPi++ % AVPOOL.length]; } while (have.indexOf(u) >= 0 && ++n < AVPOOL.length);
|
||||
var el = slots[Math.floor(Math.random() * slots.length)];
|
||||
el.classList.add('out');
|
||||
setTimeout(function () { el.src = u; el.classList.remove('out'); el.classList.add('nw'); setTimeout(function () { el.classList.remove('nw'); }, 500); }, 260);
|
||||
}, 5000);
|
||||
setInterval(function () { /* 新留言 → 头像跟着变 */
|
||||
if (document.hidden || !page.classList.contains('show') || !SIM) return;
|
||||
fetch('/api/mp/public/mama-box/plaza/comments?kind=post&target=' + encodeURIComponent(PID)).then(function (r) { return r.json(); }).then(function (j) {
|
||||
var R = j && j.code === 200 && j.result; if (!R) return;
|
||||
var k0 = AVREAL.join('|'); avRealFrom((R.list || []).filter(top)); if (AVREAL.join('|') !== k0) avPaint();
|
||||
}).catch(function () {});
|
||||
}, 60000);
|
||||
function build() {
|
||||
if (!SIM || !REAL) return;
|
||||
SIM.forEach(simStar);
|
||||
|
||||
Reference in New Issue
Block a user