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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| include ../widgets/page/banner if theme.says.enable #bber section.timeline.page-1 ul.list.waterfall .bber-loading img(src="https://yife68.gitee.io/icat-pic/blog/loading.svg") script. (async function () { let url = '!{url_for(theme.says.link)}'; const baseUrl = url.substring(0, url.indexOf("/", url.indexOf("//") + 2)); const response = await fetch(url); const data = await response.json(); const strip = !{theme.says.strip}; let items = [], topitem = [], essayTips = '';
const processedData = await Promise.all(data.map(async (item) => { const formatdata = await essayFormat(item,baseUrl); if (!formatdata) return null; if (item.content.includes('#top')) { topitem.push(formatdata); } else { items.push(formatdata); } return formatdata; }));
essayTips = strip === -1 || strip >= items.length ? `<div id="bber-tips">- 已展开所有短文 -</div>` : (items = items.slice(0, strip), `<div id="bber-tips">- 只展示最近 ${strip} 条短文 -</div>`);
document.getElementsByClassName('list')[0].innerHTML = topitem.concat(items).filter(item => item !== null).join(''); document.querySelector("#bber").insertAdjacentHTML("beforeend", essayTips); })(); case theme.says.style when 1 script. async function essayFormat(item,baseUrl) { const contentRegex = /#(.*?)\s|\n/g, imageRegex = /\!\[(.*?)\]\((.*?)\)/g, playerRegex = /{\s*player\s*(.*)\s*}/g, linkRegex = /(?<!\!)\[(.*?)\]\((.*?)\)/g, topRegex = /#top/g, fromRegex = /(?<![\w\/])(?<!\{)\{([^{}\s]+)\}(?!\})(?![\w\/])/g; let time = new Date((item.createdTs - (new Date().getTimezoneOffset() * 60)) * 1000).toISOString(), content = item.content, image = '', img = content.match(imageRegex); aplayer = content.match(/{\s*music\s*(.*?)\s*(.*?)\s*}/g), video = content.match(playerRegex), link = content.match(linkRegex), type = '', from = content.match(fromRegex); if (item.resourceList.length) { if (!img) img = []; item.resourceList.forEach(e => { if (e.externalLink) img.push(e.externalLink); else img.push(`${baseUrl}/o/r/${e.uid}`); }); } if (img) image += img.map(e => `<img src="${e.replace(imageRegex, '$2')}" alt="${e.replace(imageRegex, '$1')}" />`).join(''); aplayer = aplayer ? `<div class="bber-music"><meting-js server="${aplayer[0].match(/\{\s*music\s*(.*?)\s*\d+\s*\}/)[1]}" type="song" id="${aplayer[0].match(/\d+/)[0]}" mutex="true" preload="none" theme="var(--efu-main)" data-lrctype="0"></meting-js></div>` : ''; video = video ? `<div class="bber-video"><video src="${video[0].replace(playerRegex, '$1').trim()}" controls="controls" style="object-fit: cover;"></video></div>` : content.match(/{\s*bilibili\s*(.*?)\s*}/g); video = Array.isArray(video) ? `<div class="bber-video"><iframe src="//player.bilibili.com/player.html?bvid=${video[0].match(/(BV\w+)/)[1]}${video[0].match(/{\s*bilibili\s*(.*?)\s*true\s*}/g) ? '&autoplay=1' : '&autoplay=0'}" scrolling="no" bozrder="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>` : ''; link = link ? ((type = link[0].replace(linkRegex, '$2')), `<a class="bber-content-link" href='${type.startsWith('/') ? type : (type.startsWith('http') ? type : 'https://' + type)}' title="${link[0].replace(linkRegex, '$1') ? link[0].replace(linkRegex, '$1') : '跳转到短文指引的链接' }" target="_blank"><i class="solitude st-link-m-line"></i>链接</a>`) : ''; from = from ? `<div class="bber-info-from"><span>${from[0].replace(fromRegex, '$1')}</span></div>` : ''; content = content.replace(contentRegex, '').replace(imageRegex, '').replace(/\{(.*?)\}/g, '').replace(linkRegex, '').trim();
return ` <li class="item"> <div id="bber-content"> ${content ? `<p class="bber-content">${content}</p>` : ''} ${image ? `<div class="bber-content-img">${image}</div>` : ''} </div> ${aplayer} ${video} <hr> <div class="bber-bottom"> <div class="bber-info"> <div class="bber-info-time"> <i class="solitude st-calendar-todo-fill"></i> <time class="datatime" datetime="${time}"></time> </div> ${link} ${from} ${item.content.includes('#top') ? `<div class="bber-info-top"><i class="solitude st-thumbtack-solid"></i>置顶</div>` : ''} </div> ${content ? `<a class="bber-reply goComment" onclick="sco.toTalk('${content}')"><i class="solitude st-chat-fill" style="font-size: 1rem;"></i></a>` : ''} </div> </li>`; } when 2 script. async function essayFormat(item,baseUrl) { const contentRegex = /#(.*?)\s|\n/g, imageRegex = /\!\[(.*?)\]\((.*?)\)/g, playerRegex = /{\s*player\s*(.*)\s*}/g, linkRegex = /(?<!\!)\[(.*?)\]\((.*?)\)/g, topRegex = /#top/g, fromRegex = /(?<![\w\/])(?<!\{)\{([^{}\s]+)\}(?!\})(?![\w\/])/g; let time = new Date((item.createdTs - (new Date().getTimezoneOffset() * 60)) * 1000).toISOString(), content = item.content, image = '', img = content.match(imageRegex); aplayer = content.match(/{\s*music\s*(.*?)\s*(.*?)\s*}/g), video = content.match(playerRegex), link = content.match(linkRegex), type = '', from = content.match(fromRegex); if (item.resourceList.length) { if (!img) img = []; item.resourceList.forEach(e => { if (e.externalLink) img.push(e.externalLink); else img.push(`${baseUrl}/o/r/${e.uid}`); }); } if (img) image += img.map(e => `<img src="${e.replace(imageRegex, '$2')}" alt="${e.replace(imageRegex, '$1')}" />`).join(''); aplayer = aplayer ? `<div class="bber-music"><meting-js server="${aplayer[0].match(/\{\s*music\s*(.*?)\s*\d+\s*\}/)[1]}" type="song" id="${aplayer[0].match(/\d+/)[0]}" mutex="true" preload="none" theme="var(--efu-main)" data-lrctype="0"></meting-js></div>` : ''; video = video ? `<div class="bber-video"><video src="${video[0].replace(playerRegex, '$1').trim()}" controls="controls" style="object-fit: cover;"></video></div>` : content.match(/{\s*bilibili\s*(.*?)\s*}/g); video = Array.isArray(video) ? `<div class="bber-video"><iframe src="//player.bilibili.com/player.html?bvid=${video[0].match(/(BV\w+)/)[1]}${video[0].match(/{\s*bilibili\s*(.*?)\s*true\s*}/g) ? '&autoplay=1' : '&autoplay=0'}" scrolling="no" bozrder="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>` : ''; link = link ? ((type = link[0].replace(linkRegex, '$2')), `<a class="bber-content-link" href='${type.startsWith('/') ? type : (type.startsWith('http') ? type : 'https://' + type)}' target="_blank">${link[0].replace(linkRegex, '$1') ? ('@' + link[0].replace(linkRegex, '$1')) : '跳转到短文指引的链接' }</a>`) : ''; from = from ? `<div class="bber-info-from"><i class="solitude st-hashtag-solid"></i>${from[0].replace(fromRegex, '$1')}</div>` : ''; content = content.replace(contentRegex, '').replace(imageRegex, '').replace(/\{(.*?)\}/g, '').replace(linkRegex, '').trim();
return ` <li class="item"> <div class="meta"> <img class="no-lightbox nolazyload avatar" src="!{theme.aside.card.author.img}"> <div class="info"> <span class="bber_nick">#{config.author}</span> <time class="datetime bber_date" datetime="${time}"></time> </div> ${content ? `<a class="bber-reply goComment" onclick="sco.toTalk('${content}')"><i class="solitude st-chat-fill" style="font-size: 1rem;"></i></a>` : ''} </div> <div id="bber-content"> ${content ? `<p class="bber-content"><span>${content}</span>${link}</p>` : ''} ${image ? `<div class="bber-content-img">${image}</div>` : ''} </div> ${aplayer} ${video} <div class="bber-bottom"> <div class="bber-info"> ${item.content.includes('#top') ? `<div class="bber-info-top"><i class="solitude st-thumbtack-solid"></i>置顶</div>` : ''} ${from} </div> </div> </li>`; }
|