常看到大佬们说,刷新页面就行了。那对小白来说,究竟怎么刷新页面呢?
把下面的代码放到 js 代码片段中就可以按 shift+f5 刷新页面了,再也不用按大佬们说的打开什么控制台了。
// Shift+F5 重载界面 JS片段
(()=>{
document.addEventListener('keydown', function(event) {
// 检查是否同时按下了 Shift 和 F5 ,并且没有其他修饰键被按下
if (event.shiftKey && event.key === 'F5' && !event.ctrlKey && !event.altKey && !event.metaKey) {
event.preventDefault(); // 阻止默认行为
reloadUI(); // 重载界面 API
}
});
// 刷新UI
// mode app客户端 desktop浏览器桌面端 mobile移动端
// see https://github.com/siyuan-note/siyuan/issues/15308
function reloadUI(mode) {
// 未安装插件
if(window.siyuan.ws.app.plugins?.length === 0) {
if (mode) window.location.pathname = `stage/build/${mode}/`;
else fetch('/api/ui/reloadUI', { method: 'POST' });
return;
}
// 获取plugin
const plugin = window.siyuan.ws.app.plugins[0];
// 旧版
if(!plugin?.saveLayout) {
if (mode) window.location.pathname = `stage/build/${mode}/`;
else fetch('/api/ui/reloadUI', { method: 'POST' });
return;
}
// 新版
plugin.saveLayout(() => {
if (mode) window.location.pathname = `stage/build/${mode}/`;
else window.location.reload();
});
}
})();
感谢 @JeffreyChen @wilsons @HugZephyr 帮忙完善和提供的改进后的代码!
没想到简单的刷新背后竟然还有这么多道道。

欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于