Template titles

This commit is contained in:
2022-07-22 22:34:03 +00:00
parent b82da219ce
commit fbf37fbdfd
5 changed files with 127 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ export const AutoSettingsMixin = (SuperClass) => {
return class AutoSettingsMixinClass extends SuperClass {
_faviconTemplateSubscription;
_titleTemplateSubscription;
__currentTitle = undefined;
constructor() {
super();
@@ -12,6 +13,13 @@ export const AutoSettingsMixin = (SuperClass) => {
this.addEventListener("browser-mod-config-update", () =>
this._auto_settings_setup()
);
window.addEventListener("location-changed", () => {
this._updateTitle();
setTimeout(() => this._updateTitle(), 500);
setTimeout(() => this._updateTitle(), 1000);
setTimeout(() => this._updateTitle(), 5000);
});
}
async _auto_settings_setup() {
@@ -72,6 +80,21 @@ export const AutoSettingsMixin = (SuperClass) => {
// Title template
if (settings.titleTemplate !== undefined) {
(async () => {
if (this._titleTemplateSubscription) {
this._titleTemplateSubscription();
}
this._titleTemplateSubscription = undefined;
this._titleTemplateSubscription =
await this.connection.subscribeMessage(
this._updateTitle.bind(this),
{
type: "render_template",
template: settings.titleTemplate,
variables: {},
}
);
})();
}
}
@@ -93,5 +116,15 @@ export const AutoSettingsMixin = (SuperClass) => {
link.href = result;
window.browser_mod.fireEvent("browser-mod-favicon-update");
}
get _currentTitle() {
return this.__currentTitle;
}
_updateTitle(data = undefined) {
if (data) this.__currentTitle = data.result;
if (this.__currentTitle) document.title = this.__currentTitle;
window.browser_mod.fireEvent("browser-mod-favicon-update");
}
};
};

View File

@@ -53,12 +53,13 @@ import { AutoSettingsMixin } from "./auto-settings";
X Framework
x Save sidebar
x Kiosk mode
- Default panel?
- Default panel
- Screensaver?
x Favicon templates
- Title templates
x Title templates
- Tweaks
- Quickbar tweaks (ctrl+enter)?
- Card-mod preload
- Video player?
- Media_seek
- Screensavers