1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| - const { envId } = theme.twikoo - const { easy_Danmaku_js, danmu_page, danmu_el, danmu_line, danmu_speed, danmu_hover, danmu_loop } = theme.envelope_comment
script. window.addEventListener('load', () => { const getnaokuo_danmu = () => { if (!window.location.pathname.startsWith('!{danmu_page}')) return; const naokuo_danmu = async () => { window.Danmaku = new EasyDanmaku({ page: '!{danmu_page}', el: '!{danmu_el}', line: !{danmu_line}, speed: !{danmu_speed}, hover: !{danmu_hover}, loop: !{danmu_loop}, }); try { let danmuStore = saveToLocal.get('danmu'); if (!danmuStore) { const options = { method: "POST", body: JSON.stringify({ "event": "GET_RECENT_COMMENTS", "includeReply": false, "pageSize": 100 }), headers: { 'Content-Type': 'application/json' } } danmuStore = []; const response = await fetch(`!{envId}`, options); if (response.ok) { const { data } = await response.json(); data.forEach(i => { if (i.avatar == undefined) i.avatar = 'https://cravatar.cn/avatar/d615d5793929e8c7d70eab5f00f7f5f1?d=mp' danmuStore.push({ avatar: i.avatar, content: i.nick + ':' + formatDanmaku(i.comment), url: i.url + '#' + i.id }) }); Danmaku.batchSend(danmuStore, true); saveToLocal.set('danmu', danmuStore, 0.02) } function formatDanmaku(str) { str = str.replace(/<\/*br>|[\s\uFEFF\xA0]+/g, ''); str = str.replace(/<img.*?>/g, '[图片]'); str = str.replace(/<a.*?>.*?<\/a>/g, '[链接]'); str = str.replace(/<pre.*?>.*?<\/pre>/g, '[代码块]'); str = str.replace(/<.*?>/g, ''); return str } } else { Danmaku.batchSend(danmuStore, true); } } catch (err) { console.error("Error fetching data:", err); }
document.getElementById('danmuBtn') && (document.getElementById('danmuBtn').innerHTML = `<button class="hideBtn" onclick="document.getElementById('danmu').classList.remove('hidedanmu')">显示弹幕</button> <button class="hideBtn" onclick="document.getElementById('danmu').classList.add('hidedanmu')">隐藏弹幕</button>`) } if (typeof Danmaku === 'object') { naokuo_danmu() } else { getScript('!{url_for(easy_Danmaku_js)}').then(naokuo_danmu) } } getnaokuo_danmu() document.addEventListener('pjax:complete', getnaokuo_danmu) })
|