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 69 70 71 72 73 74 75 76 77 78
| - const { envId } = theme.twikoo - const { easy_Danmaku_js, danmu_page, danmu_el, danmu_line, danmu_speed, danmu_hover, danmu_loop, danmu_colourful, danmu_coefficient, danmu_runtime } = theme.envelope_comment
script. window.addEventListener('load', () => { const getnaokuo_danmu = () => { if (!window.location.pathname.startsWith('!{danmu_page}')) return; const naokuo_danmu = async () => { const Danmaku = new EasyDanmaku({ page: '!{danmu_page}', el: '#!{danmu_el}', line: !{danmu_line}, speed: !{danmu_speed}, hover: !{danmu_hover}, loop: !{danmu_loop}, colourful: !{danmu_colourful}, coefficient: !{danmu_coefficient}, runtime: !{danmu_runtime}, }); try { let danmuStore = saveToLocal.get('twikoo-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('twikoo-danmu', danmuStore, 0.5) } 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('danmu-Btn') && (document.getElementById('danmu-Btn').innerHTML = `<button class="hide-Btn" onclick="document.getElementById('!{danmu_el}').classList.remove('hide-danmu')">显示弹幕</button> <button class="hide-Btn" onclick="document.getElementById('!{danmu_el}').classList.add('hide-danmu')">隐藏弹幕</button>`) } (async () => { if (typeof EasyDanmaku === 'function') { await naokuo_danmu(); } else { const easyDanmakuScript = await getScript('!{url_for(easy_Danmaku_js)}'); if (typeof EasyDanmaku === 'function') { await naokuo_danmu(); } else { console.error('EasyDanmaku function not found even after loading the script.'); } } })(); } getnaokuo_danmu() document.addEventListener('pjax:complete', getnaokuo_danmu) })
|