


如果是简单的 flash 游戏,可以用思源笔记自带的 Ruffle 代替 adobe flash player 玩 下面代码是 Ruffle 运行 swf 格式的游戏
/* === 直接嵌入SWF游戏脚本 (最终优化版) === */
// 1. 设置块样式
this.innerHTML = '';
this.style.height = '500px'; // 您可以根据需要调整此高度
this.style.backgroundColor = 'black';
this.style.overflow = 'hidden';
// 2. 定义资源URL
const ruffleScriptURL = 'https://unpkg.com/@ruffle-rs/ruffle';
const swfURL = 'https://oldswf.com/data/extra/flipside/game.swf';
// 3. 定义游戏初始化函数
const initGame = function() {
try {
this.innerHTML = ''; // 清空加载提示
const ruffle = window.RufflePlayer.newest();
const player = ruffle.createPlayer();
// 让播放器填满整个块
player.style.width = '100%';
player.style.height = '100%';
this.appendChild(player);
player.load(swfURL);
} catch (e) {
console.error('Ruffle player creation failed:', e);
this.innerHTML = '<div style="color:red; padding:1em;">错误:Ruffle 播放器创建失败。</div>';
fetch('/api/notification/pushErrMsg', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ msg: 'Ruffle 播放器创建失败', timeout: 5000 })
});
}
};
// 4. 全局 Promise 加载逻辑,彻底解决竞争问题
this.textContent = '正在加载游戏核心...';
// 检查全局空间是否已有Ruffle加载任务
if (!window.rufflePromise) {
// 如果没有,则创建加载任务
window.rufflePromise = new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = ruffleScriptURL;
script.onload = () => {
console.log('Ruffle script loaded successfully.');
resolve(); // 脚本加载成功,Promise 完成
};
script.onerror = (err) => {
console.error('Ruffle script failed to load:', err);
reject(err); // 脚本加载失败,Promise 拒绝
};
document.head.appendChild(script);
});
}
// 无论此块是第几个,都等待全局的加载任务完成
window.rufflePromise.then(() => {
// 加载成功后,初始化本块的游戏
initGame.call(this);
}).catch((err) => {
// 加载失败,在本块显示错误信息
this.innerHTML = '<div style="color:red; padding:1em;">错误:无法加载游戏核心组件。</div>';
fetch('/api/notification/pushErrMsg', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ msg: '加载 Ruffle.js 失败', timeout: 5000 })
});
});
如今网页游戏都内置了 flash 功能,支持 HTML5 直接运行,然后点击全屏即可
// 1. 清空块内所有内容
this.innerHTML = '';
// 2. 设置块的样式,为 iframe 提供容器
this.style.height = '600px'; // 您可以根据游戏页面的大小调整此高度
this.style.overflow = 'hidden';
// 3. 创建 iframe 元素
const iframe = document.createElement('iframe');
// 4. 设置 iframe 的属性
iframe.src = 'https://oldswf.com/game/236210'; // 嵌入完整的游戏页面地址
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.style.border = 'none'; // 移除边框
iframe.setAttribute('allowfullscreen', 'true'); // 允许全屏
// 5. 将创建好的 iframe 添加到块中
this.appendChild(iframe);
平替 4399 小游戏网站:https://oldswf.com/
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于