1 Star 0 Fork 0

cyddgi/open-note-to-window-title

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.ts 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
luckman212 提交于 2021-02-15 22:12 . handle renames and deletions
import { Plugin, TFile } from 'obsidian';
export default class ActiveNoteTitlePlugin extends Plugin {
// Get the window title
baseTitle = document.title;
async onload() {
console.log('loading ActiveNoteTitlePlugin plugin');
// When opening, renaming or deleting a file, update the window title
this.registerEvent(this.app.workspace.on('file-open', this.handleOpen));
this.registerEvent(this.app.vault.on('rename', this.handleRename));
this.registerEvent(this.app.vault.on('delete', this.handleDelete));
}
// Restore original title on unload.
onunload() {
document.title = this.baseTitle;
}
private readonly handleRename = async (file: TFile): Promise<void> => {
document.title = this.baseTitle + ' - ' + file.path;
};
private readonly handleDelete = async (file: TFile): Promise<void> => {
document.title = this.baseTitle;
};
private readonly handleOpen = async (file: TFile): Promise<void> => {
if (file instanceof TFile) {
document.title = this.baseTitle + ' - ' + file.path;
} else {
document.title = this.baseTitle;
}
};
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cyddgi/open-note-to-window-title.git
git@gitee.com:cyddgi/open-note-to-window-title.git
cyddgi
open-note-to-window-title
open-note-to-window-title
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385