q(≧▽≦q) 大家好!我是電籽(B站_小小电子xxdz)
- 由于过去freeflarum论坛的后台ACG插件下架了,我写了一个弥补脚本,致和我一样没有本地服务器的默认服务器站长
(Due to the removal of the ACG plugin from the backend of the FreeFlarum forum in the past, I wrote a remediation script to address the default server owner who, like me, does not have a local server)
最终效果(Final effect):

请先先复制B站的视频“嵌入代码(Please copy the video embedding code from Bilibili first)”

然后,我在此代码规定:在帖子编辑器里输入“【】【】【】【】【】【】”(也就是6个【】)
然后在第3个【】后粘贴“嵌入代码”即可,例如:
(**Then, I specify in this code: * * In the post editor, enter "【】【】【】【】【】【】【" (i.e. 6 【】)
Then paste the "embed code" after the third 【】, for example🙂
【】【】【】frame src="//player.bilibili.com/player.html?isOutside=true&aid=115503062320810&bvid=BV19V2wB5ERa&cid=33762314954&p=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe>【】【】【】
接下来是如何让你的论坛支持这个功能:
请在论坛后台的页眉或页脚代码里粘贴以下代码
(Please paste the following code in the header or footer code of the forum backend)
<!==================xxdz-哔哩哔哩嵌入================>
<script>
console.log("(=OωO=) 電籽B站嵌入脚本启动");
function processEmbeds() {
console.log("(>﹏<) 开始处理");
try {
let processed = 0;
// 方法1:直接处理所有<p>标签
const paragraphs = document.querySelectorAll('p');
paragraphs.forEach(p => {
const originalHTML = p.innerHTML;
if (!originalHTML || !originalHTML.includes('【】【】【】')) return;
// 替换所有嵌入代码
const regex = /【】【】【】([\s\S]*?)【】【】【】/g;
const matches = [...originalHTML.matchAll(regex)];
if (matches.length === 0) return;
let newHTML = originalHTML;
matches.forEach(match => {
const originalCode = match[1];
// === 简化版提取逻辑(只针对特定格式) ===
// 查找 src=" 或 src=" 的位置
const srcPattern = /src\s*=\s*["“]([^"”]+)[”"]/;
const srcMatch = originalCode.match(srcPattern);
if (srcMatch) {
let rawSrc = srcMatch[1];
// 清理URL
rawSrc = rawSrc
.replace(/&/g, '&')
.replace(/"/g, '')
.replace(/"/g, '')
.trim();
if (rawSrc.startsWith('//')) {
rawSrc = 'https:' + rawSrc;
}
if (rawSrc.includes('bilibili.com/player.html')) {
const iframeHTML = `
<div style="
position: relative;
width: 100%;
max-width: 800px;
margin: 20px auto;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
background: #f5f5f5;
border-radius: 8px;
">
<iframe
src="${rawSrc}"
style="
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
border-radius: 6px;
"
allowfullscreen
scrolling="no"
frameborder="0"
></iframe>
</div>
`;
newHTML = newHTML.replace(match[0], iframeHTML);
processed++;
console.log(`(^▽^) 提取成功: ${rawSrc.substring(0, 60)}...`);
}
}
// === 结束提取逻辑 ===
});
if (newHTML !== originalHTML) {
p.innerHTML = newHTML;
}
});
// 方法2:如果方法1不行,尝试处理.content或.post-content区域
if (processed === 0) {
const contentAreas = document.querySelectorAll('.content, .post-content, [class*="content"]');
contentAreas.forEach(area => {
const originalHTML = area.innerHTML;
if (!originalHTML || !originalHTML.includes('【】【】【】')) return;
// 使用同样的替换逻辑...
// (这里可以复制上面的替换逻辑)
});
}
if (processed > 0) {
console.log(`(^▽^) 成功嵌入${processed}个视频`);
} else {
console.log("(;一_一) 未成功嵌入任何视频");
console.log(" 调试:正在检查页面中的嵌入代码...");
// 显示页面中实际的嵌入代码以供调试
const walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
false
);
let node, count = 0;
while (node = walker.nextNode()) {
if (node.textContent.includes('【】【】【】')) {
count++;
console.log(`嵌入代码 ${count}:`, node.textContent.trim().substring(0, 200));
}
}
}
} catch (error) {
console.error("(╯°口°)╯ 处理出错:", error);
}
}
// 延迟执行
setTimeout(processEmbeds, 3000);
// 按钮点击监听
document.addEventListener('click', function(event) {
if (event.target.closest && event.target.closest('.Button-label')) {
console.log("重新处理");
setTimeout(processEmbeds, 500);
}
});
// 简单的URL变化监听
let bilibiliLastUrl = window.location.href;
setInterval(() => {
if (window.location.href !== bilibiliLastUrl) {
bilibiliLastUrl = window.location.href;
console.log("(OvO) 页面变化,重新处理");
setTimeout(processEmbeds, 1000);
}
}, 1000);
</script>
目前有一个缺点,就是进入包含B站嵌入视频的页面后,还需要刷新一下,代码才能重新执行,并将富文本转换成B站视频容器。。我但愿以后可以成功修复吧,修复好后我会发新的帖子,希望大家可以关注我!谢谢
(At present, there is a drawback that after entering the page containing Bilibili embedded videos, it needs to be refreshed before the code can be re executed and the rich text can be converted into a Bilibili video container.. I hope to be able to successfully fix it in the future. After fixing it, I will post a new post. I hope everyone can follow me! Thank you)
My Bilibili
欢迎大家光临我的论坛!